本文整理汇总了Java中org.apache.lucene.search.Weight.extractTerms方法的典型用法代码示例。如果您正苦于以下问题:Java Weight.extractTerms方法的具体用法?Java Weight.extractTerms怎么用?Java Weight.extractTerms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.Weight
的用法示例。
在下文中一共展示了Weight.extractTerms方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertUnknownQuery
import org.apache.lucene.search.Weight; //导入方法依赖的package包/类
@Override
protected SpanQuery convertUnknownQuery(String field, Query query) {
if (query instanceof CommonTermsQuery) {
// specialized since rewriting would change the result query
// this query is TermContext sensitive.
CommonTermsQuery ctq = (CommonTermsQuery) query;
Set<Term> terms = new HashSet<>();
try {
Weight w = ctq.createWeight(searcher, false, 1.0f);
w.extractTerms(terms);
} catch (IOException e) {
throw new RuntimeException("IOException on searcher!!!", e);
}
List<SpanQuery> spanQs = new LinkedList<>();
for (Term term : terms) {
if (term.field().equals(field)) {
spanQs.add(new SpanTermQuery(term));
}
}
if (spanQs.size() == 0) {
return getEmptySpanQuery();
} else if (spanQs.size() == 1) {
return spanQs.get(0);
} else {
return new SpanOrQuery(spanQs.toArray(new SpanQuery[spanQs.size()]));
}
}
super.convertUnknownQuery(field, query);
return null;
}
示例2: searchSingleTerms
import org.apache.lucene.search.Weight; //导入方法依赖的package包/类
/**
* Simple utility class to perform basic term frequency/document frequency
* counts on the individual terms within a query. This relies on
* IndexReader and does not perform any concordance search/retrieval;
* it is, therefore, very fast.
* <p>
* If you want to visit more than basic terms (e.g. SpanNear),
* see {@link org.apache.lucene.search.concordance.windowvisitor.TargetVisitor}
*
* @param query query
* @param searcher searcher
* @return target term results
* @throws java.io.IOException if there is an IOException from the searcher
*/
public SimpleTargetTermResults searchSingleTerms(Query query, IndexSearcher searcher)
throws IOException {
Query tmpQ = query.rewrite(searcher.getIndexReader());
Set<Term> terms = new HashSet<>();
Weight weight = tmpQ.createWeight(searcher, false, 1.0f);//default boost 1.0f.
weight.extractTerms(terms);
Map<String, Integer> dfs = new HashMap<>();
Map<String, Integer> tfs = new HashMap<>();
for (Term t : terms) {
String targ = t.text();
int docFreq = searcher.getIndexReader().docFreq(t);
if (docFreq == 0) {
continue;
}
Integer i = Integer.valueOf(docFreq);
dfs.put(targ, i);
long tf = searcher.getIndexReader().totalTermFreq(t);
tfs.put(targ, (int) tf);
}
return new SimpleTargetTermResults(dfs, tfs);
}
示例3: extractTerms
import org.apache.lucene.search.Weight; //导入方法依赖的package包/类
@Override
public void extractTerms(Set<Term> terms) {
for (Weight w : weights) {
w.extractTerms(terms);
}
}