Java Code Examples for org.apache.lucene.queries.function.FunctionScoreQuery#boostByValue()

The following examples show how to use org.apache.lucene.queries.function.FunctionScoreQuery#boostByValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoostQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@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 FunctionScoreQuery.boostByValue(q, vs.asDoubleValuesSource());
    }


    @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);
    }
  };
}
 
Example 2
Source File: ValueSourceParser.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  Query q = fp.parseNestedQuery();
  ValueSource vs = fp.parseValueSource();
  return new QueryValueSource(FunctionScoreQuery.boostByValue(q, vs.asDoubleValuesSource()), 0.0f);
}
 
Example 3
Source File: SearchQueryFactoryImpl.java    From yes-cart with Apache License 2.0 3 votes vote down vote up
private Query productBoost(final Query query) {

        if (query == null) {
            return null;
        }

        return FunctionScoreQuery.boostByValue(query, PRODUCT_BOOST_FIELDS);

    }
 
Example 4
Source File: SearchQueryFactoryImpl.java    From yes-cart with Apache License 2.0 3 votes vote down vote up
private Query skuBoost(final Query query) {

        if (query == null) {
            return null;
        }

        return FunctionScoreQuery.boostByValue(query, SKU_BOOST_FIELDS);

    }