英文:
Range Facet on integer field in Lucene
问题
我想要在整数字段上使用范围分面。文档中说:范围分面LongRangeFacetCounts
、DoubleRangeFacetCounts
从提供的LongValuesSource
计算动态数值范围的计数,我可以在任何数值类型上使用LongRangeFacetCounts
或DoubleRangeFacetCounts
,如double
、decimal
、long
、float
,但不能用于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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论