Search in sources :

Example 1 with ValueSource

use of org.apache.lucene.queries.function.ValueSource in project lucene-solr by apache.

the class BoostQParserPlugin method createParser.

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {

        QParser baseParser;

        ValueSource vs;

        String b;

        @Override
        public Query parse() throws SyntaxError {
            b = localParams.get(BOOSTFUNC);
            baseParser = subQuery(localParams.get(QueryParsing.V), null);
            Query q = baseParser.getQuery();
            if (b == null)
                return q;
            Query bq = subQuery(b, FunctionQParserPlugin.NAME).getQuery();
            if (bq instanceof FunctionQuery) {
                vs = ((FunctionQuery) bq).getValueSource();
            } else {
                vs = new QueryValueSource(bq, 0.0f);
            }
            return new BoostedQuery(q, vs);
        }

        @Override
        public String[] getDefaultHighlightFields() {
            return baseParser.getDefaultHighlightFields();
        }

        @Override
        public Query getHighlightQuery() throws SyntaxError {
            return baseParser.getHighlightQuery();
        }

        @Override
        public void addDebugInfo(NamedList<Object> debugInfo) {
            // encapsulate base debug info in a sub-list?
            baseParser.addDebugInfo(debugInfo);
            debugInfo.add("boost_str", b);
            debugInfo.add("boost_parsed", vs);
        }
    };
}
Also used : FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) Query(org.apache.lucene.search.Query) BoostedQuery(org.apache.lucene.queries.function.BoostedQuery) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) ValueSource(org.apache.lucene.queries.function.ValueSource) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) NamedList(org.apache.solr.common.util.NamedList) BoostedQuery(org.apache.lucene.queries.function.BoostedQuery) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource)

Example 2 with ValueSource

use of org.apache.lucene.queries.function.ValueSource in project lucene-solr by apache.

the class MultiBoolFunction method getValues.

@Override
public BoolDocValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues[] vals = new FunctionValues[sources.size()];
    int i = 0;
    for (ValueSource source : sources) {
        vals[i++] = source.getValues(context, readerContext);
    }
    return new BoolDocValues(this) {

        @Override
        public boolean boolVal(int doc) throws IOException {
            return func(doc, vals);
        }

        @Override
        public String toString(int doc) throws IOException {
            StringBuilder sb = new StringBuilder(name());
            sb.append('(');
            boolean first = true;
            for (FunctionValues dv : vals) {
                if (first) {
                    first = false;
                } else {
                    sb.append(',');
                }
                sb.append(dv.toString(doc));
            }
            return sb.toString();
        }
    };
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) BoolDocValues(org.apache.lucene.queries.function.docvalues.BoolDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 3 with ValueSource

use of org.apache.lucene.queries.function.ValueSource in project lucene-solr by apache.

the class MultiFloatFunction method description.

@Override
public String description() {
    StringBuilder sb = new StringBuilder();
    sb.append(name()).append('(');
    boolean firstTime = true;
    for (ValueSource source : sources) {
        if (firstTime) {
            firstTime = false;
        } else {
            sb.append(',');
        }
        sb.append(source);
    }
    sb.append(')');
    return sb.toString();
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource)

Example 4 with ValueSource

use of org.apache.lucene.queries.function.ValueSource in project lucene-solr by apache.

the class MultiFunction method valsArr.

public static FunctionValues[] valsArr(List<ValueSource> sources, Map fcontext, LeafReaderContext readerContext) throws IOException {
    final FunctionValues[] valsArr = new FunctionValues[sources.size()];
    int i = 0;
    for (ValueSource source : sources) {
        valsArr[i++] = source.getValues(fcontext, readerContext);
    }
    return valsArr;
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 5 with ValueSource

use of org.apache.lucene.queries.function.ValueSource in project lucene-solr by apache.

the class MultiFunction method description.

public static String description(String name, List<ValueSource> sources) {
    StringBuilder sb = new StringBuilder();
    sb.append(name).append('(');
    boolean firstTime = true;
    for (ValueSource source : sources) {
        if (firstTime) {
            firstTime = false;
        } else {
            sb.append(',');
        }
        sb.append(source);
    }
    sb.append(')');
    return sb.toString();
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource)

Aggregations

ValueSource (org.apache.lucene.queries.function.ValueSource)54 Query (org.apache.lucene.search.Query)13 FunctionQuery (org.apache.lucene.queries.function.FunctionQuery)12 SolrException (org.apache.solr.common.SolrException)11 SchemaField (org.apache.solr.schema.SchemaField)11 FunctionValues (org.apache.lucene.queries.function.FunctionValues)10 ArrayList (java.util.ArrayList)8 QueryValueSource (org.apache.lucene.queries.function.valuesource.QueryValueSource)7 FieldType (org.apache.solr.schema.FieldType)6 BooleanQuery (org.apache.lucene.search.BooleanQuery)5 AggValueSource (org.apache.solr.search.facet.AggValueSource)5 IOException (java.io.IOException)4 Map (java.util.Map)4 DoubleConstValueSource (org.apache.lucene.queries.function.valuesource.DoubleConstValueSource)4 VectorValueSource (org.apache.lucene.queries.function.valuesource.VectorValueSource)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 IndexReader (org.apache.lucene.index.IndexReader)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 BoostedQuery (org.apache.lucene.queries.function.BoostedQuery)3 TermGroupSelector (org.apache.lucene.search.grouping.TermGroupSelector)3