lucene索引的增、删、改
package com.hope.lucene;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.FSDirectory;
import org.junit.Before;
import org.junit.Test;
import org.wltea.analyzer.lucene.IKAnalyzer;
import java.io.File;
/**
* @author newcityman
* @date 2020/1/15 - 17:22
*/
public class IndexManager {
private IndexWriter indexWriter;
@Before
public void init() throws Exception {
//创建一个IndexWriter对象,需要使用IKAnalyzer作为分词器
indexWriter = new IndexWriter(FSDirectory.open(new File("G:\\workspace_idea3\\lucene\\temp\\index").toPath()),
new IndexWriterConfig(new IKAnalyzer()));
}
/**
* 添加索引
* @throws Exception
*/
@Test
public void addDocument() throws Exception {
//创建一个Document对象
Document document = new Document();
//向Document对象中添加Field域
document.add(new TextField("name", "新添加的文件", Field.Store.YES));
document.add(new TextField("content", "新添加的文件内容", Field.Store.NO));
document.add(new StoredField("path", "G:\\workspace_idea3\\lucene\\temp\\index"));
//把文档写入索引库
indexWriter.addDocument(document);
//关闭索引库
indexWriter.close();
}
/**
* 删除索引
* @throws Exception
*/
@Test
public void deleteAllDocument() throws Exception {
//删除所有文档
indexWriter.deleteAll();
//关闭索引库
indexWriter.close();
}
/**
* 根据条件删除索引
*/
@Test
public void deleteDocumentByQuery() throws Exception{
indexWriter.deleteDocuments(new Term("content","apache"));
indexWriter.close();
}
/**
* 修改索引
*/
@Test
public void updateDocument() throws Exception{
Document document = new Document();
document.add(new TextField("name","更新后的内容1", Field.Store.YES));
document.add(new TextField("name2","更新后的内容2", Field.Store.YES));
document.add(new TextField("name3","更新后的内容3", Field.Store.YES));
indexWriter.updateDocument(new Term("name","spring"),document);
indexWriter.close();
}
}
lucene索引的增、删、改的更多相关文章
- iOS sqlite3 的基本使用(增 删 改 查)
iOS sqlite3 的基本使用(增 删 改 查) 这篇博客不会讲述太多sql语言,目的重在实现sqlite3的一些基本操作. 例:增 删 改 查 如果想了解更多的sql语言可以利用强大的互联网. ...
- ADO.NET 增 删 改 查
ADO.NET:(数据访问技术)就是将C#和MSSQL连接起来的一个纽带 可以通过ADO.NET将内存中的临时数据写入到数据库中 也可以将数据库中的数据提取到内存中供程序调用 ADO.NET所有数据访 ...
- 第18课-数据库开发及ado.net 连接数据库.增.删.改向表中插入数据并且返回自动编号.SQLDataReade读取数据
第18课-数据库开发及ado.net 连接数据库.增.删.改向表中插入数据并且返回自动编号.SQLDataReade读取数据 ADO.NET 为什么要学习? 我们要搭建一个平台(Web/Winform ...
- C# ADO.NET (sql语句连接方式)(增,删,改)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 好用的SQL TVP~~独家赠送[增-删-改-查]的例子
以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化. 本系列主要是针对T-SQL的总结. [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础] ...
- iOS FMDB的使用(增,删,改,查,sqlite存取图片)
iOS FMDB的使用(增,删,改,查,sqlite存取图片) 在上一篇博客我对sqlite的基本使用进行了详细介绍... 但是在实际开发中原生使用的频率是很少的... 这篇博客我将会较全面的介绍FM ...
- MVC EF 增 删 改 查
using System;using System.Collections.Generic;using System.Linq;using System.Web;//using System.Data ...
- django ajax增 删 改 查
具于django ajax实现增 删 改 查功能 代码示例: 代码: urls.py from django.conf.urls import url from django.contrib impo ...
- StringBuilder修改字符串内容,增,删,改,插
package seday01;/** * 字符串不变对象特性只针对字符串重用,并没有考虑修改操作的性能.因此String不适合频繁修改内容. * 若有频繁修改操作,使用StringBuilder来完 ...
- python基础中的四大天王-增-删-改-查
列表-list-[] 输入内存储存容器 发生改变通常直接变化,让我们看看下面列子 增---默认在最后添加 #append()--括号中可以是数字,可以是字符串,可以是元祖,可以是集合,可以是字典 #l ...
随机推荐
- Maven快速入门(五)Maven的依赖管理
前面我们讲了maven项目中的最重要的文件:pom.xml 配置文件相关内容.介绍了pom 是如何定义项目,如何添加依赖的jar 包的等. 我们知道,在Maven的生命周期中,存在编译.测试.运行等过 ...
- NOIP模拟99(多校31)
T1 法阵 解题思路 原题3100,张口放 T1(出题人原话) 思维题,合法的情况其实就是上下两个梯形拼起来的样子. 他们的边界都是在 \(i\) 轴上面,但是不能相交. 于是我们可以尝试两者相交的纵 ...
- PAT A1103—DFS
Integer Factorization The K−P factorization of a positive integer N is to write N as the sum of the ...
- 多声部处理细节之crossstaff音符处理
下面给出这几个案例的代码 ,可直接粘贴编译. \version "2.20.0" \language "english" \paper { #(set-pape ...
- vue属性绑定不能用双括号表达式
- Swagger2简单使用教程
Swagger2简单使用教程 1.简介 Swagger是为了解决企业中接口(api)中定义统一标准规范的文档生成工具.很多采用前后端分离的模式,前端只负责调用接口,进行渲染,前端和后端的唯一联系, ...
- CF611F New Year and Cleaning
题意 CF611F New Year and Cleaning 想法 这个题是\(NOIP2020\)的弱化版.. 我们把所有在二维上的点都一起考虑,那么所有点对于一个步骤的移动是相当于这些所有点所组 ...
- Codeforces 505E - Mr. Kitayuta vs. Bamboos(二分+堆)
题面传送门 首先很显然的一点是,看到类似于"最大值最小"的字眼就考虑二分答案 \(x\)(这点我倒是想到了) 然鹅之后就不会做了/wq/wq/wq 注意到此题正着处理不太方便,故考 ...
- 9 Days 停课修炼题解集
xj4604 排序 \(n,k <= 1e5\). 先考虑二分出这个值,check 有多少段的平均值小于这个 mid,这个在之前的复活赛中是原题 T4,数形结合,$ \text{Average} ...
- 【python】python之list
1.判断list是否为空 方式一: list_temp=[] if len(list_temp): #非空即为真 print('list is not empty') else: print('lis ...