本文整理汇总了Java中org.apache.lucene.index.DocsEnum.advance方法的典型用法代码示例。如果您正苦于以下问题:Java DocsEnum.advance方法的具体用法?Java DocsEnum.advance怎么用?Java DocsEnum.advance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.index.DocsEnum
的用法示例。
在下文中一共展示了DocsEnum.advance方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDocsEnum
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
@Test
public void testDocsEnum() throws Exception {
Bits mappedLiveDocs = randomLiveDocs(reader.maxDoc());
TermsEnum termsEnum = reader.terms(DOCS_ENUM_FIELD).iterator(null);
assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef(DOCS_ENUM_TERM)));
DocsEnum docs = termsEnum.docs(mappedLiveDocs, null);
int doc;
int prev = -1;
while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
assertTrue("document " + doc + " marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(doc));
assertEquals("incorrect value; doc " + doc, sortedValues[doc].intValue(), Integer.parseInt(reader.document(doc).get(ID_FIELD)));
while (++prev < doc) {
assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
}
}
while (++prev < reader.maxDoc()) {
assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
}
DocsEnum reuse = docs;
docs = termsEnum.docs(mappedLiveDocs, reuse);
if (docs instanceof SortingDocsEnum) {
assertTrue(((SortingDocsEnum) docs).reused(reuse)); // make sure reuse worked
}
doc = -1;
prev = -1;
while ((doc = docs.advance(doc + 1)) != DocIdSetIterator.NO_MORE_DOCS) {
assertTrue("document " + doc + " marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(doc));
assertEquals("incorrect value; doc " + doc, sortedValues[doc].intValue(), Integer.parseInt(reader.document(doc).get(ID_FIELD)));
while (++prev < doc) {
assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
}
}
while (++prev < reader.maxDoc()) {
assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
}
}
示例2: assertDocsSkippingEquals
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
/**
* checks advancing docs
*/
public void assertDocsSkippingEquals(String info, IndexReader leftReader, int docFreq, DocsEnum leftDocs, DocsEnum rightDocs, boolean hasFreqs) throws IOException {
if (leftDocs == null) {
assertNull(rightDocs);
return;
}
int docid = -1;
int averageGap = leftReader.maxDoc() / (1+docFreq);
int skipInterval = 16;
while (true) {
if (random().nextBoolean()) {
// nextDoc()
docid = leftDocs.nextDoc();
assertEquals(info, docid, rightDocs.nextDoc());
} else {
// advance()
int skip = docid + (int) Math.ceil(Math.abs(skipInterval + random().nextGaussian() * averageGap));
docid = leftDocs.advance(skip);
assertEquals(info, docid, rightDocs.advance(skip));
}
if (docid == DocIdSetIterator.NO_MORE_DOCS) {
return;
}
if (hasFreqs) {
assertEquals(info, leftDocs.freq(), rightDocs.freq());
}
}
}
示例3: assertDocsSkipping
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
/**
* checks advancing docs
*/
public void assertDocsSkipping(int docFreq, DocsEnum leftDocs, DocsEnum rightDocs) throws Exception {
if (leftDocs == null) {
assertNull(rightDocs);
return;
}
int docid = -1;
int averageGap = MAXDOC / (1+docFreq);
int skipInterval = 16;
while (true) {
if (random().nextBoolean()) {
// nextDoc()
docid = leftDocs.nextDoc();
assertEquals(docid, rightDocs.nextDoc());
} else {
// advance()
int skip = docid + (int) Math.ceil(Math.abs(skipInterval + random().nextGaussian() * averageGap));
docid = leftDocs.advance(skip);
assertEquals(docid, rightDocs.advance(skip));
}
if (docid == DocIdSetIterator.NO_MORE_DOCS) {
return;
}
// we don't assert freqs, they are allowed to be different
}
}
示例4: applyFamily
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
private static void applyFamily(OpenBitSet bits, String family, AtomicReader atomicReader, int primeDocRowId,
int numberOfDocsInRow, Bits liveDocs) throws IOException {
Fields fields = atomicReader.fields();
Terms terms = fields.terms(BlurConstants.FAMILY);
TermsEnum iterator = terms.iterator(null);
BytesRef text = new BytesRef(family);
int lastDocId = primeDocRowId + numberOfDocsInRow;
if (iterator.seekExact(text, true)) {
DocsEnum docs = iterator.docs(liveDocs, null, DocsEnum.FLAG_NONE);
int doc = primeDocRowId;
while ((doc = docs.advance(doc)) < lastDocId) {
bits.set(doc - primeDocRowId);
}
}
}
示例5: checkDocs
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
private boolean checkDocs() throws IOException {
DocsEnum maskDocsEnum = _maskTermsEnum.docs(null, null, DocsEnum.FLAG_NONE);
DocsEnum docsEnum = in.docs(null, null, DocsEnum.FLAG_NONE);
int docId;
while ((docId = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
if (maskDocsEnum.advance(docId) != docId) {
return true;
}
}
return false;
}
示例6: testLeapFrogStrategy
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
public void testLeapFrogStrategy() throws IOException {
Directory directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter (random(), directory, newIndexWriterConfig(new MockAnalyzer(random())));
int numDocs = atLeast(50);
int totalDocsWithZero = 0;
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
int num = random().nextInt(10);
if (num == 0) {
totalDocsWithZero++;
}
doc.add (newTextField("field", ""+num, Field.Store.YES));
writer.addDocument (doc);
}
IndexReader reader = writer.getReader();
writer.close ();
final boolean queryFirst = random().nextBoolean();
IndexSearcher searcher = newSearcher(reader);
Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new Filter() {
@Override
public DocIdSet getDocIdSet(final AtomicReaderContext context, Bits acceptDocs)
throws IOException {
return new DocIdSet() {
@Override
public Bits bits() throws IOException {
return null;
}
@Override
public DocIdSetIterator iterator() throws IOException {
final DocsEnum termDocsEnum = context.reader().termDocsEnum(new Term("field", "0"));
if (termDocsEnum == null) {
return null;
}
return new DocIdSetIterator() {
boolean nextCalled;
boolean advanceCalled;
@Override
public int nextDoc() throws IOException {
assertTrue("queryFirst: "+ queryFirst + " advanced: " + advanceCalled + " next: "+ nextCalled, nextCalled || advanceCalled ^ !queryFirst);
nextCalled = true;
return termDocsEnum.nextDoc();
}
@Override
public int docID() {
return termDocsEnum.docID();
}
@Override
public int advance(int target) throws IOException {
assertTrue("queryFirst: "+ queryFirst + " advanced: " + advanceCalled + " next: "+ nextCalled, advanceCalled || nextCalled ^ queryFirst);
advanceCalled = true;
return termDocsEnum.advance(target);
}
@Override
public long cost() {
return termDocsEnum.cost();
}
};
}
};
}
}, queryFirst ? FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY : random()
.nextBoolean() ? FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY
: FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY); // if filterFirst, we can use random here since bits are null
TopDocs search = searcher.search(query, 10);
assertEquals(totalDocsWithZero, search.totalHits);
IOUtils.close(reader, writer, directory);
}
示例7: doBaseAdvanceScoring
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
/** Used when base query is highly constraining vs the
* drilldowns; in this case we just .next() on base and
* .advance() on the dims. */
private void doBaseAdvanceScoring(Collector collector, DocsEnum[][] docsEnums, Collector[] sidewaysCollectors) throws IOException {
//if (DEBUG) {
// System.out.println(" doBaseAdvanceScoring");
//}
int docID = baseScorer.docID();
final int numDims = dims.length;
nextDoc: while (docID != NO_MORE_DOCS) {
int failedDim = -1;
for(int dim=0;dim<numDims;dim++) {
// TODO: should we sort this 2nd dimension of
// docsEnums from most frequent to least?
boolean found = false;
for(DocsEnum docsEnum : docsEnums[dim]) {
if (docsEnum == null) {
continue;
}
if (docsEnum.docID() < docID) {
docsEnum.advance(docID);
}
if (docsEnum.docID() == docID) {
found = true;
break;
}
}
if (!found) {
if (failedDim != -1) {
// More than one dim fails on this document, so
// it's neither a hit nor a near-miss; move to
// next doc:
docID = baseScorer.nextDoc();
continue nextDoc;
} else {
failedDim = dim;
}
}
}
collectDocID = docID;
// TODO: we could score on demand instead since we are
// daat here:
collectScore = baseScorer.score();
if (failedDim == -1) {
collectHit(collector, sidewaysCollectors);
} else {
collectNearMiss(sidewaysCollectors, failedDim);
}
docID = baseScorer.nextDoc();
}
}
示例8: countIntersection
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
/**
* Count the size of the intersection between two lists: a TermDocs (list of
* documents in a certain category) and a DocIdSetIterator (list of documents
* matching a query).
*/
private static int countIntersection(DocsEnum p1, ScoredDocIDsIterator p2)
throws IOException {
// The documentation of of both TermDocs and DocIdSetIterator claim
// that we must do next() before doc(). So we do, and if one of the
// lists is empty, obviously return 0;
if (p1 == null || p1.nextDoc() == DocIdSetIterator.NO_MORE_DOCS) {
return 0;
}
if (!p2.next()) {
return 0;
}
int d1 = p1.docID();
int d2 = p2.getDocID();
int count = 0;
for (;;) {
if (d1 == d2) {
++count;
if (p1.nextDoc() == DocIdSetIterator.NO_MORE_DOCS) {
break; // end of list 1, nothing more in intersection
}
d1 = p1.docID();
if (!advance(p2, d1)) {
break; // end of list 2, nothing more in intersection
}
d2 = p2.getDocID();
} else if (d1 < d2) {
if (p1.advance(d2) == DocIdSetIterator.NO_MORE_DOCS) {
break; // end of list 1, nothing more in intersection
}
d1 = p1.docID();
} else /* d1>d2 */ {
if (!advance(p2, d1)) {
break; // end of list 2, nothing more in intersection
}
d2 = p2.getDocID();
}
}
return count;
}
示例9: testLeapFrogStrategy
import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
public void testLeapFrogStrategy() throws IOException {
Directory directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter (random(), directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
int numDocs = atLeast(50);
int totalDocsWithZero = 0;
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
int num = random().nextInt(10);
if (num == 0) {
totalDocsWithZero++;
}
doc.add (newTextField("field", ""+num, Field.Store.YES));
writer.addDocument (doc);
}
IndexReader reader = writer.getReader();
writer.close ();
final boolean queryFirst = random().nextBoolean();
IndexSearcher searcher = newSearcher(reader);
Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new Filter() {
@Override
public DocIdSet getDocIdSet(final AtomicReaderContext context, Bits acceptDocs)
throws IOException {
return new DocIdSet() {
@Override
public Bits bits() throws IOException {
return null;
}
@Override
public DocIdSetIterator iterator() throws IOException {
final DocsEnum termDocsEnum = context.reader().termDocsEnum(new Term("field", "0"));
if (termDocsEnum == null) {
return null;
}
return new DocIdSetIterator() {
boolean nextCalled;
boolean advanceCalled;
@Override
public int nextDoc() throws IOException {
assertTrue("queryFirst: "+ queryFirst + " advanced: " + advanceCalled + " next: "+ nextCalled, nextCalled || advanceCalled ^ !queryFirst);
nextCalled = true;
return termDocsEnum.nextDoc();
}
@Override
public int docID() {
return termDocsEnum.docID();
}
@Override
public int advance(int target) throws IOException {
assertTrue("queryFirst: "+ queryFirst + " advanced: " + advanceCalled + " next: "+ nextCalled, advanceCalled || nextCalled ^ queryFirst);
advanceCalled = true;
return termDocsEnum.advance(target);
}
};
}
};
}
}, queryFirst ? FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY : random()
.nextBoolean() ? FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY
: FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY); // if filterFirst, we can use random here since bits are null
TopDocs search = searcher.search(query, 10);
assertEquals(totalDocsWithZero, search.totalHits);
IOUtils.close(reader, writer, directory);
}