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

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

Introduction

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

Prototype

public ProductFloatFunction(ValueSource[] sources) 

Source Link

Usage

From source file:org.apache.solr.search.AqpExtendedDismaxQParserPlugin.java

License:Apache License

@Override
public Query parse() throws SyntaxError {
    parsed = true;/*from w ww.ja va 2s .co  m*/

    /* the main query we will execute.  we disable the coord because
     * this query is an artificial construct
     */
    BooleanQuery query = new BooleanQuery(true);

    /* * * 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
        AqpExtendedSolrQueryParser up = createEdismaxQueryParser(this, IMPOSSIBLE_FIELD_NAME);
        up.addAlias(IMPOSSIBLE_FIELD_NAME, config.tiebreaker, config.queryFields);
        addAliasesFromRequest(up, config.tiebreaker);
        up.setPhraseSlop(config.qslop); // slop for explicit user phrase queries
        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;

        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;
    List<ValueSource> boosts = getMultiplicativeBoosts();
    if (boosts.size() > 1) {
        ValueSource prod = new ProductFloatFunction(boosts.toArray(new ValueSource[boosts.size()]));
        topQuery = new BoostedQuery(query, prod);
    } else if (boosts.size() == 1) {
        topQuery = new BoostedQuery(query, boosts.get(0));
    }

    return topQuery;
}

From source file:org.apache.solr.search.ExtendedDismaxQParser.java

License:Apache License

@Override
public Query parse() throws SyntaxError {

    /* the main query we will execute.  we disable the coord because
     * this query is an artificial construct
     *///  ww  w . j  a  v a2  s  .  c om
    BooleanQuery query = new BooleanQuery(true);

    /* * * 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);
        up.setPhraseSlop(config.qslop); // slop for explicit user phrase queries
        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;

        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;
    List<ValueSource> boosts = getMultiplicativeBoosts();
    if (boosts.size() > 1) {
        ValueSource prod = new ProductFloatFunction(boosts.toArray(new ValueSource[boosts.size()]));
        topQuery = new BoostedQuery(query, prod);
    } else if (boosts.size() == 1) {
        topQuery = new BoostedQuery(query, boosts.get(0));
    }

    return topQuery;
}