IndexWriter操作索引库,增删改
// 构造方法:如果索引库不存在,会自动创建。如果存在,就使用他
new IndexWriter(String/Directory indexPath, Analyzer a, MaxFieldLength mfl)
// 构造方法:第三个参数指定是否创建一个新的索引库。
// 1,有索引库,create为true:会重新创建。2,没有索引库,create为false,会报错。
new IndexWriter(String/Directory indexPath, Analyzer a, boolean create, MaxFieldLength mfl)
// 添加索引
addDocument( Document doc )
// 更新
updateDocument(Term term, Document doc)
// 删除
deleteDocument(Term term)
// 合并索引库
addIndexesNoOptimize(Directory[])
// 优化索引库
optimize()
IndexSearcher:操作索引库,查询
// 构造方法,索引库不存在,就报错
new IndexSearcher( String indexPath )
// 搜索
TopDocs search( Query query, Filter filer, int n )
// 搜索
TopDocs search( Query query, Filter filer, int n , Sort sort)
//
Document doc( int docSn )
Document:Lucene所操作的对象
Field:组成Document的元素,代表一个属性。Store、Index
new Field( String name, String value, Store store, Index index )
Directory:索引库(目录)
FSDirectory :真实的目录
RAMDirectory:在内存中的一个虚拟的目录
QueryParser:把查询字符串变为查询对象的工具。使用子类: MultiFieldQueryParser
new MultiFieldQueryParser(String[] fields, Analyzer a)
Term:代表某个属性中的一个关键词(目录中出现的条目),是搜索的最小单位
Query :查询对象(封装的过滤条件)。有很多子类,对应各种各样的查询方式。
TopDocs(一套) :代表查询结果
Filter
Sort