1.Lucene是什么?
2.Luncene的核心索引类
Field类型:
UnIndexed - 不被分析也不被索引,但它的值存储在索引中,这个类型适合于你需要和搜索结果一起显示的字段(如URL或数据库主键)
UnStored - 被分析并索引,但是值不被存储在索引中,适合索引大量的文本;如网页
Text - 被分析并索引,这种字段类型可以被搜索,但小心字段大小(数据来自String可以被存储,但如果数据来自Reader则将不会被存储)
不同字段类型的特征和使用方法
Fied method/type | Analyzed | Indexed | Stored | Example usage |
Field.Keyword(String,String) Field.Keyword(String,Date) |
| ? | ? | Telephone and Social Security numbers, URLs, personal names, Dates |
Field.UnIndexed(String,String) |
|
| ? | Document type (PDF, HTML, and so on), if not used as search criteria |
Field.UnStored(String,String) | ? | ? |
| Document titles and content |
Field.Text(String,String) | ? | ? | ? | Document titles and content |
Field.Text(String,Reader) | ? | ? |
| Document titles and content |
3.Lucene核心搜索类
IndexSearcher - 以只读方式打开索引的一个类,经提供了几个搜索方法
Term - Term是搜索的基本单元,与Field对象类似,它由字段的名称和字段的值组成
Query - Query是最基本的抽象父类,Lucene包含一些Query的具体子类
TermQuery - TermQuery是Lucene支持的最基本的查询类型,它用来匹配含有指定值的字段的文档
Hits - 搜索结果的简单容器,Hits并不从索引加载所有文档而是每次一小部分