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


Java BooleanQuery.setMinimumNumberShouldMatch方法代码示例

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


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

示例1: addSearchText

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * Adds a filter for the given search text to the given {@link BooleanQuery}.
 * If the search text is blank, than the query will not modified.
 * For each part of the search text {@link #buildSearchTermQuery(IIndexTypeConf, String, float)}
 * will be called.
 *
 * @param query the {@link BooleanQuery} to add the sub queries.
 * @param searchText the search text. May be blank (null or contain only white spaces).
 * @param indexType the type in which should be searched.
 * @param baseBoost highest possible boost of the query. The more the match is exact
 * 			than a bigger boost will be used.
 */
public static void addSearchText(final BooleanQuery query,
		final String searchText, final IIndexTypeConf indexType, final float baseBoost) {

	if(StringUtils.isBlank(searchText)) {
		return;
	}

	query.setMinimumNumberShouldMatch(1); // at least one "should" should match
	query.add(buildSearchTermQuery(indexType, searchText, baseBoost), Occur.SHOULD);

	final BooleanQuery partsQuery = new BooleanQuery();
	query.add(partsQuery, Occur.SHOULD);

	final String[] searchTexts = searchText.toLowerCase().split("\\s");
	for (final String search : searchTexts) {
		partsQuery.add(buildSearchTermQuery(indexType, search, baseBoost), Occur.MUST); // each part has to match
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:31,代码来源:QueryUtil.java

示例2: createMinShouldMatchQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/** 
 * Creates a minimum-should-match query from the query text.
 * <p>
 * @param field field name
 * @param queryText text to be passed to the analyzer
 * @param fraction of query terms {@code [0..1]} that should match 
 * @return {@code TermQuery} or {@code BooleanQuery}, based on the analysis 
 *         of {@code queryText}
 */
public Query createMinShouldMatchQuery(String field, String queryText, float fraction) {
  if (Float.isNaN(fraction) || fraction < 0 || fraction > 1) {
    throw new IllegalArgumentException("fraction should be >= 0 and <= 1");
  }
  
  // TODO: wierd that BQ equals/rewrite/scorer doesn't handle this?
  if (fraction == 1) {
    return createBooleanQuery(field, queryText, BooleanClause.Occur.MUST);
  }
  
  Query query = createFieldQuery(analyzer, BooleanClause.Occur.SHOULD, field, queryText, false, 0);
  if (query instanceof BooleanQuery) {
    BooleanQuery bq = (BooleanQuery) query;
    bq.setMinimumNumberShouldMatch((int) (fraction * bq.clauses().size()));
  }
  return query;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:QueryBuilder.java

示例3: getQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  BooleanQuery bq = new BooleanQuery(DOMUtils.getAttribute(e, "disableCoord", false));
  bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0));
  bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));

  NodeList nl = e.getChildNodes();
  for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node.getNodeName().equals("Clause")) {
      Element clauseElem = (Element) node;
      BooleanClause.Occur occurs = getOccursValue(clauseElem);

      Element clauseQuery = DOMUtils.getFirstChildOrFail(clauseElem);
      Query q = factory.getQuery(clauseQuery);
      bq.add(new BooleanClause(q, occurs));
    }
  }

  return bq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:BooleanQueryBuilder.java

示例4: build

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
  AnyQueryNode andNode = (AnyQueryNode) queryNode;

  BooleanQuery bQuery = new BooleanQuery();
  List<QueryNode> children = andNode.getChildren();

  if (children != null) {

    for (QueryNode child : children) {
      Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

      if (obj != null) {
        Query query = (Query) obj;

        try {
          bQuery.add(query, BooleanClause.Occur.SHOULD);
        } catch (TooManyClauses ex) {

          throw new QueryNodeException(new MessageImpl(
          /*
           * IQQQ.Q0028E_TOO_MANY_BOOLEAN_CLAUSES,
           * BooleanQuery.getMaxClauseCount()
           */QueryParserMessages.EMPTY_MESSAGE), ex);

        }

      }

    }

  }

  bQuery.setMinimumNumberShouldMatch(andNode.getMinimumMatchingElements());

  return bQuery;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:AnyQueryNodeBuilder.java


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