Search in sources :

Example 1 with TrieLongField

use of org.apache.solr.schema.TrieLongField in project lucene-solr by apache.

the class StatsCollectorSupplierFactory method buildFieldSource.

/**
   *  Builds a value source for a given field, making sure that the field fits a given source type.
   * @param schema the schema
   * @param expressionString The name of the field to build a Field Source from.
   * @param sourceType FIELD_TYPE for any type of field, NUMBER_TYPE for numeric fields, 
   * DATE_TYPE for date fields and STRING_TYPE for string fields.
   * @return a value source
   */
private static ValueSource buildFieldSource(IndexSchema schema, String expressionString, int sourceType) {
    SchemaField sf;
    try {
        sf = schema.getField(expressionString);
    } catch (SolrException e) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "The field " + expressionString + " does not exist.", e);
    }
    FieldType type = sf.getType();
    if (type instanceof TrieIntField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new IntFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieLongField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new LongFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieFloatField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new FloatFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieDoubleField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new DoubleFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieDateField) {
        if (sourceType != DATE_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new DateFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof StrField) {
        if (sourceType != STRING_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new BytesRefFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    }
    throw new SolrException(ErrorCode.BAD_REQUEST, type.toString() + " is not a supported field type in Solr Analytics.");
}
Also used : TrieDoubleField(org.apache.solr.schema.TrieDoubleField) StrField(org.apache.solr.schema.StrField) LongFieldSource(org.apache.lucene.queries.function.valuesource.LongFieldSource) TrieIntField(org.apache.solr.schema.TrieIntField) TrieDateField(org.apache.solr.schema.TrieDateField) BytesRefFieldSource(org.apache.lucene.queries.function.valuesource.BytesRefFieldSource) FieldType(org.apache.solr.schema.FieldType) SchemaField(org.apache.solr.schema.SchemaField) DoubleFieldSource(org.apache.lucene.queries.function.valuesource.DoubleFieldSource) IntFieldSource(org.apache.lucene.queries.function.valuesource.IntFieldSource) TrieLongField(org.apache.solr.schema.TrieLongField) FloatFieldSource(org.apache.lucene.queries.function.valuesource.FloatFieldSource) DateFieldSource(org.apache.solr.analytics.util.valuesource.DateFieldSource) SolrException(org.apache.solr.common.SolrException) TrieFloatField(org.apache.solr.schema.TrieFloatField)

Example 2 with TrieLongField

use of org.apache.solr.schema.TrieLongField in project lucene-solr by apache.

the class ExportWriter method getFieldWriters.

protected FieldWriter[] getFieldWriters(String[] fields, SolrIndexSearcher searcher) throws IOException {
    IndexSchema schema = searcher.getSchema();
    FieldWriter[] writers = new FieldWriter[fields.length];
    for (int i = 0; i < fields.length; i++) {
        String field = fields[i];
        SchemaField schemaField = null;
        try {
            schemaField = schema.getField(field);
        } catch (Exception e) {
            throw new IOException(e);
        }
        if (!schemaField.hasDocValues()) {
            throw new IOException(field + " must have DocValues to use this feature.");
        }
        boolean multiValued = schemaField.multiValued();
        FieldType fieldType = schemaField.getType();
        if (fieldType instanceof TrieIntField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, true);
            } else {
                writers[i] = new IntFieldWriter(field);
            }
        } else if (fieldType instanceof TrieLongField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, true);
            } else {
                writers[i] = new LongFieldWriter(field);
            }
        } else if (fieldType instanceof TrieFloatField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, true);
            } else {
                writers[i] = new FloatFieldWriter(field);
            }
        } else if (fieldType instanceof TrieDoubleField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, true);
            } else {
                writers[i] = new DoubleFieldWriter(field);
            }
        } else if (fieldType instanceof StrField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, false);
            } else {
                writers[i] = new StringFieldWriter(field, fieldType);
            }
        } else if (fieldType instanceof TrieDateField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, false);
            } else {
                writers[i] = new DateFieldWriter(field);
            }
        } else if (fieldType instanceof BoolField) {
            if (multiValued) {
                writers[i] = new MultiFieldWriter(field, fieldType, schemaField, true);
            } else {
                writers[i] = new BoolFieldWriter(field, fieldType);
            }
        } else {
            throw new IOException("Export fields must either be one of the following types: int,float,long,double,string,date,boolean");
        }
    }
    return writers;
}
Also used : StrField(org.apache.solr.schema.StrField) TrieIntField(org.apache.solr.schema.TrieIntField) TrieDateField(org.apache.solr.schema.TrieDateField) TrieLongField(org.apache.solr.schema.TrieLongField) TrieFloatField(org.apache.solr.schema.TrieFloatField) TrieDoubleField(org.apache.solr.schema.TrieDoubleField) BoolField(org.apache.solr.schema.BoolField) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) FieldType(org.apache.solr.schema.FieldType) SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 3 with TrieLongField

use of org.apache.solr.schema.TrieLongField in project lucene-solr by apache.

the class ExportWriter method getSortDoc.

private SortDoc getSortDoc(SolrIndexSearcher searcher, SortField[] sortFields) throws IOException {
    SortValue[] sortValues = new SortValue[sortFields.length];
    IndexSchema schema = searcher.getSchema();
    for (int i = 0; i < sortFields.length; ++i) {
        SortField sf = sortFields[i];
        String field = sf.getField();
        boolean reverse = sf.getReverse();
        SchemaField schemaField = schema.getField(field);
        FieldType ft = schemaField.getType();
        if (!schemaField.hasDocValues()) {
            throw new IOException(field + " must have DocValues to use this feature.");
        }
        if (ft instanceof TrieIntField) {
            if (reverse) {
                sortValues[i] = new IntValue(field, new IntDesc());
            } else {
                sortValues[i] = new IntValue(field, new IntAsc());
            }
        } else if (ft instanceof TrieFloatField) {
            if (reverse) {
                sortValues[i] = new FloatValue(field, new FloatDesc());
            } else {
                sortValues[i] = new FloatValue(field, new FloatAsc());
            }
        } else if (ft instanceof TrieDoubleField) {
            if (reverse) {
                sortValues[i] = new DoubleValue(field, new DoubleDesc());
            } else {
                sortValues[i] = new DoubleValue(field, new DoubleAsc());
            }
        } else if (ft instanceof TrieLongField) {
            if (reverse) {
                sortValues[i] = new LongValue(field, new LongDesc());
            } else {
                sortValues[i] = new LongValue(field, new LongAsc());
            }
        } else if (ft instanceof StrField) {
            LeafReader reader = searcher.getSlowAtomicReader();
            SortedDocValues vals = reader.getSortedDocValues(field);
            if (reverse) {
                sortValues[i] = new StringValue(vals, field, new IntDesc());
            } else {
                sortValues[i] = new StringValue(vals, field, new IntAsc());
            }
        } else if (ft instanceof TrieDateField) {
            if (reverse) {
                sortValues[i] = new LongValue(field, new LongDesc());
            } else {
                sortValues[i] = new LongValue(field, new LongAsc());
            }
        } else if (ft instanceof BoolField) {
            // This is a bit of a hack, but since the boolean field stores ByteRefs, just like Strings
            // _and_ since "F" happens to sort before "T" (thus false sorts "less" than true)
            // we can just use the existing StringValue here.
            LeafReader reader = searcher.getSlowAtomicReader();
            SortedDocValues vals = reader.getSortedDocValues(field);
            if (reverse) {
                sortValues[i] = new StringValue(vals, field, new IntDesc());
            } else {
                sortValues[i] = new StringValue(vals, field, new IntAsc());
            }
        } else {
            throw new IOException("Sort fields must be one of the following types: int,float,long,double,string,date,boolean");
        }
    }
    if (sortValues.length == 1) {
        return new SingleValueSortDoc(sortValues[0]);
    } else if (sortValues.length == 2) {
        return new DoubleValueSortDoc(sortValues[0], sortValues[1]);
    } else if (sortValues.length == 3) {
        return new TripleValueSortDoc(sortValues[0], sortValues[1], sortValues[2]);
    } else if (sortValues.length == 4) {
        return new QuadValueSortDoc(sortValues[0], sortValues[1], sortValues[2], sortValues[3]);
    } else {
        throw new IOException("A max of 4 sorts can be specified");
    }
}
Also used : StrField(org.apache.solr.schema.StrField) TrieIntField(org.apache.solr.schema.TrieIntField) SortField(org.apache.lucene.search.SortField) TrieDateField(org.apache.solr.schema.TrieDateField) TrieLongField(org.apache.solr.schema.TrieLongField) TrieFloatField(org.apache.solr.schema.TrieFloatField) TrieDoubleField(org.apache.solr.schema.TrieDoubleField) BoolField(org.apache.solr.schema.BoolField) LeafReader(org.apache.lucene.index.LeafReader) IOException(java.io.IOException) SortedDocValues(org.apache.lucene.index.SortedDocValues) FieldType(org.apache.solr.schema.FieldType) SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema)

Aggregations

FieldType (org.apache.solr.schema.FieldType)3 SchemaField (org.apache.solr.schema.SchemaField)3 StrField (org.apache.solr.schema.StrField)3 TrieDateField (org.apache.solr.schema.TrieDateField)3 TrieDoubleField (org.apache.solr.schema.TrieDoubleField)3 TrieFloatField (org.apache.solr.schema.TrieFloatField)3 TrieIntField (org.apache.solr.schema.TrieIntField)3 TrieLongField (org.apache.solr.schema.TrieLongField)3 IOException (java.io.IOException)2 SolrException (org.apache.solr.common.SolrException)2 BoolField (org.apache.solr.schema.BoolField)2 IndexSchema (org.apache.solr.schema.IndexSchema)2 LeafReader (org.apache.lucene.index.LeafReader)1 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 BytesRefFieldSource (org.apache.lucene.queries.function.valuesource.BytesRefFieldSource)1 DoubleFieldSource (org.apache.lucene.queries.function.valuesource.DoubleFieldSource)1 FloatFieldSource (org.apache.lucene.queries.function.valuesource.FloatFieldSource)1 IntFieldSource (org.apache.lucene.queries.function.valuesource.IntFieldSource)1 LongFieldSource (org.apache.lucene.queries.function.valuesource.LongFieldSource)1 SortField (org.apache.lucene.search.SortField)1