本文整理汇总了Java中org.apache.lucene.util.PriorityQueue.size方法的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue.size方法的具体用法?Java PriorityQueue.size怎么用?Java PriorityQueue.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.util.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDocHits
import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/** Construct the array of doc hits for the hit group. */
private void buildDocHits(int group, ResultGroup resultGroup)
{
PriorityQueue queue = hitQueue[group];
int nFound = queue.size();
DocHitImpl[] hitArray = new DocHitImpl[nFound];
for (int i = 0; i < nFound; i++) {
int index = nFound - i - 1;
hitArray[index] = (DocHitImpl)queue.pop();
}
int start = startDoc[group];
int max = maxDocs[group];
int nHits = Math.max(0, Math.min(nFound - start, max));
resultGroup.docHits = new DocHit[nHits];
resultGroup.totalDocs = nDocHits(group);
resultGroup.startDoc = start;
resultGroup.endDoc = start + nHits;
for (int i = startDoc[group]; i < nFound; i++)
resultGroup.docHits[i - start] = hitArray[i];
}
示例2: bestTerms
import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
private String [] bestTerms(String field,int numTerms) throws IOException {
PriorityQueue<TermDf> pq = new TermsDfQueue(numTerms);
IndexReader ir = DirectoryReader.open(dir);
try {
int threshold = ir.maxDoc() / 10; // ignore words too common.
Terms terms = MultiFields.getTerms(ir, field);
if (terms != null) {
TermsEnum termsEnum = terms.iterator(null);
while (termsEnum.next() != null) {
int df = termsEnum.docFreq();
if (df<threshold) {
String ttxt = termsEnum.term().utf8ToString();
pq.insertWithOverflow(new TermDf(ttxt,df));
}
}
}
} finally {
ir.close();
}
String res[] = new String[pq.size()];
int i = 0;
while (pq.size()>0) {
TermDf tdf = pq.pop();
res[i++] = tdf.word;
System.out.println(i+". word: "+tdf.df+" "+tdf.word);
}
return res;
}
示例3: queueToList
import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
private static List<TermAndFreq> queueToList(PriorityQueue<TermAndFreq> queue) {
List<TermAndFreq> terms = new ArrayList<>();
while (queue.size() > 0) {
terms.add(queue.pop());
}
return terms;
}
示例4: queueToList
import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
private static List<TermAndFreq> queueToList(PriorityQueue<TermAndFreq> queue) {
List<TermAndFreq> terms = new ArrayList<CommonTermsQueryTest.TermAndFreq>();
while (queue.size() > 0) {
terms.add(queue.pop());
}
return terms;
}
示例5: createQuery
import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
* Create the More like query from a PriorityQueue
*/
private Query createQuery(IndexReader indexReader, PriorityQueue q)
throws IOException
{
// Pop everything from the queue.
QueryWord[] queryWords = new QueryWord[q.size()];
for (int i = q.size() - 1; i >= 0; i--)
queryWords[i] = (QueryWord)q.pop();
BooleanQuery query = new BooleanQuery(true /*disable coord*/);
// At the moment, there's no need to scale by the best score. It simply
// clouds the query explanation. It doesn't affect the scores, since
// Lucene applies a query normalization factor anyway.
//
//float bestScore = (queryWords.length > 0) ? queryWords[0].score : 0.0f;
for (int i = 0; i < fieldNames.length; i++)
{
ArrayList fieldClauses = new ArrayList();
for (int j = 0; j < queryWords.length; j++)
{
QueryWord qw = queryWords[j];
Term term = new Term(fieldNames[i], qw.word);
// Skip words not present in this field.
int docFreq = indexReader.docFreq(term);
if (docFreq == 0)
continue;
// Add it to the query.
SpanTermQuery tq = new SpanTermQuery(term);
if (boost)
tq.setBoost(qw.score);
fieldClauses.add(tq);
} // for j
// If no terms for this field, skip it.
if (fieldClauses.isEmpty())
continue;
SpanQuery[] clauses = (SpanQuery[])fieldClauses.toArray(
new SpanQuery[fieldClauses.size()]);
// Now make a special Or-Near query out of the clauses.
SpanOrNearQuery fieldQuery = new SpanOrNearQuery(clauses, 10, false);
// Boost if necessary.
if (fieldBoosts != null)
fieldQuery.setBoost(fieldBoosts[i]);
// We currently don't support more-like-this queries on the full text.
// It would involve de-chunking, and also fancier logic to pick the
// "most interesting" terms in the first place.
//
if (fieldNames[i].equals("text"))
throw new RuntimeException("MoreLikeThisQuery does not support 'text' field.");
// And add to the main query.
query.add(fieldQuery, BooleanClause.Occur.SHOULD);
} // for i
// All done.
return query;
}