Lucene创建索引,删除索引
2017-08-08 23:19
274 查看
Lucene创建索引
删除索引
现在的Field构造函数原型是如下样子的:
public Field(String name, String value, Store store, Index index) <
Lucene 的核心索引类 IndexWriter :建立索引的核心组件。
Directory:代表一个 lucene 索引项的位置。
Analyzer :对文本内容进行分析的抽象类,具体实现中有停用词切除、词干分析、大小写切换等功能。
Document :可以视作文本经过处理后所对应的对象,由多个字段组成,如路径、标题、摘要、修改日期等等。
Field :字段,对应于文本的某一部分数据,便于检索时根据结果提取。早期版本分为四个类型: Keyword 、 UnIndexed 、 UnStored 和 Text ,其主要区别归结于三个方面:是否被分
4000
析,是否被索引,是否存储于索引中。但是在最新版本的Lucene中,使用了一种更为统一的形式,也即只有Field一个类,然后使用一些参数来描述这个字段的属性,通过参数组合,可以组合出各种类别,甚至那四种不存在的类别理论上也是可以组合出来。
package testindex; import java.io.IOException; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class TestIndex { /** * user(id,name,address) * insert into user(id,name,address) values(1,'zhangsan','shanghaichangningqv'); * @throws IOException */ public static void main(String[] args) throws IOException { String [] ids={"1","2","3"}; String [] names={"zhangsan","lisi","wangwu"}; String [] addresses={"shanghai","beijing","guangzhou"}; Analyzer analyzer=new StandardAnalyzer(); String indexDir="C:/Users/yihong/Desktop/luceneindex"; Directory dir=FSDirectory.getDirectory(indexDir); //true 表示创建或覆盖当前索引;false表示对当前索引进行追加 //Default value is 128 IndexWriter writer=new IndexWriter(dir,analyzer,true,IndexWriter.MaxFieldLength.LIMITED); for(int i=0;i<ids.length;i++){ Document document=new Document(); document.add(new Field("id",ids[i],Field.Store.YES,Field.Index.ANALYZED)); document.add(new Field("name",names[i],Field.Store.YES,Field.Index.NO)); document.add(new Field("address",addresses[i],Field.Store.YES,Field.Index.ANALYZED)); writer.addDocument(document); } writer.optimize(); writer.close(); } }
删除索引
package testindex; import java.io.IOException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class TestDelDocument { public static void main(String[] args) throws IOException { String indexDir="C:/Users/yihong/Desktop/luceneindex"; Directory dir=FSDirectory.getDirectory(indexDir); IndexReader reader=IndexReader.open(dir); // System.out.println(reader.maxDoc()); reader.deleteDocument(0); System.out.println(reader.deleteDocuments(new Term("id","2"))); System.out.println(reader.numDocs()); reader.close(); dir.close(); } }
现在的Field构造函数原型是如下样子的:
public Field(String name, String value, Store store, Index index) <
Lucene 的核心索引类 IndexWriter :建立索引的核心组件。
Directory:代表一个 lucene 索引项的位置。
Analyzer :对文本内容进行分析的抽象类,具体实现中有停用词切除、词干分析、大小写切换等功能。
Document :可以视作文本经过处理后所对应的对象,由多个字段组成,如路径、标题、摘要、修改日期等等。
Field :字段,对应于文本的某一部分数据,便于检索时根据结果提取。早期版本分为四个类型: Keyword 、 UnIndexed 、 UnStored 和 Text ,其主要区别归结于三个方面:是否被分
4000
析,是否被索引,是否存储于索引中。但是在最新版本的Lucene中,使用了一种更为统一的形式,也即只有Field一个类,然后使用一些参数来描述这个字段的属性,通过参数组合,可以组合出各种类别,甚至那四种不存在的类别理论上也是可以组合出来。
相关文章推荐
- Lucene中创建索引的效率和删除索引的实现
- Lucene中创建索引的效率和删除索引的实现
- lucene索引_创建_域选项和lucene索引_的删除、更新.
- Lucene3.5 的索引的创建,删除,更新,加权
- Lucene创建、查询、删除、更新 索引
- lucene索引管理(索引创建于删除)
- Lucene中创建索引的效率和删除索引的实现
- Lucene中创建索引的效率和删除索引的实现
- lucene5学习 - 索引基本操作(创建,查询,更新,删除,分页)
- MySQL索引的创建、删除和查看
- 索引动态模板的创建,删除,是否存在
- 关于Lucene.net 2.9.2.2 中删除索引的若干问题
- lucene创建索引高级特性和索引创建参数优化
- MySQL查看、创建和删除索引的方法
- python中pandas.DataFrame的简单操作方法(创建、索引、增添与删除)
- 创建索引小程序 (Lucene2.1)
- ORACLE数据库中创建、删除--同义词、视图、索引、序列
- MySQL之表的创建、删除、修改、删除、查看及索引
- MySQL数据库索引:删除、查看、创建索引
- MySQL查看、创建和删除索引的方法