本文整理匯總了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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
}