简体   繁体   English

文档字段setBoost中的lucene错误

[英]lucene error in document field setBoost

As the lucene migration guide mentioned, to set document level boost we should multiply all fields boost by boosting value. 如lucene迁移指南所述,要设置文档级别提升,我们应将所有字段提升值乘以提升值。 here is my code : 这是我的代码:

    StringField nameField = new StringField("name", name, Field.Store.YES) ;
    StringField linkField = new StringField("link", link, Field.Store.YES);
    Field descField;
    TextField reviewsField = new TextField("reviews", reviews_str, Field.Store.YES);
    TextField authorsField = new TextField("authors", authors_str, Field.Store.YES);        
    FloatField scoreField = new FloatField("score", origScore,Field.Store.YES);
    if (desc != null) {
        descField = new TextField("desc", desc, Field.Store.YES);
    } else {
        descField = new TextField("desc", "", Field.Store.YES);
    }


    doc.add(nameField);
    doc.add(linkField);
    doc.add(descField);
    doc.add(reviewsField);
    doc.add(authorsField);
    doc.add(scoreField);


    nameField.setBoost(score);
    linkField.setBoost(score);
    descField.setBoost(score);
    reviewsField.setBoost(score);
    authorsField.setBoost(score);
    scoreField.setBoost(score);

but I've got this exception when running code : 但是我在运行代码时遇到了这个异常:

Exception in thread "main" java.lang.IllegalArgumentException: You cannot set an index-time boost on an unindexed field, or one that omits norms

I've searched google. 我搜索过谷歌。 but I've got no answers. 但我没有答案。 would you please help me? 你能帮我吗?

Index-time boosts are stored in the field's norm, and both StringField and FloatField omit norms by default. 索引时间提升存储在字段的规范中,默认情况下,StringField和FloatField都忽略规范。 So, you'll need to turn them on before you set the boosts. 因此,您需要在设置增强之前将它们打开。

To turn norms on, you'll need to define your own field types: 要打开规范,您需要定义自己的字段类型:

//Start with a copy of the standard field type
FieldType myStringType = new FieldType(StringField.TYPE_STORED);
myStringType.setOmitNorms(false);
//StringField doesn't do anything special except have a customized fieldtype, so just use Field.
Field nameField = new Field("name", name, myStringType);

FieldType myFloatType = new FieldType(FloatField.TYPE_STORED);
myFloatType.setOmitNorms(false);
//For FloatField, use the appropriate FloatField ctor, instead of Field (similar for other numerics)
Field scoreField = new FloatField("score", origScore, myFloatType);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM