Search in sources :

Example 1 with StrFieldSource

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

the class Grouping method addFunctionCommand.

public void addFunctionCommand(String groupByStr, SolrQueryRequest request) throws SyntaxError {
    QParser parser = QParser.getParser(groupByStr, "func", request);
    Query q = parser.getQuery();
    final Grouping.Command gc;
    if (q instanceof FunctionQuery) {
        ValueSource valueSource = ((FunctionQuery) q).getValueSource();
        if (valueSource instanceof StrFieldSource) {
            String field = ((StrFieldSource) valueSource).getField();
            CommandField commandField = new CommandField();
            commandField.groupBy = field;
            gc = commandField;
        } else {
            CommandFunc commandFunc = new CommandFunc();
            commandFunc.groupBy = valueSource;
            gc = commandFunc;
        }
    } else {
        CommandFunc commandFunc = new CommandFunc();
        commandFunc.groupBy = new QueryValueSource(q, 0.0f);
        gc = commandFunc;
    }
    gc.withinGroupSort = withinGroupSort;
    gc.key = groupByStr;
    gc.numGroups = limitDefault;
    gc.docsPerGroup = docsPerGroupDefault;
    gc.groupOffset = groupOffsetDefault;
    gc.offset = cmd.getOffset();
    gc.groupSort = groupSort;
    gc.format = defaultFormat;
    gc.totalCount = defaultTotalCount;
    if (main) {
        gc.main = true;
        gc.format = Grouping.Format.simple;
    }
    if (gc.format == Grouping.Format.simple) {
        // doesn't make sense
        gc.groupOffset = 0;
    }
    commands.add(gc);
}
Also used : FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) Query(org.apache.lucene.search.Query) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) ValueSource(org.apache.lucene.queries.function.ValueSource) StrFieldSource(org.apache.solr.schema.StrFieldSource) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource)

Example 2 with StrFieldSource

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

the class Grouping method addFieldCommand.

/**
   * Adds a field command based on the specified field.
   * If the field is not compatible with {@link CommandField} it invokes the
   * {@link #addFunctionCommand(String, org.apache.solr.request.SolrQueryRequest)} method.
   *
   * @param field The fieldname to group by.
   */
public void addFieldCommand(String field, SolrQueryRequest request) throws SyntaxError {
    // Throws an exception when field doesn't exist. Bad request.
    SchemaField schemaField = searcher.getSchema().getField(field);
    FieldType fieldType = schemaField.getType();
    ValueSource valueSource = fieldType.getValueSource(schemaField, null);
    if (!(valueSource instanceof StrFieldSource)) {
        addFunctionCommand(field, request);
        return;
    }
    Grouping.CommandField gc = new CommandField();
    gc.withinGroupSort = withinGroupSort;
    gc.groupBy = field;
    gc.key = field;
    gc.numGroups = limitDefault;
    gc.docsPerGroup = docsPerGroupDefault;
    gc.groupOffset = groupOffsetDefault;
    gc.offset = cmd.getOffset();
    gc.groupSort = groupSort;
    gc.format = defaultFormat;
    gc.totalCount = defaultTotalCount;
    if (main) {
        gc.main = true;
        gc.format = Grouping.Format.simple;
    }
    if (gc.format == Grouping.Format.simple) {
        // doesn't make sense
        gc.groupOffset = 0;
    }
    commands.add(gc);
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) ValueSource(org.apache.lucene.queries.function.ValueSource) StrFieldSource(org.apache.solr.schema.StrFieldSource) FieldType(org.apache.solr.schema.FieldType)

Example 3 with StrFieldSource

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

the class MinMaxAgg method createSlotAcc.

@Override
public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) throws IOException {
    ValueSource vs = getArg();
    if (vs instanceof StrFieldSource) {
        String field = ((StrFieldSource) vs).getField();
        SchemaField sf = fcontext.qcontext.searcher().getSchema().getField(field);
        if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
            if (sf.hasDocValues()) {
            // dv
            } else {
            // uif
            }
        } else {
            return new SingleValuedOrdAcc(fcontext, sf, numSlots);
        }
    }
    // numeric functions
    return new ValSlotAcc(vs, fcontext, numSlots);
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) ValueSource(org.apache.lucene.queries.function.ValueSource) StrFieldSource(org.apache.solr.schema.StrFieldSource)

Aggregations

ValueSource (org.apache.lucene.queries.function.ValueSource)3 StrFieldSource (org.apache.solr.schema.StrFieldSource)3 QueryValueSource (org.apache.lucene.queries.function.valuesource.QueryValueSource)2 SchemaField (org.apache.solr.schema.SchemaField)2 FunctionQuery (org.apache.lucene.queries.function.FunctionQuery)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Query (org.apache.lucene.search.Query)1 FieldType (org.apache.solr.schema.FieldType)1