當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。