Search in sources :

Example 51 with SortedSetDocValuesField

use of org.apache.lucene.document.SortedSetDocValuesField 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 52 with SortedSetDocValuesField

use of org.apache.lucene.document.SortedSetDocValuesField 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 53 with SortedSetDocValuesField

use of org.apache.lucene.document.SortedSetDocValuesField 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)

Example 54 with SortedSetDocValuesField

use of org.apache.lucene.document.SortedSetDocValuesField in project lucene-solr by apache.

the class CollationField 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 55 with SortedSetDocValuesField

use of org.apache.lucene.document.SortedSetDocValuesField in project lucene-solr by apache.

the class TrieDateFieldSource method createFields.

@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();
            storedToIndexed(field, bytes);
            fields.add(new SortedSetDocValuesField(sf.getName(), bytes.get()));
        } else {
            final long bits;
            if (field.numericValue() instanceof Integer || field.numericValue() instanceof Long) {
                bits = field.numericValue().longValue();
            } else if (field.numericValue() instanceof Float) {
                bits = Float.floatToIntBits(field.numericValue().floatValue());
            } else {
                assert field.numericValue() instanceof Double;
                bits = Double.doubleToLongBits(field.numericValue().doubleValue());
            }
            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) MutableValueLong(org.apache.lucene.util.mutable.MutableValueLong) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField)

Aggregations

SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)98 BytesRef (org.apache.lucene.util.BytesRef)96 Document (org.apache.lucene.document.Document)82 Directory (org.apache.lucene.store.Directory)74 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)38 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)36 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)33 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)27 IndexReader (org.apache.lucene.index.IndexReader)27 StringField (org.apache.lucene.document.StringField)23 BinaryDocValuesField (org.apache.lucene.document.BinaryDocValuesField)22 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)20 ArrayList (java.util.ArrayList)18 Analyzer (org.apache.lucene.analysis.Analyzer)14 IndexableField (org.apache.lucene.index.IndexableField)13 Field (org.apache.lucene.document.Field)12 DirectoryReader (org.apache.lucene.index.DirectoryReader)11 LeafReader (org.apache.lucene.index.LeafReader)11 IntPoint (org.apache.lucene.document.IntPoint)10 StoredField (org.apache.lucene.document.StoredField)10