Search in sources :

Example 1 with ProductFloatFunction

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

the class TestValueSources method testProduct.

public void testProduct() throws Exception {
    ValueSource vs = new ProductFloatFunction(new ValueSource[] { new ConstValueSource(2f), new ConstValueSource(3f) });
    assertHits(new FunctionQuery(vs), new float[] { 6f, 6f });
    assertAllExist(vs);
    vs = new ProductFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, new ConstValueSource(3f) });
    assertNoneExist(vs);
}
Also used : ProductFloatFunction(org.apache.lucene.queries.function.valuesource.ProductFloatFunction) SumTotalTermFreqValueSource(org.apache.lucene.queries.function.valuesource.SumTotalTermFreqValueSource) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) DocFreqValueSource(org.apache.lucene.queries.function.valuesource.DocFreqValueSource) NormValueSource(org.apache.lucene.queries.function.valuesource.NormValueSource) NumDocsValueSource(org.apache.lucene.queries.function.valuesource.NumDocsValueSource) MaxDocValueSource(org.apache.lucene.queries.function.valuesource.MaxDocValueSource) JoinDocFreqValueSource(org.apache.lucene.queries.function.valuesource.JoinDocFreqValueSource) LiteralValueSource(org.apache.lucene.queries.function.valuesource.LiteralValueSource) TotalTermFreqValueSource(org.apache.lucene.queries.function.valuesource.TotalTermFreqValueSource) IDFValueSource(org.apache.lucene.queries.function.valuesource.IDFValueSource) TermFreqValueSource(org.apache.lucene.queries.function.valuesource.TermFreqValueSource) TFValueSource(org.apache.lucene.queries.function.valuesource.TFValueSource) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 2 with ProductFloatFunction

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

the class ExtendedDismaxQParser method parse.

@Override
public Query parse() throws SyntaxError {
    parsed = true;
    /* the main query we will execute.  we disable the coord because
     * this query is an artificial construct
     */
    BooleanQuery.Builder query = new BooleanQuery.Builder();
    /* * * Main User Query * * */
    parsedUserQuery = null;
    String userQuery = getString();
    altUserQuery = null;
    if (userQuery == null || userQuery.trim().length() == 0) {
        // If no query is specified, we may have an alternate
        if (config.altQ != null) {
            QParser altQParser = subQuery(config.altQ, null);
            altUserQuery = altQParser.getQuery();
            query.add(altUserQuery, BooleanClause.Occur.MUST);
        } else {
            return null;
        // throw new SyntaxError("missing query string" );
        }
    } else {
        // There is a valid query string
        ExtendedSolrQueryParser up = createEdismaxQueryParser(this, IMPOSSIBLE_FIELD_NAME);
        up.addAlias(IMPOSSIBLE_FIELD_NAME, config.tiebreaker, config.queryFields);
        addAliasesFromRequest(up, config.tiebreaker);
        // slop for explicit user phrase queries
        up.setPhraseSlop(config.qslop);
        up.setAllowLeadingWildcard(true);
        // defer escaping and only do if lucene parsing fails, or we need phrases
        // parsing fails.  Need to sloppy phrase queries anyway though.
        List<Clause> clauses = splitIntoClauses(userQuery, false);
        // Always rebuild mainUserQuery from clauses to catch modifications from splitIntoClauses
        // This was necessary for userFields modifications to get propagated into the query.
        // Convert lower or mixed case operators to uppercase if we saw them.
        // only do this for the lucene query part and not for phrase query boosting
        // since some fields might not be case insensitive.
        // We don't use a regex for this because it might change and AND or OR in
        // a phrase query in a case sensitive field.
        String mainUserQuery = rebuildUserQuery(clauses, config.lowercaseOperators);
        // but always for unstructured implicit bqs created by getFieldQuery
        up.minShouldMatch = config.minShouldMatch;
        up.setSplitOnWhitespace(config.splitOnWhitespace);
        parsedUserQuery = parseOriginalQuery(up, mainUserQuery, clauses, config);
        if (parsedUserQuery == null) {
            parsedUserQuery = parseEscapedQuery(up, escapeUserQuery(clauses), config);
        }
        query.add(parsedUserQuery, BooleanClause.Occur.MUST);
        addPhraseFieldQueries(query, clauses, config);
    }
    /* * * Boosting Query * * */
    boostQueries = getBoostQueries();
    for (Query f : boostQueries) {
        query.add(f, BooleanClause.Occur.SHOULD);
    }
    /* * * Boosting Functions * * */
    List<Query> boostFunctions = getBoostFunctions();
    for (Query f : boostFunctions) {
        query.add(f, BooleanClause.Occur.SHOULD);
    }
    //
    // create a boosted query (scores multiplied by boosts)
    //
    Query topQuery = query.build();
    List<ValueSource> boosts = getMultiplicativeBoosts();
    if (boosts.size() > 1) {
        ValueSource prod = new ProductFloatFunction(boosts.toArray(new ValueSource[boosts.size()]));
        topQuery = new BoostedQuery(topQuery, prod);
    } else if (boosts.size() == 1) {
        topQuery = new BoostedQuery(topQuery, boosts.get(0));
    }
    return topQuery;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostedQuery(org.apache.lucene.queries.function.BoostedQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ProductFloatFunction(org.apache.lucene.queries.function.valuesource.ProductFloatFunction) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) ValueSource(org.apache.lucene.queries.function.ValueSource) BooleanClause(org.apache.lucene.search.BooleanClause) BoostedQuery(org.apache.lucene.queries.function.BoostedQuery)

Aggregations

ProductFloatFunction (org.apache.lucene.queries.function.valuesource.ProductFloatFunction)2 QueryValueSource (org.apache.lucene.queries.function.valuesource.QueryValueSource)2 BoostedQuery (org.apache.lucene.queries.function.BoostedQuery)1 FunctionQuery (org.apache.lucene.queries.function.FunctionQuery)1 ValueSource (org.apache.lucene.queries.function.ValueSource)1 ConstValueSource (org.apache.lucene.queries.function.valuesource.ConstValueSource)1 DocFreqValueSource (org.apache.lucene.queries.function.valuesource.DocFreqValueSource)1 DoubleConstValueSource (org.apache.lucene.queries.function.valuesource.DoubleConstValueSource)1 IDFValueSource (org.apache.lucene.queries.function.valuesource.IDFValueSource)1 JoinDocFreqValueSource (org.apache.lucene.queries.function.valuesource.JoinDocFreqValueSource)1 LiteralValueSource (org.apache.lucene.queries.function.valuesource.LiteralValueSource)1 MaxDocValueSource (org.apache.lucene.queries.function.valuesource.MaxDocValueSource)1 NormValueSource (org.apache.lucene.queries.function.valuesource.NormValueSource)1 NumDocsValueSource (org.apache.lucene.queries.function.valuesource.NumDocsValueSource)1 SumTotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.SumTotalTermFreqValueSource)1 TFValueSource (org.apache.lucene.queries.function.valuesource.TFValueSource)1 TermFreqValueSource (org.apache.lucene.queries.function.valuesource.TermFreqValueSource)1 TotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.TotalTermFreqValueSource)1 BooleanClause (org.apache.lucene.search.BooleanClause)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1