【发布时间】:2018-09-10 15:07:05
【问题描述】:
我正在使用 Lucene 7.4 来索引和存储字段。在查看 API 时,我注意到提供了用于索引大多数数据类型(字节、整数、长整型、双精度、浮点数、字符串)的字段类,但没有用于 Shorts 的字段类。 https://lucene.apache.org/core/7_4_0/core/org/apache/lucene/document/Field.html
我的理解是,我可以使用默认的 Field 类为 Shorts 创建一个“自定义”字段类型,但我不确定如何正确构造它,因为没有构造函数接受我的字段类型:
FieldType shortFieldType = new FieldType();
shortFieldType.setStored(true);
shortFieldType.setTokenized(false);
shortFieldType.setIndexOptions(IndexOptions.DOCS);
shortFieldType.setDocValuesType(DocValuesType.NUMERIC);
Field shortField = new Field("fieldName", ???, shortFieldType);
shortField.setShortValue((Short) shortValue);
document.add(shortField);
我也很好奇为什么 API 中没有定义 ShortPoint 类。我可能会使用 IntPoint 侥幸逃脱,但我想避免浪费空间。我之前所做的所有研究都参考了具有不同类结构的早期版本的 Lucene。
【问题讨论】: