Example usage for org.apache.lucene.queries.function.valuesource SumFloatFunction SumFloatFunction

List of usage examples for org.apache.lucene.queries.function.valuesource SumFloatFunction SumFloatFunction

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function.valuesource SumFloatFunction SumFloatFunction.

Prototype

public SumFloatFunction(ValueSource[] sources) 

Source Link

Usage

From source file:com.ifactory.press.db.solr.HitCount.java

License:Apache License

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    // hitcount() takes no arguments.  If we wanted to pass a query
    // we could call fp.parseNestedQuery()
    HashSet<String> fields = new HashSet<String>();
    while (fp.hasMoreArguments()) {
        fields.add(fp.parseArg());/*from  w  w w .j av a  2 s  . co m*/
    }
    Query q = fp.subQuery(fp.getParams().get("q"), "lucene").getQuery();
    HashSet<Term> terms = new HashSet<Term>();
    try {
        q.extractTerms(terms);
    } catch (UnsupportedOperationException e) {
        return new DoubleConstValueSource(1);
    }
    ArrayList<ValueSource> termcounts = new ArrayList<ValueSource>();
    for (Term t : terms) {
        if (fields.isEmpty() || fields.contains(t.field())) {
            termcounts.add(new TermFreqValueSource(t.field(), t.text(), t.field(), t.bytes()));
        }
    }
    return new SumFloatFunction(termcounts.toArray(new ValueSource[termcounts.size()]));
}