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


Java BooleanQuery.add方法代码示例

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


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

示例1: parse

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * @deprecated Use {@link #parse(String, String[], BooleanClause.Occur[], Analyzer)}
 */
@Deprecated
public static Query parse(Version matchVersion, String query, String[] fields,
      BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
  if (fields.length != flags.length)
    throw new IllegalArgumentException("fields.length != flags.length");
  BooleanQuery bQuery = new BooleanQuery();
  for (int i = 0; i < fields.length; i++) {
    QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
    Query q = qp.parse(query);
    if (q!=null && // q never null, just being defensive 
        (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
      bQuery.add(q, flags[i]);
    }
  }
  return bQuery;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:MultiFieldQueryParser.java

示例2: applyConstraints

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
protected void applyConstraints(BooleanQuery query) {
	if (fileNames != null) {
		BooleanQuery subQuery = new BooleanQuery(true);
		for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
			subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
		if (subQuery.getClauses().length != 0)
			query.add(subQuery, Occur.MUST);
	}

	if (regex) 
		query.add(new RegexLiterals(term).asNGramQuery(BLOB_TEXT.name(), NGRAM_SIZE), Occur.MUST);
	else if (term.length() >= NGRAM_SIZE)
		query.add(new NGramLuceneQuery(BLOB_TEXT.name(), term, NGRAM_SIZE), Occur.MUST);
	else 
		throw new TooGeneralQueryException();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:18,代码来源:TextQuery.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: addSearchTermQueries

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * Adds for every field in {@link IIndexTypeConf} a {@link TermQuery}, {@link PrefixQuery} and
 * a {@link FuzzyQuery} with a suitable boost relative to the given base boost.
 *
 * @param indexType the type in which should be searched.
 * @param search the search text.
 * @param subQuery the {@link BooleanQuery} to add the sub queries.
 * @param baseBoost highest possible boost of the query. The more the match is exact
 * 			than a bigger boost will be used.
 */
private static void addSearchTermQueries(final IIndexTypeConf indexType, final String search,
		final BooleanQuery subQuery, final float baseBoost) {

	for(final IIndexFieldConf<?> field : indexType.getFields()) {
		final Term term = new Term(field.getName(), search);

		final TermQuery exactQuery = new TermQuery(term);
		exactQuery.setBoost(baseBoost);
		subQuery.add(exactQuery, Occur.SHOULD);

		final PrefixQuery pfQuery = new PrefixQuery(term);
		pfQuery.setBoost(0.7f*baseBoost);
		subQuery.add(pfQuery, Occur.SHOULD);

		final FuzzyQuery fuzzyQuery = new FuzzyQuery(term);
		fuzzyQuery.setBoost(0.5f*baseBoost);
		subQuery.add(fuzzyQuery, Occur.SHOULD);
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:30,代码来源:QueryUtil.java

示例5: prefixSearch

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String keywords) throws IOException {
    if (StringUtils.isEmpty(keywords) || keywords.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", keywords);
        return null;
    }
    Sort sort = new Sort(new SortField("downloadRank", SortField.INT, true));

    Term nameFldTerm = new Term(fieldName, keywords);
    PrefixQuery nameFldQuery = new PrefixQuery(nameFldTerm);

    NumericRangeQuery<Integer> catalogQuery = NumericRangeQuery.newIntRange("catalog",
            (int) EnumCatalog.SOFT.getCatalog(), (int) EnumCatalog.GAME.getCatalog(), true, true);
    BooleanQuery booleanQuery = new BooleanQuery();
    booleanQuery.add(catalogQuery, Occur.MUST);
    booleanQuery.add(nameFldQuery, Occur.MUST);

    TopDocs topDocs = quickTipsSearcher.search(booleanQuery, appConfig.getQuickTipsNum() * 2, sort);
    ScoreDoc[] docs = topDocs.scoreDocs;
    return docs;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:22,代码来源:QuickTipsServiceImpl.java

示例6: getLuceneQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * Returns the Lucene query for the given locale and query text.
 * 
 * @param searchString
 *            the text query for the Lucene query parser
 * @param mId
 *            the marketplace id
 * @param locale
 *            the locale for the analyzer to use
 * @param isDefaultLocaleHandling
 * @return the Lucene query for the given locale and query text
 * @throws ParseException
 *             in case the query cannot be parsed
 */
private org.apache.lucene.search.Query getLuceneQuery(String searchString,
        String mId, String locale, boolean isDefaultLocaleHandling)
        throws SyntaxError, QueryNodeException {

    // construct wildcard query for the actual search part
    org.apache.lucene.search.Query textQuery = LuceneQueryBuilder
            .getServiceQuery(searchString, locale, DEFAULT_LOCALE,
                    isDefaultLocaleHandling);

    // build mId part
    TermQuery mIdQuery = new TermQuery(new Term(ProductClassBridge.MP_ID,
            QueryParser.escape(mId).toLowerCase()));

    // now construct final query
    BooleanQuery query = new BooleanQuery();
    query.add(mIdQuery, Occur.MUST);
    query.add(textQuery, Occur.MUST);
    return query;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:SearchServiceBean.java

示例7: constructWildcardQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private static BooleanQuery constructWildcardQuery(String searchPhrase,
        List<String> fieldNames, String locale, String defaultLocale,
        boolean isDefaultLocaleHandling) {

    String[] splitStr = searchPhrase.split("\\s+");

    BooleanQuery booleanQuery = new BooleanQuery();

    for (String token : splitStr) {
        booleanQuery.add(
                prepareWildcardQueryForSingleToken(token, fieldNames,
                        locale, defaultLocale, isDefaultLocaleHandling),
                Occur.MUST);
    }

    return booleanQuery;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:LuceneQueryBuilder.java

示例8: addUniqueIdClauseToQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private Query addUniqueIdClauseToQuery(Query query, SearchResults<T> itemResults, IndexReader reader)
{
	List<T> results = itemResults.getResults();
	BooleanQuery orQuery = new BooleanQuery();

	for( T t : results )
	{
		ItemIdKey itemIdKey = t.getItemIdKey();
		String[] split = itemIdKey.toString().split("/");
		String uniqueId = split[1] + "/" + split[2];

		FreeTextBooleanQuery bquery = new FreeTextBooleanQuery(false, true);
		bquery.add(new FreeTextFieldQuery(FreeTextQuery.FIELD_UNIQUE, uniqueId));
		BooleanClause convertBoolean = convertToBooleanClause(bquery, reader);
		convertBoolean.setOccur(Occur.SHOULD);
		orQuery.add(convertBoolean);
	}

	BooleanQuery newQuery = new BooleanQuery();
	newQuery.add(query, Occur.MUST);
	newQuery.add(orQuery, Occur.MUST);

	return newQuery;
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:ItemIndex.java

示例9: constructDefaultLocaleHandlingQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private static BooleanQuery constructDefaultLocaleHandlingQuery(
        String fieldName, String locale, String defaultLocale,
        String searchPhrase) {
    BooleanQuery bq1 = new BooleanQuery();
    TermQuery tq1 = new TermQuery(
            new Term(fieldName + ProductClassBridge.DEFINED_LOCALES_SUFFIX,
                    defaultLocale));
    TermQuery tq2 = new TermQuery(new Term(
            fieldName + ProductClassBridge.DEFINED_LOCALES_SUFFIX, locale));
    bq1.add(tq1, Occur.MUST);
    bq1.add(tq2, Occur.MUST_NOT);
    BooleanQuery bq2 = new BooleanQuery();
    WildcardQuery wq1 = new WildcardQuery(
            new Term(fieldName + defaultLocale,
                    "*" + searchPhrase.toLowerCase() + "*"));
    bq2.add(wq1, Occur.SHOULD);
    BooleanQuery finalQuery = new BooleanQuery();
    finalQuery.add(bq1, Occur.MUST);
    finalQuery.add(bq2, Occur.MUST);

    return finalQuery;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:LuceneQueryBuilder.java

示例10: applyConstraints

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
protected void applyConstraints(BooleanQuery query) {
	if (fileNames != null) {
		BooleanQuery subQuery = new BooleanQuery(true);
		for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
			subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
		if (subQuery.getClauses().length != 0)
			query.add(subQuery, Occur.MUST);
	}

	boolean tooGeneral = true;
	for (char ch: term.toCharArray()) {
		if (ch != '?' && ch != '*') {
			tooGeneral = false;
			break;
		}
	}
	if (tooGeneral)
		throw new TooGeneralQueryException();

	if (primary != null) {
		String fieldName;
		if (primary)
			fieldName = BLOB_PRIMARY_SYMBOLS.name();
		else
			fieldName = BLOB_SECONDARY_SYMBOLS.name();
		
		query.add(new WildcardQuery(new Term(fieldName, term.toLowerCase())), Occur.MUST);
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:31,代码来源:SymbolQuery.java

示例11: createClassWithEnclosedQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private static Query createClassWithEnclosedQuery (final String resourceName, final String sourceName) {
    final BooleanQuery query = createFQNQuery(resourceName);
    if (sourceName != null) {
        query.add (new TermQuery(new Term (DocumentUtil.FIELD_SOURCE,sourceName)), Occur.MUST);
    }
    return query;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DocumentUtil.java

示例12: newPhraseQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * Factory method to generate a phrase query with slop.
 */
protected Query newPhraseQuery(String text, int slop) {
  BooleanQuery bq = new BooleanQuery(true);
  for (Map.Entry<String,Float> entry : weights.entrySet()) {
    Query q = createPhraseQuery(entry.getKey(), text, slop);
    if (q != null) {
      q.setBoost(entry.getValue());
      bq.add(q, BooleanClause.Occur.SHOULD);
    }
  }
  return simplify(bq);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:SimpleQueryParser.java

示例13: delete

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * Deletes the given {@link IIndexElement} from the index.
 * @param element the {@link IIndexElement} to remove.
 * @throws IOException if an error occurred in the index.
 */
private void delete(final IIndexElement element) throws IOException {
	final IIndexTypeConf conf = indexData.getConf();

	// build query for deletion
	final BooleanQuery query = new BooleanQuery();
	query.add(new TermQuery(new Term(IIndexElement.FIELD_ID, element.getId())), Occur.MUST);
	query.add(new TermQuery(new Term(IIndexElement.FIELD_INDEX_TYPE, conf.getName())), Occur.MUST);

	index.deleteDocuments(query);
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:16,代码来源:IndexingThread.java

示例14: fiterSafeToQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private void fiterSafeToQuery(BooleanQuery query, Boolean bNoAds, Boolean bOfficial) {
    NumericRangeQuery<Integer> catalogNumQuery = NumericRangeQuery.newIntRange("catalog",
            (int) EnumCatalog.SOFT.getCatalog(), (int) EnumCatalog.GAME.getCatalog(), true, true);
    ;
    query.add(catalogNumQuery, Occur.MUST);

    if (bNoAds != null && bNoAds.booleanValue()) {
        NumericRangeQuery<Integer> noAdsQuery = NumericRangeQuery.newIntRange("noAds", 1, 1, true, true);
        query.add(noAdsQuery, Occur.MUST);
    }
    if (bOfficial != null && bOfficial.booleanValue()) {
        NumericRangeQuery<Integer> officialQuery = NumericRangeQuery.newIntRange("official", 1, 1, true, true);
        query.add(officialQuery, Occur.MUST);
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:16,代码来源:SearchService1Impl.java

示例15: makeLuceneQueryFieldNoBoost

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public Query makeLuceneQueryFieldNoBoost(String fieldName, BasicQueryFactory qf) {
  List<Query> luceneSubQueries = makeLuceneSubQueriesField(fieldName, qf);
  BooleanQuery bq = new BooleanQuery();
  bq.add( luceneSubQueries.get(0), BooleanClause.Occur.MUST);
  SrndBooleanQuery.addQueriesToBoolean(bq,
          // FIXME: do not allow weights on prohibited subqueries.
          luceneSubQueries.subList(1, luceneSubQueries.size()),
          // later subqueries: not required, prohibited
          BooleanClause.Occur.MUST_NOT);
  return bq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:NotQuery.java


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