Lucene 如何为范围方面的数值编制索引?

Lucene 如何为范围方面的数值编制索引?,lucene,hibernate-search,Lucene,Hibernate Search,我的项目有很多产品。产品具有属性。属性可以动态创建。我需要属性的范围方面。但是没有数字刻面。下面的示例仅适用于字符串镶嵌。如何获取属性的数值范围方面 //product entity @Indexed public class Product{ // ommited @Field(analyze = Analyze.NO, bridge = @FieldBridge(impl = AttrFieldBridge.class)) private List<Attrib

我的项目有很多产品。产品具有属性。属性可以动态创建。我需要属性的范围方面。但是没有数字刻面。下面的示例仅适用于字符串镶嵌。如何获取属性的数值范围方面

//product entity
@Indexed
public class Product{
    // ommited
    @Field(analyze = Analyze.NO, bridge = @FieldBridge(impl = AttrFieldBridge.class))
    private List<Attribute> attributes;
    // ommited
}

// attribute bridge used in Product
public class AttrFieldBridge implements FieldBridge {

public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
    if (value != null) {
        @SuppressWarnings("unchecked")
        List<Attribute> attrs = (List<Attribute>) value;
        for (Attribute attr : attrs){
            String fieldName = name+"_"+attr.getAttributeId();
            double fieldValue = attr.getVal();

            document.add(new SortedSetDocValuesFacetField(fieldName, Double.toString(fieldValue))); // here I need something like SortedSetDocNumericValuesFacetField
            document.add(new DoubleField(fieldName, fieldValue, Field.Store.NO));
        }
    }
}
//产品实体
@索引
公共类产品{
//奥米特
@字段(analyze=analyze.NO,bridge=@FieldBridge(impl=AttrFieldBridge.class))
私有列表属性;
//奥米特
}
//属性桥在产品中的应用
公共类AttrFieldBridge实现了FieldBridge{
公共无效集(字符串名称、对象值、文档、LuceneOptions LuceneOptions){
if(值!=null){
@抑制警告(“未选中”)
列表属性=(列表)值;
for(属性属性attr:attrs){
字符串fieldName=name+“”+attr.getAttributeId();
double fieldValue=attr.getVal();
document.add(new SortedSetDocValuesFacetField(fieldName,Double.toString(fieldValue));//这里我需要类似SortedSetDocNumericValuesFacetField的内容
添加(新的双字段(fieldName、fieldValue、Field.Store.NO));
}
}
}
}

警告 首先,要知道Hibernate搜索不支持桥接定义字段上的刻面(目前还不支持)。如果是,您就不必自己添加镶嵌面字段。你可以请求这样的支持

现在,您可以自己尝试通过索引刻面字段来解决这个问题,并希望查询端能够工作。但是,如果它能工作,就不支持使用Hibernate搜索,这意味着只需对Hibernate搜索进行一次小的更新,它就可能中断

解决方案 要正确索引镶嵌面字段,应使用
DoubleDocValuesField

// attribute bridge used in Product
public class AttrFieldBridge implements FieldBridge {

public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
    if (value != null) {
        @SuppressWarnings("unchecked")
        List<Attribute> attrs = (List<Attribute>) value;
        for (Attribute attr : attrs){
            String fieldName = name+"_"+attr.getAttributeId();
            double fieldValue = attr.getVal();

            document.add(new DoubleDocValuesField(fieldName, fieldValue));
            document.add(new DoubleField(fieldName, fieldValue, Field.Store.NO));
        }
    }
}
//产品中使用的属性桥
公共类AttrFieldBridge实现了FieldBridge{
公共无效集(字符串名称、对象值、文档、LuceneOptions LuceneOptions){
if(值!=null){
@抑制警告(“未选中”)
列表

警告 首先,要知道Hibernate搜索不支持桥接定义字段上的刻面。如果支持,您就不必自己添加刻面字段。您可以请求这样的支持

现在,您可以自己尝试通过索引刻面字段来解决这一问题,并希望查询端能够工作。如果它工作,则不支持使用Hibernate搜索,这意味着可能只需对Hibernate搜索进行一次小的更新即可中断

解决方案 要正确索引镶嵌面字段,应使用
DoubleDocValuesField

// attribute bridge used in Product
public class AttrFieldBridge implements FieldBridge {

public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
    if (value != null) {
        @SuppressWarnings("unchecked")
        List<Attribute> attrs = (List<Attribute>) value;
        for (Attribute attr : attrs){
            String fieldName = name+"_"+attr.getAttributeId();
            double fieldValue = attr.getVal();

            document.add(new DoubleDocValuesField(fieldName, fieldValue));
            document.add(new DoubleField(fieldName, fieldValue, Field.Store.NO));
        }
    }
}
//产品中使用的属性桥
公共类AttrFieldBridge实现了FieldBridge{
公共无效集(字符串名称、对象值、文档、LuceneOptions LuceneOptions){
if(值!=null){
@抑制警告(“未选中”)
名单