Search in sources :

Example 1 with IndexableField

use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.

the class FieldMapper method parse.

/**
     * 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<IndexableField> fields = new ArrayList<>(2);
    try {
        parseCreateField(context, fields);
        for (IndexableField field : fields) {
            if (!customBoost() && // don't set boosts eg. on dv fields
            field.fieldType().indexOptions() != IndexOptions.NONE && indexCreatedVersion.before(Version.V_5_0_0_alpha1)) {
                ((Field) (field)).setBoost(fieldType().boost());
            }
            context.doc().add(field);
        }
    } catch (Exception e) {
        throw new MapperParsingException("failed to parse [" + fieldType().name() + "]", e);
    }
    multiFields.parse(this, context);
    return null;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) IndexableField(org.apache.lucene.index.IndexableField) Field(org.apache.lucene.document.Field) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with IndexableField

use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.

the class UidFieldMapper method parseCreateField.

@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    Field uid = new Field(NAME, Uid.createUid(context.sourceToParse().type(), context.sourceToParse().id()), Defaults.FIELD_TYPE);
    fields.add(uid);
    if (fieldType().hasDocValues()) {
        fields.add(new BinaryDocValuesField(NAME, new BytesRef(uid.stringValue())));
    }
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) BinaryDocValuesField(org.apache.lucene.document.BinaryDocValuesField) Field(org.apache.lucene.document.Field) BinaryDocValuesField(org.apache.lucene.document.BinaryDocValuesField) BytesRef(org.apache.lucene.util.BytesRef)

Example 3 with IndexableField

use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.

the class VersionFieldMapper method parseCreateField.

@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    // see InternalEngine.updateVersion to see where the real version value is set
    final Field version = new NumericDocValuesField(NAME, -1L);
    context.version(version);
    fields.add(version);
}
Also used : NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexableField(org.apache.lucene.index.IndexableField) Field(org.apache.lucene.document.Field) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField)

Example 4 with IndexableField

use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.

the class CategoryContextMapping method parseContext.

@Override
public Set<CharSequence> parseContext(Document document) {
    Set<CharSequence> values = null;
    if (fieldName != null) {
        IndexableField[] fields = document.getFields(fieldName);
        values = new HashSet<>(fields.length);
        for (IndexableField field : fields) {
            values.add(field.stringValue());
        }
    }
    return (values == null) ? Collections.<CharSequence>emptySet() : values;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField)

Example 5 with IndexableField

use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.

the class CategoryContextMappingTests method testIndexingWithMultipleContexts.

public void testIndexingWithMultipleContexts() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().startObject().field("name", "type").field("type", "category").endObject().endArray().endObject().endObject().endObject().endObject().string();
    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
    MappedFieldType completionFieldType = fieldMapper.fieldType();
    XContentBuilder builder = jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").field("weight", 5).startObject("contexts").array("ctx", "ctx1", "ctx2", "ctx3").array("type", "typr3", "ftg").endObject().endObject().endArray().endObject();
    ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", builder.bytes());
    IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
    assertContextSuggestFields(fields, 3);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

IndexableField (org.apache.lucene.index.IndexableField)276 Document (org.apache.lucene.document.Document)90 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)75 Matchers.containsString (org.hamcrest.Matchers.containsString)57 BytesRef (org.apache.lucene.util.BytesRef)53 ArrayList (java.util.ArrayList)50 Field (org.apache.lucene.document.Field)34 Test (org.junit.Test)28 IOException (java.io.IOException)27 HashMap (java.util.HashMap)24 IndexReader (org.apache.lucene.index.IndexReader)24 Directory (org.apache.lucene.store.Directory)23 Map (java.util.Map)22 TopDocs (org.apache.lucene.search.TopDocs)22 Term (org.apache.lucene.index.Term)21 HashSet (java.util.HashSet)20 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)20 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)20 Query (org.apache.lucene.search.Query)19 Analyzer (org.apache.lucene.analysis.Analyzer)18