org.apache.lucene.store.Directory数据库
指定索引所在目录。apache
org.apache.lucene.store.RAMDirectory缓存
存放于内存中的目录。函数
org.apache.lucene.store.RAMDirectory.RAMDirectory(FSDirectory dir, IOContext context)
构造函数。把文件索引载入内存中。this
org.apache.lucene.store.FSDirectoryspa
抽象类,表明磁盘中的目录。有三个实现类:MMapDirectory、NIOFSDirectory与SimpleFSDirectory。orm
org.apache.lucene.document.Document对象
文档是索引存储与搜索的基本单位。排序
org.apache.lucene.document.Document.Document()继承
默认构造函数。
void org.apache.lucene.document.Document.add(IndexableField field)
向文档中添加一个字段。
String org.apache.lucene.document.Document.get(String name)
根据field name拿内容。若不存在返回null。
String org.apache.lucene.document.Document.toString()
内容格式为:Document<字段1信息 字段2信息 ... 字段n信息>。
一个例子为:Document<stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:4> stored,indexed,tokenized<content:try everything>>
org.apache.lucene.document.Field
基类。通常会使用它的多个子类。
org.apache.lucene.document.Field.Store
Field类的内部枚举类。有enum{YES,NO}两个值。
org.apache.lucene.document.FieldType
描述一个Field的配置信息,包括是否分词、是否存储等。
org.apache.lucene.document.FieldType.FieldType()
默认构造函数。
void org.apache.lucene.document.FieldType.setStored(boolean value)
设置为true表示要在正向文件.fdx/.fdt中存储这个域。
void org.apache.lucene.document.FieldType.setTokenized(boolean value)
设置为true表示对内容按照预先配置的analyzer进行分词。
org.apache.lucene.document.TextField
Field的子类。
org.apache.lucene.document.TextField.TextField(String name, String value, Store store)
构造函数。内部调用setTokenized(true)实现分词。通常用于文档正文。
org.apache.lucene.document.StringField
Field的子类。
org.apache.lucene.document.StringField.StringField(String name, String value, Store stored)
构造函数。内部调用setTokenized(false)设置不分词。通常用于国家名、做者名、id等。
org.apache.lucene.document.NumericDocValuesField
存储long类型。日期与时间也能够转换为数字类型存储与筛选。
org.apache.lucene.document.DoubleDocValuesField
存储double类型。
org.apache.lucene.index.IndexWriter
建立并维护索引的类。
org.apache.lucene.index.IndexWriter.IndexWriter(Directory d, IndexWriterConfig conf)
构造函数。
org.apache.lucene.index.IndexWriterConfig
表明IndexWriter的配置。
org.apache.lucene.index.IndexWriterConfig.IndexWriterConfig(Analyzer analyzer)
构造函数。
void org.apache.lucene.index.IndexWriter.addDocument(Iterable<? extends IndexableField> doc)
向索引中添加文档。
void org.apache.lucene.index.IndexWriter.deleteDocuments(Term... terms)
删除指定的文档。若是只想删除单个文档,务必确保传入的域值只会匹配到单个文档,就像数据库中表的主键PrimaryKey那样。
void org.apache.lucene.index.IndexWriter.deleteDocuments(Query... queries)
删除指定的文档。注意事项同上。
void org.apache.lucene.index.IndexWriter.updateDocument(Term term, Iterable<? extends IndexableField> doc)
首先删除与term匹配的全部文档,而后添加新文档。这个方法是经过调用deleteDocuments()与addDocument()函数实现的。
int org.apache.lucene.index.IndexWriter.maxDoc()
返回索引中未删除+已删除的文档数。
int org.apache.lucene.index.IndexWriter.numDocs()
返回索引中未删除的文档数。
void org.apache.lucene.index.IndexWriter.commit()
一些更改会被缓存,如增删文档、添加索引。调用此方法当即向索引提交待定的更改。
void org.apache.lucene.index.IndexWriter.close()
关闭相关的资源并释放索引的“write lock'”。关闭前会自动提交待定的更改。
org.apache.lucene.index.IndexReader
抽象类,读索引。
DirectoryReader org.apache.lucene.index.DirectoryReader.open(Directory directory)
在指定的目录上打开索引。如 IndexReader reader=DirectoryReader.open(directory);
Document org.apache.lucene.search.IndexSearcher.doc(int docID)
根据id读doc。
org.apache.lucene.search.IndexSearcher
在单索引上搜索。
org.apache.lucene.search.IndexSearcher.IndexSearcher(IndexReader r)
构造函数。
TopDocs org.apache.lucene.search.IndexSearcher.search(Query query, int n)
搜索并返回top n 的文档。
void org.apache.lucene.search.IndexSearcher.search(Query query, Collector results)
search()的重载函数。
TopFieldDocs org.apache.lucene.search.IndexSearcher.search(Query query, int n,Sort sort)
search()的重载函数。
org.apache.lucene.search.TopDocs
类,表示搜索的返回结果。
float org.apache.lucene.search.TopDocs.getMaxScore()
结果列表中文档的最大得分值。
ScoreDoc[] org.apache.lucene.search.TopDocs.scoreDocs
public 字段,它没有get()方法,直接用。
org.apache.lucene.search.ScoreDoc
类。TopDocs内的基本存储单位。有int doc 与float score两个字段。
int org.apache.lucene.search.ScoreDoc.doc
这个ScoreDoc的id。而后可根据IndexSearcher.doc(int docID)拿到原始doc。
org.apache.lucene.search.TopFieldDocs
TopDocs的子类,表明IndexSearcher.search(Query, int, Sort).方法的返回结果。
SortField[] org.apache.lucene.search.TopFieldDocs.fields
字段。表明者若干排序依据。
ScoreDoc[] org.apache.lucene.search.TopDocs.scoreDocs
继承的父类的字段,盛放的实际是FieldDoc。
org.apache.lucene.search.FieldDoc
ScoreDoc的子类。
Object[] org.apache.lucene.search.FieldDoc.fields
字段。从前到后依次盛放着各项排序标准的分数,为int,float等。
IndexSearcher.search()->TopDocs->topdocs.scoreDocs->ScoreDoc[]->docid=ScoreDoc.doc->Document=IndexSearcher.doc(id)
org.apache.lucene.index.Term
与field概念相似,只不过field.value为完整的内容,term.value为感兴趣的切分后的词。
org.apache.lucene.index.Term.Term(String fld, String text)
构造函数。如Term term=new Term("field","content");
“this”、“,”之类的停用词通常会被收录进索引中,但在搜索的时候被过滤掉。
对域值分析并生成token,可通俗地理解为分词器。
9.Query
查询类,抽象类
TermQuery 最简单、最基本的Query,用来查询不切分的单词。依靠Term类初始化
如Query query=new TermQuery(term);
org.apache.lucene.queryparser.classic.QueryParser
此类用于将lucene查询表达式转换为内置的查询类型。
org.apache.lucene.queryparser.classic.QueryParser.QueryParser(String fieldName, Analyzer a)
构造函数。
Query org.apache.lucene.queryparser.classic.QueryParserBase.parse(String query)
获得Query对象。
编写自定义的Colletor,能够对搜索返回的文档实现更精确的控制。