Search in sources :

Example 6 with LegacyFieldType

use of org.apache.solr.legacy.LegacyFieldType in project lucene-solr by apache.

the class TrieDateFieldSource method createField.

@Override
public IndexableField createField(SchemaField field, Object value) {
    boolean indexed = field.indexed();
    boolean stored = field.stored();
    boolean docValues = field.hasDocValues();
    if (!indexed && !stored && !docValues) {
        if (log.isTraceEnabled())
            log.trace("Ignoring unindexed/unstored field: " + field);
        return null;
    }
    LegacyFieldType ft = new LegacyFieldType();
    ft.setStored(stored);
    ft.setTokenized(true);
    ft.setOmitNorms(field.omitNorms());
    ft.setIndexOptions(field.indexOptions());
    switch(type) {
        case INTEGER:
            ft.setNumericType(LegacyNumericType.INT);
            break;
        case FLOAT:
            ft.setNumericType(LegacyNumericType.FLOAT);
            break;
        case LONG:
            ft.setNumericType(LegacyNumericType.LONG);
            break;
        case DOUBLE:
            ft.setNumericType(LegacyNumericType.DOUBLE);
            break;
        case DATE:
            ft.setNumericType(LegacyNumericType.LONG);
            break;
        default:
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }
    ft.setNumericPrecisionStep(precisionStep);
    final org.apache.lucene.document.Field f;
    switch(type) {
        case INTEGER:
            int i = (value instanceof Number) ? ((Number) value).intValue() : Integer.parseInt(value.toString());
            f = new LegacyIntField(field.getName(), i, ft);
            break;
        case FLOAT:
            float fl = (value instanceof Number) ? ((Number) value).floatValue() : Float.parseFloat(value.toString());
            f = new LegacyFloatField(field.getName(), fl, ft);
            break;
        case LONG:
            long l = (value instanceof Number) ? ((Number) value).longValue() : Long.parseLong(value.toString());
            f = new LegacyLongField(field.getName(), l, ft);
            break;
        case DOUBLE:
            double d = (value instanceof Number) ? ((Number) value).doubleValue() : Double.parseDouble(value.toString());
            f = new LegacyDoubleField(field.getName(), d, ft);
            break;
        case DATE:
            Date date = (value instanceof Date) ? ((Date) value) : DateMathParser.parseMath(null, value.toString());
            f = new LegacyLongField(field.getName(), date.getTime(), ft);
            break;
        default:
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }
    return f;
}
Also used : LegacyFieldType(org.apache.solr.legacy.LegacyFieldType) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) Date(java.util.Date) MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) LegacyLongField(org.apache.solr.legacy.LegacyLongField) LegacyFloatField(org.apache.solr.legacy.LegacyFloatField) SolrException(org.apache.solr.common.SolrException) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Example 7 with LegacyFieldType

use of org.apache.solr.legacy.LegacyFieldType in project lucene-solr by apache.

the class EnumField method createField.

/**
   * {@inheritDoc}
   */
@Override
public IndexableField createField(SchemaField field, Object value) {
    final boolean indexed = field.indexed();
    final boolean stored = field.stored();
    final boolean docValues = field.hasDocValues();
    if (!indexed && !stored && !docValues) {
        if (log.isTraceEnabled())
            log.trace("Ignoring unindexed/unstored field: " + field);
        return null;
    }
    final Integer intValue = stringValueToIntValue(value.toString());
    if (intValue == null || intValue.equals(DEFAULT_VALUE))
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown value for enum field: " + value.toString());
    final LegacyFieldType newType = new LegacyFieldType();
    newType.setTokenized(field.isTokenized());
    newType.setStored(field.stored());
    newType.setOmitNorms(field.omitNorms());
    newType.setIndexOptions(field.indexOptions());
    newType.setStoreTermVectors(field.storeTermVector());
    newType.setStoreTermVectorOffsets(field.storeTermOffsets());
    newType.setStoreTermVectorPositions(field.storeTermPositions());
    newType.setStoreTermVectorPayloads(field.storeTermPayloads());
    newType.setNumericType(LegacyNumericType.INT);
    newType.setNumericPrecisionStep(DEFAULT_PRECISION_STEP);
    return new LegacyIntField(field.getName(), intValue.intValue(), newType);
}
Also used : LegacyFieldType(org.apache.solr.legacy.LegacyFieldType) SolrException(org.apache.solr.common.SolrException) LegacyIntField(org.apache.solr.legacy.LegacyIntField)

Aggregations

LegacyFieldType (org.apache.solr.legacy.LegacyFieldType)7 LegacyIntField (org.apache.solr.legacy.LegacyIntField)4 Document (org.apache.lucene.document.Document)3 Type (org.apache.solr.uninverting.UninvertingReader.Type)3 HashMap (java.util.HashMap)2 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 SolrException (org.apache.solr.common.SolrException)2 LegacyLongField (org.apache.solr.legacy.LegacyLongField)2 BeforeClass (org.junit.BeforeClass)2 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 IntPoint (org.apache.lucene.document.IntPoint)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 DocValuesType (org.apache.lucene.index.DocValuesType)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 LeafReader (org.apache.lucene.index.LeafReader)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1