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

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

Introduction

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

Prototype

public TermFreqValueSource(String field, String val, String indexedField, BytesRef indexedBytes) 

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.  jav  a2 s.  com
    }
    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()]));
}