Search in sources :

Example 76 with IndexableField

use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.

the class ICUCollationField method createFields.

@Override
public List<IndexableField> createFields(SchemaField field, Object value) {
    if (field.hasDocValues()) {
        List<IndexableField> fields = new ArrayList<>();
        fields.add(createField(field, value));
        final BytesRef bytes = getCollationKey(field.getName(), value.toString());
        if (field.multiValued()) {
            fields.add(new SortedSetDocValuesField(field.getName(), bytes));
        } else {
            fields.add(new SortedDocValuesField(field.getName(), bytes));
        }
        return fields;
    } else {
        return Collections.singletonList(createField(field, value));
    }
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) ArrayList(java.util.ArrayList) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BytesRef(org.apache.lucene.util.BytesRef)

Example 77 with IndexableField

use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.

the class XLSXWriter method writeArray.

@Override
public void writeArray(String name, Iterator val) throws IOException {
    StringBuffer output = new StringBuffer();
    while (val.hasNext()) {
        Object v = val.next();
        if (v instanceof IndexableField) {
            IndexableField f = (IndexableField) v;
            if (v instanceof Date) {
                output.append(((Date) val).toInstant().toString() + "; ");
            } else {
                output.append(f.stringValue() + "; ");
            }
        } else {
            output.append(v.toString() + "; ");
        }
    }
    if (output.length() > 0) {
        output.deleteCharAt(output.length() - 1);
        output.deleteCharAt(output.length() - 1);
    }
    writeStr(name, output.toString(), false);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) Date(java.util.Date)

Example 78 with IndexableField

use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.

the class EnumField method createFields.

/**
   * {@inheritDoc}
   */
@Override
public List<IndexableField> createFields(SchemaField sf, Object value) {
    if (sf.hasDocValues()) {
        List<IndexableField> fields = new ArrayList<>();
        final IndexableField field = createField(sf, value);
        fields.add(field);
        if (sf.multiValued()) {
            BytesRefBuilder bytes = new BytesRefBuilder();
            readableToIndexed(stringValueToIntValue(value.toString()).toString(), bytes);
            fields.add(new SortedSetDocValuesField(sf.getName(), bytes.toBytesRef()));
        } else {
            final long bits = field.numericValue().intValue();
            fields.add(new NumericDocValuesField(sf.getName(), bits));
        }
        return fields;
    } else {
        return Collections.singletonList(createField(sf, value));
    }
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) ArrayList(java.util.ArrayList) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField)

Example 79 with IndexableField

use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.

the class FieldType method toObject.

public Object toObject(SchemaField sf, BytesRef term) {
    final CharsRefBuilder ref = new CharsRefBuilder();
    indexedToReadable(term, ref);
    final IndexableField f = createField(sf, ref.toString());
    return toObject(f);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder)

Example 80 with IndexableField

use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.

the class BoolFieldSource method createFields.

@Override
public List<IndexableField> createFields(SchemaField field, Object value) {
    IndexableField fval = createField(field, value);
    if (field.hasDocValues()) {
        IndexableField docval;
        final BytesRef bytes = new BytesRef(toInternal(value.toString()));
        if (field.multiValued()) {
            docval = new SortedSetDocValuesField(field.getName(), bytes);
        } else {
            docval = new SortedDocValuesField(field.getName(), bytes);
        }
        // Only create a list of we have 2 values...
        if (fval != null) {
            List<IndexableField> fields = new ArrayList<>(2);
            fields.add(fval);
            fields.add(docval);
            return fields;
        }
        fval = docval;
    }
    return Collections.singletonList(fval);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) ArrayList(java.util.ArrayList) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BytesRef(org.apache.lucene.util.BytesRef)

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