本文整理匯總了Java中org.apache.lucene.search.TermQuery.getTerm方法的典型用法代碼示例。如果您正苦於以下問題:Java TermQuery.getTerm方法的具體用法?Java TermQuery.getTerm怎麽用?Java TermQuery.getTerm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.search.TermQuery
的用法示例。
在下文中一共展示了TermQuery.getTerm方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addComplexPhraseClause
import org.apache.lucene.search.TermQuery; //導入方法依賴的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);
}
}