本文整理汇总了Java中org.apache.lucene.util.ArrayUtil.mergeSort方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtil.mergeSort方法的具体用法?Java ArrayUtil.mergeSort怎么用?Java ArrayUtil.mergeSort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.util.ArrayUtil
的用法示例。
在下文中一共展示了ArrayUtil.mergeSort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConjunctionTermScorer
import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
ConjunctionTermScorer(Weight weight, float coord,
DocsAndFreqs[] docsAndFreqs) {
super(weight);
this.coord = coord;
this.docsAndFreqs = docsAndFreqs;
// Sort the array the first time to allow the least frequent DocsEnum to
// lead the matching.
ArrayUtil.mergeSort(docsAndFreqs, new Comparator<DocsAndFreqs>() {
public int compare(DocsAndFreqs o1, DocsAndFreqs o2) {
return o1.docFreq - o2.docFreq;
}
});
lead = docsAndFreqs[0]; // least frequent DocsEnum leads the
// intersection
}
示例2: initAtomicContextPositionsFreqs
import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
boolean initAtomicContextPositionsFreqs() throws IOException {
boolean foundAll = false;
// posEnum is in the same order as the labels in the query
final DocsAndPositionsEnum[] posEnum = new DocsAndPositionsEnum[labels.length];
final Term[] terms = new Term[labels.length];
final int[] docFreq = new int[labels.length];
while (!foundAll && contextIter.hasNext()) {
foundAll = true;
reader = contextIter.next().reader();
final Terms fieldTerms = reader.terms(Constants.FIELD_NAME);
final TermsEnum termsIterator = fieldTerms.iterator(null);
for (int i = 0; i < labels.length; i++) {
String label = labels[i];
terms[i] = new Term(Constants.FIELD_NAME, label);
boolean seek = termsIterator.seekExact(terms[i].bytes(), true);
if (!seek) {
foundAll = false;
break;
}
docFreq[i] = termsIterator.docFreq();
posEnum[i] = reader.termPositionsEnum(terms[i]);
if (posEnum[i] == null) {
foundAll = false;
break;
}
}
currentContextPos++;
}
if (foundAll) {
for (int i = 0; i < posEnum.length; i++) {
if (postingsFreqs[i] == null) {
postingsFreqs[i] = new PostingsAndFreq(posEnum[i],
docFreq[i], i, terms[i]);
if (parentPos[i] == -1) {
root = postingsFreqs[i];
}
} else {
postingsFreqs[i].reset(posEnum[i], docFreq[i], i, terms[i]);
if (parentPos[i] == -1) {
root = postingsFreqs[i];
}
}
}
setParentChild();
// so far the postingsFreqs is ordered in the same arrangement as
// the query terms; after the mergesort the order changes; the
// PostingsAndFreq object contains the position field that stores
// the position of the PostingsAndFreq term in the query but an
// inverse mapping from the query order to index on a particular
// PostingsAndFreq object in postingsFreqs is required in
// TwigStackJoin only
ArrayUtil.mergeSort(postingsFreqs);
for (int i = 0; i < postingsFreqs.length; i++) {
// Optimization copied from Lucene phrase query
// Coarse optimization: advance(target) is fairly
// costly, so, if the relative freq of the 2nd
// rarest term is not that much (> 1/5th) rarer than
// the first term, then we just use .nextDoc() when
// ANDing. This buys ~15% gain where
// freq of rarest 2 terms is close:
final boolean useAdvance = postingsFreqs[i].docFreq > 5 * postingsFreqs[0].docFreq;
postingsFreqs[i].setUseAdvance(useAdvance);
}
setupPerAtomicContext();
}
return foundAll;
}
示例3: ConjunctionScorer
import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
public ConjunctionScorer(Weight weight, int docBase, LearnToRankClause[] learnToRankclauses, Scorer... scorers)
throws IOException {
super(weight);
this.scorers = scorers;
this.clauses = learnToRankclauses;
this.docBase = docBase;
for (int i = 0; i < scorers.length; i++) {
if (scorers[i].nextDoc() == NO_MORE_DOCS) {
// If even one of the sub-scorers does not have any documents,
// this
// scorer should not attempt to do any more work.
lastDoc = NO_MORE_DOCS;
return;
}
}
// Sort the array the first time...
// We don't need to sort the array in any future calls because we know
// it will already start off sorted (all scorers on same doc).
// Note that this comparator is not consistent with equals!
// Also we use mergeSort here to be stable (so order of Scoreres that
// match on first document keeps preserved):
ArrayUtil.mergeSort(scorers, new Comparator<Scorer>() { // sort the
// array
public int compare(Scorer o1, Scorer o2) {
return o1.docID() - o2.docID();
}
});
// NOTE: doNext() must be called before the re-sorting of the array
// later on.
// The reason is this: assume there are 5 scorers, whose first docs are
// 1,
// 2, 3, 5, 5 respectively. Sorting (above) leaves the array as is.
// Calling
// doNext() here advances all the first scorers to 5 (or a larger doc ID
// they all agree on).
// However, if we re-sort before doNext() is called, the order will be
// 5, 3,
// 2, 1, 5 and then doNext() will stop immediately, since the first
// scorer's
// docs equals the last one. So the invariant that after calling
// doNext()
// all scorers are on the same doc ID is broken.
if (doNext() == NO_MORE_DOCS) {
// The scorers did not agree on any document.
lastDoc = NO_MORE_DOCS;
return;
}
// If first-time skip distance is any predictor of
// scorer sparseness, then we should always try to skip first on
// those scorers.
// Keep last scorer in it's last place (it will be the first
// to be skipped on), but reverse all of the others so that
// they will be skipped on in order of original high skip.
int end = scorers.length - 1;
int max = end >> 1;
for (int i = 0; i < max; i++) {
Scorer tmp = scorers[i];
LearnToRankClause tempc = clauses[i];
int idx = end - i - 1;
scorers[i] = scorers[idx];
clauses[i] = clauses[idx];
scorers[idx] = tmp;
clauses[idx] = tempc;
}
}