在Lucene中对整数字段的范围分面

huangapple go评论58阅读模式
英文:

Range Facet on integer field in Lucene

问题

我想要在整数字段上使用范围分面。文档中说:范围分面LongRangeFacetCountsDoubleRangeFacetCounts从提供的LongValuesSource计算动态数值范围的计数,我可以在任何数值类型上使用LongRangeFacetCountsDoubleRangeFacetCounts,如doubledecimallongfloat,但不能用于int,这很让人困扰。有人有从整数字段获取范围分面的经验吗?谢谢。

英文:

So as the title says, I want to have range facets on integer fields.

In the documentation it says: Range faceting LongRangeFacetCounts, DoubleRangeFacetCounts compute counts for a dynamic numeric range from a provided LongValuesSource
I can use LongRanceFacetCounts or DoubleRangeFacetCounts for any numeric type: double, decimal, long, float, but not int, which is annoying.

Does anybody have experience with getting a range facet from an int field?

Thank you

答案1

得分: 1

您可以为整数值字段获取一个LongValuesSource:LongValuesSource.fromIntField

(或者,如果您希望,可以获取一个DoubleValuesSource:DoubleValuesSource.fromIntField

英文:

You can get a LongValuesSource for an int-valued field: LongValuesSource.fromIntField

(Or, if you wish, a DoubleValuesSource: DoubleValuesSource.fromIntField)

答案2

得分: 1

感谢 @femtoRgon 的评论,我找到了解决方案适用于 Lucene.net

DoubleRangeFacetCounts 有一个像这样的构造函数:

DoubleRangeFacetCounts(string field, **ValueSource valueSource,** FacetsCollector hits, params DoubleRange[] ranges)

这里的 valueSource 参数很有趣,因为我们可以传递不同的类实现。

例如:如果字段是整数,可以使用 new Int32FieldSource(definitionFacet.Key),如果字段是双精度数,则可以使用 new DoubleFieldSource(definitionFacet.Key) 等等。

事后看来很明显,但我一开始没有注意到。

英文:

Thanks to @femtoRgon's comment, I found a solution for Lucene.net.

The DoubleRangeFacetCounts has a constructor like this:

DoubleRangeFacetCounts(string field, **ValueSource valueSource,** FacetsCollector hits, params DoubleRange[] ranges)

The valueSource param is interesting here, because we can pass different implementation of the class.

Fx.: new Int32FieldSource(definitionFacet.Key) if the field is an int
or new DoubleFieldSource(definitionFacet.Key) if the field is a double etc.

In hindsight it is obvious, but I didn't notice it at first

huangapple
  • 本文由 发表于 2020年1月3日 19:54:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578180.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定