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


Java BooleanQuery.getClauses方法代码示例

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


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

示例1: 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

示例2: asNGramQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * @param fieldName
 * @param gramSize
 * @return
 * @throws TooGeneralQueryException
 */
public Query asNGramQuery(String fieldName, int gramSize) throws TooGeneralQueryException {
	BooleanQuery orQuery = new BooleanQuery();
	for (List<LeafLiterals> row: rows) {
		BooleanQuery andQuery = new BooleanQuery();
		for (LeafLiterals literals: row) {
			if (literals.getLiteral() != null && literals.getLiteral().length()>=NGRAM_SIZE)
				andQuery.add(new NGramLuceneQuery(fieldName, literals.getLiteral(), gramSize), Occur.MUST);
		}
		if (andQuery.getClauses().length != 0)
			orQuery.add(andQuery, Occur.SHOULD);
	}
	if (orQuery.getClauses().length != 0)
		return orQuery;
	else
		throw new TooGeneralQueryException();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:23,代码来源:RegexLiterals.java

示例3: applyConstraints

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
protected void applyConstraints(BooleanQuery query) {
	boolean tooGeneral = true;
	for (char ch: fileNames.toCharArray()) {
		if (ch != '?' && ch != '*' && ch != ',' && ch != '.') {
			tooGeneral = false;
			break;
		}
	}
	if (tooGeneral)
		throw new TooGeneralQueryException();
	
	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);
	else
		throw new TooGeneralQueryException();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:22,代码来源:FileQuery.java

示例4: attach

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private static void attach (final BooleanQuery query, final TermCollector collector) {
    for (BooleanClause clause : query.getClauses()) {
        final Query q = clause.getQuery();
        if (!(q instanceof TermCollector.TermCollecting)) {
            throw new IllegalArgumentException();
        }
        ((TermCollector.TermCollecting)q).attach(collector);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:Queries.java

示例5: 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

示例6: addComplexPhraseClause

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private void addComplexPhraseClause(List<SpanQuery> spanClauses, BooleanQuery qc) {
  ArrayList<SpanQuery> ors = new ArrayList<>();
  ArrayList<SpanQuery> nots = new ArrayList<>();
  BooleanClause[] bclauses = qc.getClauses();

  // For all clauses e.g. one* two~
  for (int i = 0; i < bclauses.length; i++) {
    Query childQuery = bclauses[i].getQuery();

    // select the list to which we will add these options
    ArrayList<SpanQuery> chosenList = ors;
    if (bclauses[i].getOccur() == BooleanClause.Occur.MUST_NOT) {
      chosenList = nots;
    }

    if (childQuery instanceof TermQuery) {
      TermQuery tq = (TermQuery) childQuery;
      SpanTermQuery stq = new SpanTermQuery(tq.getTerm());
      stq.setBoost(tq.getBoost());
      chosenList.add(stq);
    } else if (childQuery instanceof BooleanQuery) {
      BooleanQuery cbq = (BooleanQuery) childQuery;
      addComplexPhraseClause(chosenList, cbq);
    } else {
      // TODO alternatively could call extract terms here?
      throw new IllegalArgumentException("Unknown query type:"
          + childQuery.getClass().getName());
    }
  }
  if (ors.size() == 0) {
    return;
  }
  SpanOrQuery soq = new SpanOrQuery(ors
      .toArray(new SpanQuery[ors.size()]));
  if (nots.size() == 0) {
    spanClauses.add(soq);
  } else {
    SpanOrQuery snqs = new SpanOrQuery(nots
        .toArray(new SpanQuery[nots.size()]));
    SpanNotQuery snq = new SpanNotQuery(soq, snqs);
    spanClauses.add(snq);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:44,代码来源:ComplexPhraseQueryParser.java


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