Index Lucene:如何获取LongPoint字段

时间:2018-06-11 07:59:30

标签: java lucene

我正在寻找解决方法如何通过字段名称获取索引的PointValues的条款。对于String,它非常简单(我的示例代码):

    IndexReader reader = caseIndexer.getIndexReader();

    Fields fields = MultiFields.getFields(reader);
    Iterator<String> names = fields.iterator();
    Map<String, Terms> map = new HashMap<>();
    while (names.hasNext()) {
        String name = names.next();
        // logger.info("->>fieldName: {}", name);
        Terms terms = fields.terms(name);
        map.put(name, terms);
        TermsEnum termsEnum = terms.iterator();
        BytesRef text;
        while ((text = termsEnum.next()) != null) {
            System.out.println("field=" + name + "; text=" + text.utf8ToString());
        }
    }

我知道如何获取最大值和最小值等简单统计信息(示例代码):

    List<FieldInfo> allFields = new ArrayList<>();
    for (LeafReaderContext ctx : reader.leaves()) {
        LeafReader lr = ctx.reader();
        Iterator<FieldInfo> infos = lr.getFieldInfos().iterator();
        PointValues values = lr.getPointValues();
        while (infos.hasNext()) {
            FieldInfo info = infos.next();
            allFields.add(info);

            if (DocValuesType.SORTED_NUMERIC.equals(info.getDocValuesType())) {

                final int numDimensions = values.getNumDimensions(info.name);
                final int numBytesPerDimension = values.getBytesPerDimension(info.name);
                byte[] leafMinValue = values.getMinPackedValue(info.name);
                long size = values.size(info.name);
                byte[] leafMaxValue = values.getMaxPackedValue(info.name);
                long minValueLong = NumericUtils.sortableBytesToLong(leafMinValue, 0);
                long maxValueLong = NumericUtils.sortableBytesToLong(leafMaxValue, 0);
                double minValueDouble = NumericUtils.sortableLongToDouble(minValueLong);
                System.out.println("field=" + info.name + "; minValueLong=" + minValueLong + "; maxValueLong="
                        + maxValueLong + "; minValueDouble=" + minValueDouble + "; numDimensions=" + numDimensions
                        + "; numBytesPerDimension=" + numBytesPerDimension + "; size=" + size);

            }
        }

    }

但如何获得积分条款?

1 个答案:

答案 0 :(得分:1)

如果您需要获取LongPoint字段的原始值,则需要按照LongPoint Field JavaDoc中的说明将值存储到专用的StoredField中。

通常:Point(范围/精确用例)和DocValues(排序用例)字段用于特定的内部Lucene使用,并且这些值不可用于搜索返回值。