Java Code Examples for org.apache.lucene.document.Field#setBoost()

The following examples show how to use org.apache.lucene.document.Field#setBoost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Parse using the provided {@link ParseContext} and return a mapping
 * update if dynamic mappings modified the mappings, or {@code null} if
 * mappings were not modified.
 */
public Mapper parse(ParseContext context) throws IOException {
    final List<Field> fields = new ArrayList<>(2);
    try {
        parseCreateField(context, fields);
        for (Field field : fields) {
            if (!customBoost()) {
                field.setBoost(fieldType().boost());
            }
            context.doc().add(field);
        }
    } catch (Exception e) {
        throw new MapperParsingException("failed to parse [" + fieldType().names().fullName() + "]", e);
    }
    multiFields.parse(this, context);
    return null;
}
 
Example 2
Source File: StringFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
    ValueAndBoost valueAndBoost = parseCreateFieldForString(context, fieldType().nullValueAsString(), fieldType().boost());
    if (valueAndBoost.value() == null) {
        return;
    }
    if (ignoreAbove > 0 && valueAndBoost.value().length() > ignoreAbove) {
        return;
    }
    if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(fieldType().names().fullName(), valueAndBoost.value(), valueAndBoost.boost());
    }

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        Field field = new Field(fieldType().names().indexName(), valueAndBoost.value(), fieldType());
        field.setBoost(valueAndBoost.boost());
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().names().indexName(), new BytesRef(valueAndBoost.value())));
    }
}
 
Example 3
Source File: GeoShapeFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Mapper parse(ParseContext context) throws IOException {
    try {
        Shape shape = context.parseExternalValue(Shape.class);
        if (shape == null) {
            ShapeBuilder shapeBuilder = ShapeBuilder.parse(context.parser(), this);
            if (shapeBuilder == null) {
                return null;
            }
            shape = shapeBuilder.build();
        }
        if (fieldType().pointsOnly() && !(shape instanceof Point)) {
            throw new MapperParsingException("[{" + fieldType().names().fullName() + "}] is configured for points only but a " +
                    ((shape instanceof JtsGeometry) ? ((JtsGeometry)shape).getGeom().getGeometryType() : shape.getClass()) + " was found");
        }
        Field[] fields = fieldType().defaultStrategy().createIndexableFields(shape);
        if (fields == null || fields.length == 0) {
            return null;
        }
        for (Field field : fields) {
            if (!customBoost()) {
                field.setBoost(fieldType().boost());
            }
            context.doc().add(field);
        }
    } catch (Exception e) {
        throw new MapperParsingException("failed to parse [" + fieldType().names().fullName() + "]", e);
    }
    return null;
}
 
Example 4
Source File: UUIDFieldBridge.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void set(String name, Object value, Document doc, LuceneOptions options) {
	Field field = new Field(name, value.toString(), options.getStore(), options.getIndex(), options.getTermVector());
	field.setBoost(options.getBoost());
	doc.add(field);
}
 
Example 5
Source File: OlatDocument.java    From olat with Apache License 2.0 4 votes vote down vote up
private Field createField(String fieldName, String content, Field.Index fieldIndex, float wight) {
    Field field = new Field(fieldName, content, Field.Store.YES, fieldIndex);
    field.setBoost(wight);
    return field;
}
 
Example 6
Source File: OlatDocument.java    From olat with Apache License 2.0 4 votes vote down vote up
private Field createField(String fieldName, String content, Field.Index fieldIndex, float wight) {
    Field field = new Field(fieldName, content, Field.Store.YES, fieldIndex);
    field.setBoost(wight);
    return field;
}