一、field说明
对于一个文档来说有多个域,域也是对应的搜索模块。
二、field的
1.一些子类
首先是一个不变的属性值,这类字段还有一个主要用途,就是可以用于对搜索的返回结果集排序或是按范围查询FloatField
DoubleField
IntField
LongField
BinaryDocValuesField
NumericDocValuesField
SortedDocValuesField
SortedSetDocValuesField
StoredField 整个域要存储的
StringField 是一个不需要分词,而直接用于索引的字符串
TextField 是一大块需要经过分词的文本
2.基本使用格式
StringField
StringField(String name, String value, Field.Store stored)
TextField
TextField(String name, Reader reader)
Creates a new un-stored TextField with Reader value.
TextField(String name, String value, Field.Store store)
Creates a new TextField with String value.
TextField(String name, TokenStream stream)
Creates a new un-stored TextField with TokenStream value.
StoreField
StoredField(String name, byte[] value)
Create a stored-only field with the given binary value.
StoredField(String name, byte[] value, int offset, int length)
Create a stored-only field with the given binary value.
StoredField(String name, BytesRef value)
Create a stored-only field with the given binary value.
StoredField(String name, double value)
Create a stored-only field with the given double value.
StoredField(String name, float value)
Create a stored-only field with the given float value.
StoredField(String name, int value)
Create a stored-only field with the given integer value.
StoredField(String name, long value)
Create a stored-only field with the given long value.
StoredField(String name, String value)
Create a stored-only field with the given string value.
DoubleFielt 数值类型的方法一直
DoubleField(String name, double value, Field.Store stored)
Creates a stored or un-stored DoubleField with the provided value and default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4).
DoubleField(String name, double value, FieldType type)
Expert: allows you to customize the FieldType.
DocValues的格式
BinaryDocValuesField(String name, BytesRef value)
Create a new binary DocValues field.
3.域的选项
索引选项
Index.ANALYZED 域值被分解切能被搜索,对于普通的文本(正文,标题,摘要等)
Index.NOT_ANALYZED 能被搜索但是不被分解,用于精确匹配 日期了,人名了
Index.ANALYZED_NO_NORMS 进行分词但是不存储norms信息,这个norms中包括了创建索引的时间和权值等信息
Index.NOT_ANALYZED_NO_NORMS 即不进行分词也不存储norms信息
Index.NO 对应不会被搜索
存储选项
Store.YES 存储 小的信息
Store。NO 不存储 大的文本
搭配
ANALYZED | YES | 文档标题和摘要 |
ANALYZED | NO | 文档正文 |
NOT_ANALYZED | YES | 标识符(主键、文件名),电话号码、身份证号,姓名,日期 |
NOT_ANALYZED | NO | 隐藏关键字 |
NO | YES | 文档类型,数据库主键(不进行索引) |