当Sorting, faceting时, 通过设置DocValues来保存记录域值的方式是非常高效的。
Solr通过倒排建立索引, 首先建立term list, 然后每个term对应一个document list。 这样
因为传统的Solr建立Index是通过倒排索引建立的Index, 首先建立term list, 然后每个term对应一个document list, 这样的结构使得查询能够非常快速, 因为terms在内存中有已经准备好的term-to-documentList.
对于其它的我们的搜索, 如sorting, faceting, 和highlighting, 倒排索引并不是非常有效。 比如对faceting来讲, 必须先得到在每一个document中的term组装成结果集, 再得到document IDs. 这些所有操作都是在内存中, 当数据量大的时候 , 会使速度减慢, 并且会占用宝贵的内存资源。
在Lucene4.0以后,DocValue 以面向列的存储方式被引用。这是以document-to-value mapping 的方式在index时被创建。 减轻了fieldCache的内存需求, 使faceting, sorting, grouping更加快速。
- 启动DocValues
<field name="manu_exact" type="string" indexed="false" stored="false" docValues="true" />
如果没有添加DocValues之前索引已经建好, 现在又需要DocValues则需要重新创建。
DocValues只有在特定的field types中起作用, 不同的filed type决定不同的Lucene docValue 类型。可用的Solr field 类型有:
- StrField and UUIDField.
- field is single-valued (i.e., multi-valued is false), Lucene will use the SORTED type.
- field is multi-valued, Lucene will use the SORTED_SET type.
- 以Trie开头的 numeric fields, date fields and EnumField.
- field is single-valued (i.e., multi-valued is false), Lucene will use the NUMERIC type.
- If the field is multi-valued, Lucene will use the SORTED_SET type.
- 返回的值并非是原始输入的顺序,而是经过排序之后进行返回
- 当有多个相同的值时, 只有一个被返回