Java Code Examples for org.apache.solr.util.SolrPluginUtils#DisjunctionMaxQueryParser

The following examples show how to use org.apache.solr.util.SolrPluginUtils#DisjunctionMaxQueryParser . 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: DisMaxQParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected Query getUserQuery(String userQuery, SolrPluginUtils.DisjunctionMaxQueryParser up, SolrParams solrParams)
        throws SyntaxError {


  String minShouldMatch = parseMinShouldMatch(req.getSchema(), solrParams);
  Query dis = up.parse(userQuery);
  Query query = dis;

  if (dis instanceof BooleanQuery) {
    BooleanQuery.Builder t = new BooleanQuery.Builder();
    SolrPluginUtils.flattenBooleanQuery(t, (BooleanQuery) dis);
    boolean mmAutoRelax = params.getBool(DisMaxParams.MM_AUTORELAX, false);
    SolrPluginUtils.setMinShouldMatch(t, minShouldMatch, mmAutoRelax);
    query = QueryUtils.build(t, this);
  }
  return query;
}
 
Example 2
Source File: DisMaxQParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Adds the main query to the query argument. If it's blank then false is returned. */
protected boolean addMainQuery(BooleanQuery.Builder query, SolrParams solrParams) throws SyntaxError {
  Map<String, Float> phraseFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.PF));
  float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f);

  /* a parser for dealing with user input, which will convert
   * things to DisjunctionMaxQueries
   */
  SolrPluginUtils.DisjunctionMaxQueryParser up = getParser(queryFields, DisMaxParams.QS, solrParams, tiebreaker);

  /* for parsing sloppy phrases using DisjunctionMaxQueries */
  SolrPluginUtils.DisjunctionMaxQueryParser pp = getParser(phraseFields, DisMaxParams.PS, solrParams, tiebreaker);

  /* * * Main User Query * * */
  parsedUserQuery = null;
  String userQuery = getString();
  altUserQuery = null;
  if (StringUtils.isBlank(userQuery)) {
    // If no query is specified, we may have an alternate
    altUserQuery = getAlternateUserQuery(solrParams);
    if (altUserQuery == null)
      return false;
    query.add(altUserQuery, BooleanClause.Occur.MUST);
  } else {
    // There is a valid query string
    userQuery = SolrPluginUtils.partialEscape(SolrPluginUtils.stripUnbalancedQuotes(userQuery)).toString();
    userQuery = SolrPluginUtils.stripIllegalOperators(userQuery).toString();

    parsedUserQuery = getUserQuery(userQuery, up, solrParams);
    query.add(parsedUserQuery, BooleanClause.Occur.MUST);

    Query phrase = getPhraseQuery(userQuery, pp);
    if (null != phrase) {
      query.add(phrase, BooleanClause.Occur.SHOULD);
    }
  }
  return true;
}
 
Example 3
Source File: DisMaxQParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected Query getPhraseQuery(String userQuery, SolrPluginUtils.DisjunctionMaxQueryParser pp) throws SyntaxError {
  /* * * Add on Phrases for the Query * * */

  /* build up phrase boosting queries */

  /* if the userQuery already has some quotes, strip them out.
   * we've already done the phrases they asked for in the main
   * part of the query, this is to boost docs that may not have
   * matched those phrases but do match looser phrases.
  */
  String userPhraseQuery = userQuery.replace("\"", "");
  return pp.parse("\"" + userPhraseQuery + "\"");
}
 
Example 4
Source File: DisMaxQParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected SolrPluginUtils.DisjunctionMaxQueryParser getParser(Map<String, Float> fields, String paramName,
                                                              SolrParams solrParams, float tiebreaker) {
  int slop = solrParams.getInt(paramName, 0);
  SolrPluginUtils.DisjunctionMaxQueryParser parser = new SolrPluginUtils.DisjunctionMaxQueryParser(this,
          IMPOSSIBLE_FIELD_NAME);
  parser.addAlias(IMPOSSIBLE_FIELD_NAME, tiebreaker, fields);
  parser.setPhraseSlop(slop);
  parser.setSplitOnWhitespace(true);
  return parser;
}