当前位置: 首页>>代码示例>>Java>>正文


Java DocsEnum类代码示例

本文整理汇总了Java中org.apache.lucene.index.DocsEnum的典型用法代码示例。如果您正苦于以下问题:Java DocsEnum类的具体用法?Java DocsEnum怎么用?Java DocsEnum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DocsEnum类属于org.apache.lucene.index包,在下文中一共展示了DocsEnum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: UnionDocsAndPositionsEnum

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
public UnionDocsAndPositionsEnum(Bits liveDocs, AtomicReaderContext context, Term[] terms, Map<Term,TermContext> termContexts, TermsEnum termsEnum) throws IOException {
  List<DocsAndPositionsEnum> docsEnums = new LinkedList<>();
  for (int i = 0; i < terms.length; i++) {
    final Term term = terms[i];
    TermState termState = termContexts.get(term).get(context.ord);
    if (termState == null) {
      // Term doesn't exist in reader
      continue;
    }
    termsEnum.seekExact(term.bytes(), termState);
    DocsAndPositionsEnum postings = termsEnum.docsAndPositions(liveDocs, null, DocsEnum.FLAG_NONE);
    if (postings == null) {
      // term does exist, but has no positions
      throw new IllegalStateException("field \"" + term.field() + "\" was indexed without position data; cannot run PhraseQuery (term=" + term.text() + ")");
    }
    cost += postings.cost();
    docsEnums.add(postings);
  }

  _queue = new DocsQueue(docsEnums);
  _posList = new IntQueue();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:MultiPhraseQuery.java

示例2: getPosEnum

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
protected DocsAndPositionsEnum getPosEnum(IndexReader r, int docid, Term t)
		throws IOException {
	List<AtomicReaderContext> leaves = r.getContext().leaves();
	for (AtomicReaderContext context : leaves) {
		AtomicReader reader = context.reader();
		DocsAndPositionsEnum termPositions = reader.termPositionsEnum(t);
		int doc;
		while ((doc = termPositions.nextDoc()) != DocsEnum.NO_MORE_DOCS
				&& doc != docid) {
		}
		if (doc != DocsEnum.NO_MORE_DOCS) {
			return termPositions;
		}
	}
	assertFalse("Expected positions enum for doc " + docid, true);
	return null; // will never come here
}
 
开发者ID:arne-cl,项目名称:fangorn,代码行数:18,代码来源:IndexTestCase.java

示例3: testDocsEnumStart

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
public void testDocsEnumStart() throws Exception {
  Analyzer analyzer = new MockAnalyzer(random());
  MemoryIndex memory = new MemoryIndex(random().nextBoolean(),  random().nextInt(50) * 1024 * 1024);
  memory.addField("foo", "bar", analyzer);
  AtomicReader reader = (AtomicReader) memory.createSearcher().getIndexReader();
  DocsEnum disi = TestUtil.docs(random(), reader, "foo", new BytesRef("bar"), null, null, DocsEnum.FLAG_NONE);
  int docid = disi.docID();
  assertEquals(-1, docid);
  assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
  
  // now reuse and check again
  TermsEnum te = reader.terms("foo").iterator(null);
  assertTrue(te.seekExact(new BytesRef("bar")));
  disi = te.docs(null, disi, DocsEnum.FLAG_NONE);
  docid = disi.docID();
  assertEquals(-1, docid);
  assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
  reader.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:MemoryIndexTest.java

示例4: docs

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
@Override
public DocsEnum docs(FieldInfo fieldInfo, BlockTermState _termState, Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
  final SepTermState termState = (SepTermState) _termState;
  SepDocsEnum docsEnum;
  if (reuse == null || !(reuse instanceof SepDocsEnum)) {
    docsEnum = new SepDocsEnum();
  } else {
    docsEnum = (SepDocsEnum) reuse;
    if (docsEnum.startDocIn != docIn) {
      // If you are using ParellelReader, and pass in a
      // reused DocsAndPositionsEnum, it could have come
      // from another reader also using sep codec
      docsEnum = new SepDocsEnum();        
    }
  }

  return docsEnum.init(fieldInfo, termState, liveDocs);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SepPostingsReader.java

示例5: getDocIdSet

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, final Bits acceptDocs) throws IOException {
  Terms terms = context.reader().terms(term.field());
  if (terms == null) {
    return null;
  }

  final TermsEnum termsEnum = terms.iterator(null);
  if (!termsEnum.seekExact(term.bytes())) {
    return null;
  }
  return new DocIdSet() {
    @Override
    public DocIdSetIterator iterator() throws IOException {
      return termsEnum.docs(acceptDocs, null, DocsEnum.FLAG_NONE);
    }

  };
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TermFilter.java

示例6: collectDocs

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
private SmallDocSet collectDocs(Bits acceptContains) throws IOException {
  SmallDocSet set = null;

  docsEnum = termsEnum.docs(acceptContains, docsEnum, DocsEnum.FLAG_NONE);
  int docid;
  while ((docid = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    if (set == null) {
      int size = termsEnum.docFreq();
      if (size <= 0)
        size = 16;
      set = new SmallDocSet(size);
    }
    set.set(docid);
  }
  return set;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:ContainsPrefixTreeFilter.java

示例7: docs

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
@Override
public DocsEnum docs(Bits liveDocs, DocsEnum reuse, final int flags) throws IOException {
  final DocsEnum inReuse;
  final SortingDocsEnum wrapReuse;
  if (reuse != null && reuse instanceof SortingDocsEnum) {
    // if we're asked to reuse the given DocsEnum and it is Sorting, return
    // the wrapped one, since some Codecs expect it.
    wrapReuse = (SortingDocsEnum) reuse;
    inReuse = wrapReuse.getWrapped();
  } else {
    wrapReuse = null;
    inReuse = reuse;
  }

  final DocsEnum inDocs = in.docs(newToOld(liveDocs), inReuse, flags);
  final boolean withFreqs = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS) >=0 && (flags & DocsEnum.FLAG_FREQS) != 0;
  return new SortingDocsEnum(docMap.size(), wrapReuse, inDocs, withFreqs, docMap);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SortingAtomicReader.java

示例8: score

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
@Override
public boolean score(Collector collector, int max) throws IOException {
  FakeScorer fakeScorer = new FakeScorer();
  collector.setScorer(fakeScorer);
  if (doc == -1) {
    doc = nextDocOutOfOrder();
  }
  while(doc < max) {
    fakeScorer.doc = doc;
    fakeScorer.score = scores[ords[scoreUpto]];
    collector.collect(doc);
    doc = nextDocOutOfOrder();
  }

  return doc != DocsEnum.NO_MORE_DOCS;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TermsIncludingScoreQuery.java

示例9: nextDocOutOfOrder

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
int nextDocOutOfOrder() throws IOException {
  while (true) {
    if (docsEnum != null) {
      int docId = docsEnumNextDoc();
      if (docId == DocIdSetIterator.NO_MORE_DOCS) {
        docsEnum = null;
      } else {
        return doc = docId;
      }
    }

    if (upto == terms.size()) {
      return doc = DocIdSetIterator.NO_MORE_DOCS;
    }

    scoreUpto = upto;
    if (termsEnum.seekExact(terms.get(ords[upto++], spare))) {
      docsEnum = reuse = termsEnum.docs(acceptDocs, reuse, DocsEnum.FLAG_NONE);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:TermsIncludingScoreQuery.java

示例10: fillDocsAndScores

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
protected void fillDocsAndScores(FixedBitSet matchingDocs, Bits acceptDocs, TermsEnum termsEnum) throws IOException {
  BytesRef spare = new BytesRef();
  DocsEnum docsEnum = null;
  for (int i = 0; i < terms.size(); i++) {
    if (termsEnum.seekExact(terms.get(ords[i], spare))) {
      docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
      float score = TermsIncludingScoreQuery.this.scores[ords[i]];
      for (int doc = docsEnum.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = docsEnum.nextDoc()) {
        matchingDocs.set(doc);
        // In the case the same doc is also related to a another doc, a score might be overwritten. I think this
        // can only happen in a many-to-many relation
        scores[doc] = score;
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TermsIncludingScoreQuery.java

示例11: lookup

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
/** Returns docID if found, else -1. */
public int lookup(BytesRef id, long version) throws IOException {
  for(int seg=0;seg<numSegs;seg++) {
    if (((IDVersionSegmentTermsEnum) termsEnums[seg]).seekExact(id, version)) {
      if (VERBOSE) {
        System.out.println("  found in seg=" + termsEnums[seg]);
      }
      docsEnums[seg] = termsEnums[seg].docs(liveDocs[seg], docsEnums[seg], 0);
      int docID = docsEnums[seg].nextDoc();
      if (docID != DocsEnum.NO_MORE_DOCS) {
        lastVersion = ((IDVersionSegmentTermsEnum) termsEnums[seg]).getVersion();
        return docBases[seg] + docID;
      }
      assert hasDeletions;
    }
  }

  return -1;
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestIDVersionPostingsFormat.java

示例12: docs

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
public static DocsEnum docs(Random random, TermsEnum termsEnum, Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
  if (random.nextBoolean()) {
    if (random.nextBoolean()) {
      final int posFlags;
      switch (random.nextInt(4)) {
        case 0: posFlags = 0; break;
        case 1: posFlags = DocsAndPositionsEnum.FLAG_OFFSETS; break;
        case 2: posFlags = DocsAndPositionsEnum.FLAG_PAYLOADS; break;
        default: posFlags = DocsAndPositionsEnum.FLAG_OFFSETS | DocsAndPositionsEnum.FLAG_PAYLOADS; break;
      }
      // TODO: cast to DocsAndPositionsEnum?
      DocsAndPositionsEnum docsAndPositions = termsEnum.docsAndPositions(liveDocs, null, posFlags);
      if (docsAndPositions != null) {
        return docsAndPositions;
      }
    }
    flags |= DocsEnum.FLAG_FREQS;
  }
  return termsEnum.docs(liveDocs, reuse, flags);
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestUtil.java

示例13: assertDocsEnumEquals

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
/**
 * checks docs + freqs, sequentially
 */
public void assertDocsEnumEquals(String info, DocsEnum leftDocs, DocsEnum rightDocs, boolean hasFreqs) throws IOException {
  if (leftDocs == null) {
    assertNull(rightDocs);
    return;
  }
  assertEquals(info, -1, leftDocs.docID());
  assertEquals(info, -1, rightDocs.docID());
  int docid;
  while ((docid = leftDocs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    assertEquals(info, docid, rightDocs.nextDoc());
    if (hasFreqs) {
      assertEquals(info, leftDocs.freq(), rightDocs.freq());
    }
  }
  assertEquals(info, DocIdSetIterator.NO_MORE_DOCS, rightDocs.nextDoc());
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:LuceneTestCase.java

示例14: testReuseDocsEnumNoReuse

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
public void testReuseDocsEnumNoReuse() throws IOException {
  Directory dir = newDirectory();
  Codec cp = TestUtil.alwaysPostingsFormat(new Lucene40RWPostingsFormat());
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir,
      newIndexWriterConfig(new MockAnalyzer(random())).setCodec(cp));
  int numdocs = atLeast(20);
  createRandomIndex(numdocs, writer, random());
  writer.commit();

  DirectoryReader open = DirectoryReader.open(dir);
  for (AtomicReaderContext ctx : open.leaves()) {
    AtomicReader indexReader = ctx.reader();
    Terms terms = indexReader.terms("body");
    TermsEnum iterator = terms.iterator(null);
    IdentityHashMap<DocsEnum, Boolean> enums = new IdentityHashMap<>();
    MatchNoBits bits = new Bits.MatchNoBits(indexReader.maxDoc());
    while ((iterator.next()) != null) {
      DocsEnum docs = iterator.docs(random().nextBoolean() ? bits : new Bits.MatchNoBits(indexReader.maxDoc()), null, random().nextBoolean() ? DocsEnum.FLAG_FREQS : DocsEnum.FLAG_NONE);
      enums.put(docs, true);
    }
    
    assertEquals(terms.size(), enums.size());
  }
  IOUtils.close(writer, open, dir);
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestReuseDocsEnum.java

示例15: getFirstMatch

import org.apache.lucene.index.DocsEnum; //导入依赖的package包/类
/**
 * Returns the first document number containing the term <code>t</code>
 * Returns -1 if no document was found.
 * This method is primarily intended for clients that want to fetch
 * documents using a unique identifier."
 * @return the first document number containing the term
 */
public int getFirstMatch(Term t) throws IOException {
  Fields fields = atomicReader.fields();
  if (fields == null) return -1;
  Terms terms = fields.terms(t.field());
  if (terms == null) return -1;
  BytesRef termBytes = t.bytes();
  final TermsEnum termsEnum = terms.iterator(null);
  if (!termsEnum.seekExact(termBytes)) {
    return -1;
  }
  DocsEnum docs = termsEnum.docs(atomicReader.getLiveDocs(), null, DocsEnum.FLAG_NONE);
  if (docs == null) return -1;
  int id = docs.nextDoc();
  return id == DocIdSetIterator.NO_MORE_DOCS ? -1 : id;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:SolrIndexSearcher.java


注:本文中的org.apache.lucene.index.DocsEnum类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。