当前位置: 首页>>代码示例>>Java>>正文


Java SolrPluginUtils.setMinShouldMatch方法代码示例

本文整理汇总了Java中org.apache.solr.util.SolrPluginUtils.setMinShouldMatch方法的典型用法代码示例。如果您正苦于以下问题:Java SolrPluginUtils.setMinShouldMatch方法的具体用法?Java SolrPluginUtils.setMinShouldMatch怎么用?Java SolrPluginUtils.setMinShouldMatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.util.SolrPluginUtils的用法示例。


在下文中一共展示了SolrPluginUtils.setMinShouldMatch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUserQuery

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
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 t = new BooleanQuery();
    SolrPluginUtils.flattenBooleanQuery(t, (BooleanQuery) dis);
    SolrPluginUtils.setMinShouldMatch(t, minShouldMatch);
    query = t;
  }
  return query;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:DisMaxQParser.java

示例2: applyMinShouldMatch

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
 * @param query
 */
public Query applyMinShouldMatch(final Query query) {

    if (!(query instanceof BooleanQuery)) {
        return query;
    }

    final BooleanQuery bq = (BooleanQuery) query;
    List<BooleanClause> clauses = bq.clauses();
    if (clauses.size() < 2) {
        return bq;
    }

    for (BooleanClause clause : clauses) {
        if ((clause.getQuery() instanceof BooleanQuery) && (clause.getOccur() != Occur.MUST)) {
            return bq; // seems to be a complex query with sub queries - do not
            // apply mm
        }
    }

    return SolrPluginUtils.setMinShouldMatch(bq, config.getMinShouldMatch());

}
 
开发者ID:renekrie,项目名称:querqy,代码行数:26,代码来源:QuerqyDismaxQParser.java

示例3: getOrQuery

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public Query getOrQuery(){
    BooleanQuery.Builder qryBuilder = new BooleanQuery.Builder();
    for(RFTerm RFTerm : this.RFTerms){
        qryBuilder.add(toBoostedQuery(RFTerm), BooleanClause.Occur.SHOULD);
    }
    SolrPluginUtils.setMinShouldMatch(qryBuilder, mm);
    return qryBuilder.build();
}
 
开发者ID:DiceTechJobs,项目名称:RelevancyFeedback,代码行数:9,代码来源:RFQuery.java

示例4: parseEscapedQuery

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
 * Parses an escaped version of the user's query.  This method is called 
 * in the event that the original query encounters exceptions during parsing.
 *
 * @param up parser used
 * @param escapedUserQuery query that is parsed, should already be escaped so that no trivial parse errors are encountered
 * @param config Configuration options for this parse request
 * @return the resulting query (flattened if needed) with "min should match" rules applied as specified in the config.
 * @see #parseOriginalQuery
 * @see SolrPluginUtils#flattenBooleanQuery
 */
protected Query parseEscapedQuery(ExtendedSolrQueryParser up,
    String escapedUserQuery, ExtendedDismaxConfiguration config) throws SyntaxError {
  Query query = up.parse(escapedUserQuery);
  
  if (query instanceof BooleanQuery) {
    BooleanQuery t = new BooleanQuery();
    SolrPluginUtils.flattenBooleanQuery(t, (BooleanQuery)query);
    SolrPluginUtils.setMinShouldMatch(t, config.minShouldMatch);
    query = t;
  }
  return query;
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:ExtendedDismaxQParser.java

示例5: parseOriginalQuery

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
/**
 * Parses the user's original query.  This method attempts to cleanly parse the specified query string using the specified parser, any Exceptions are ignored resulting in null being returned.
 *
 * @param up parser used
 * @param mainUserQuery query string that is parsed
 * @param clauses used to dictate "min should match" logic
 * @param config Configuration options for this parse request
 * @return the resulting query with "min should match" rules applied as specified in the config.
 * @see #parseEscapedQuery
 */
 protected Query parseOriginalQuery(ExtendedSolrQueryParser up,
    String mainUserQuery, List<Clause> clauses, ExtendedDismaxConfiguration config) {
  
  Query query = null;
  try {
    up.setRemoveStopFilter(!config.stopwords);
    up.exceptions = true;
    query = up.parse(mainUserQuery);
    
    if (shouldRemoveStopFilter(config, query)) {
      // if the query was all stop words, remove none of them
      up.setRemoveStopFilter(true);
      query = up.parse(mainUserQuery);          
    }
  } catch (Exception e) {
    // ignore failure and reparse later after escaping reserved chars
    up.exceptions = false;
  }
  
  if(query == null) {
    return null;
  }
  // For correct lucene queries, turn off mm processing if there
  // were explicit operators (except for AND).
  boolean doMinMatched = doMinMatched(clauses, config.lowercaseOperators);
  if (doMinMatched && query instanceof BooleanQuery) {
    SolrPluginUtils.setMinShouldMatch((BooleanQuery)query, config.minShouldMatch);
  }
  return query;
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:ExtendedDismaxQParser.java

示例6: getOrQuery

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
public Query getOrQuery(){
    BooleanQuery.Builder qryBuilder = new BooleanQuery.Builder();
    for(MLTTerm mltTerm: this.mltTerms){
        qryBuilder.add(toBoostedQuery(mltTerm), BooleanClause.Occur.SHOULD);
    }
    SolrPluginUtils.setMinShouldMatch(qryBuilder, mm);
    return qryBuilder.build();
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:9,代码来源:MLTQuery.java

示例7: testMinShouldMatchCalculator

import org.apache.solr.util.SolrPluginUtils; //导入方法依赖的package包/类
@Test                                    
public void testMinShouldMatchCalculator() {

  /* zero is zero is zero */
  assertEquals(0, calcMSM(5, "0"));
  assertEquals(0, calcMSM(5, "0%"));
  assertEquals(0, calcMSM(5, " -5 "));
  assertEquals(0, calcMSM(5, "\n -100% \n"));

  /* basic integers */
  assertEquals(3, calcMSM(5, " \n3\n "));
  assertEquals(2, calcMSM(5, "-3"));
  assertEquals(3, calcMSM(3, "3"));
  assertEquals(0, calcMSM(3, "-3"));
  assertEquals(3, calcMSM(3, "5"));
  assertEquals(0, calcMSM(3, "-5"));

  /* positive percentages with rounding */
  assertEquals(0, calcMSM(3, " \n25% \n"));
  assertEquals(1, calcMSM(4, "25%"));
  assertEquals(1, calcMSM(5, " 25% "));
  assertEquals(2, calcMSM(10, "25%"));
      
  /* negative percentages with rounding */
  assertEquals(3, calcMSM(3, " \n-25%\n "));
  assertEquals(3, calcMSM(4, "-25%"));
  assertEquals(4, calcMSM(5, "-25%"));
  assertEquals(8, calcMSM(10, "-25%"));

  /* conditional */
  assertEquals(1, calcMSM(1, "3<0"));
  assertEquals(2, calcMSM(2, "3<0"));
  assertEquals(3, calcMSM(3, "3<0"));
  assertEquals(0, calcMSM(4, "3<0"));
  assertEquals(0, calcMSM(5, "3<0"));
  assertEquals(1, calcMSM(1, "3<25%"));
  assertEquals(2, calcMSM(2, " 3\n<\n25% "));
  assertEquals(3, calcMSM(3, "3<25%"));
  assertEquals(1, calcMSM(4, "\n 3 < \n25%\n "));
  assertEquals(1, calcMSM(5, "3<25%"));

  /* multiple conditionals */
  assertEquals(1, calcMSM(1, "\n3 < -25% 10 < -3 \n"));
  assertEquals(2, calcMSM(2, " 3 < -25% 10 < -3\n"));
  assertEquals(3, calcMSM(3, " 3 < -25% \n 10 < -3 \n"));
  assertEquals(3, calcMSM(4, " 3 < -25% 10 < -3 "));
  assertEquals(4, calcMSM(5, " 3 < -25% 10 < -3"));
  assertEquals(5, calcMSM(6, "3<-25% 10<-3"));
  assertEquals(6, calcMSM(7, " 3 < -25% 10 < -3 "));
  assertEquals(6, calcMSM(8, " 3 < -25% 10 \n < -3\n"));
  assertEquals(7, calcMSM(9, " 3 < -25% 10 < -3 \n"));
  assertEquals(8, calcMSM(10, " 3 < -25% 10 < -3"));
  assertEquals(8, calcMSM(11, "3<-25% 10<-3"));
  assertEquals(9, calcMSM(12, "3<-25% 10<-3"));
  assertEquals(97, calcMSM(100, "3<-25% 10<-3"));

  BooleanQuery q = new BooleanQuery();
  q.add(new TermQuery(new Term("a","b")), Occur.SHOULD);
  q.add(new TermQuery(new Term("a","c")), Occur.SHOULD);
  q.add(new TermQuery(new Term("a","d")), Occur.SHOULD);
  q.add(new TermQuery(new Term("a","d")), Occur.SHOULD);

  SolrPluginUtils.setMinShouldMatch(q, "0");
  assertEquals(0, q.getMinimumNumberShouldMatch());
      
  SolrPluginUtils.setMinShouldMatch(q, "1");
  assertEquals(1, q.getMinimumNumberShouldMatch());
      
  SolrPluginUtils.setMinShouldMatch(q, "50%");
  assertEquals(2, q.getMinimumNumberShouldMatch());

  SolrPluginUtils.setMinShouldMatch(q, "99");
  assertEquals(4, q.getMinimumNumberShouldMatch());

  q.add(new TermQuery(new Term("a","e")), Occur.MUST);
  q.add(new TermQuery(new Term("a","f")), Occur.MUST);

  SolrPluginUtils.setMinShouldMatch(q, "50%");
  assertEquals(2, q.getMinimumNumberShouldMatch());
      
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:82,代码来源:SolrPluginUtilsTest.java


注:本文中的org.apache.solr.util.SolrPluginUtils.setMinShouldMatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。