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


Java DocsEnum.docID方法代码示例

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


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

示例1: 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

示例2: 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();
  assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
  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"), true));
  disi = te.docs(null, disi, DocsEnum.FLAG_NONE);
  docid = disi.docID();
  assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
  assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
  reader.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:20,代码来源:MemoryIndexTest.java

示例3: getOrdinal

import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
@Override
public int getOrdinal(FacetLabel cp) throws IOException {
  ensureOpen();
  if (cp.length == 0) {
    return ROOT_ORDINAL;
  }

  // First try to find the answer in the LRU cache:
  synchronized (ordinalCache) {
    Integer res = ordinalCache.get(cp);
    if (res != null) {
      if (res.intValue() < indexReader.maxDoc()) {
        // Since the cache is shared with DTR instances allocated from
        // doOpenIfChanged, we need to ensure that the ordinal is one that
        // this DTR instance recognizes.
        return res.intValue();
      } else {
        // if we get here, it means that the category was found in the cache,
        // but is not recognized by this TR instance. Therefore there's no
        // need to continue search for the path on disk, because we won't find
        // it there too.
        return TaxonomyReader.INVALID_ORDINAL;
      }
    }
  }

  // If we're still here, we have a cache miss. We need to fetch the
  // value from disk, and then also put it in the cache:
  int ret = TaxonomyReader.INVALID_ORDINAL;
  DocsEnum docs = MultiFields.getTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(FacetsConfig.pathToString(cp.components, cp.length)), 0);
  if (docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
    ret = docs.docID();
    
    // we only store the fact that a category exists, not its inexistence.
    // This is required because the caches are shared with new DTR instances
    // that are allocated from doOpenIfChanged. Therefore, if we only store
    // information about found categories, we cannot accidently tell a new
    // generation of DTR that a category does not exist.
    synchronized (ordinalCache) {
      ordinalCache.put(cp, Integer.valueOf(ret));
    }
  }

  return ret;
}
 
开发者ID:europeana,项目名称:search,代码行数:46,代码来源:DirectoryTaxonomyReader.java

示例4: 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);
   
}
 
开发者ID:europeana,项目名称:search,代码行数:75,代码来源:TestFilteredQuery.java

示例5: 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();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:58,代码来源:DrillSidewaysScorer.java

示例6: 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;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:47,代码来源:TakmiSampleFixer.java

示例7: getOrdinal

import org.apache.lucene.index.DocsEnum; //导入方法依赖的package包/类
@Override
public int getOrdinal(CategoryPath cp) throws IOException {
  ensureOpen();
  if (cp.length == 0) {
    return ROOT_ORDINAL;
  }

  // First try to find the answer in the LRU cache:
  synchronized (ordinalCache) {
    Integer res = ordinalCache.get(cp);
    if (res != null) {
      if (res.intValue() < indexReader.maxDoc()) {
        // Since the cache is shared with DTR instances allocated from
        // doOpenIfChanged, we need to ensure that the ordinal is one that
        // this DTR instance recognizes.
        return res.intValue();
      } else {
        // if we get here, it means that the category was found in the cache,
        // but is not recognized by this TR instance. Therefore there's no
        // need to continue search for the path on disk, because we won't find
        // it there too.
        return TaxonomyReader.INVALID_ORDINAL;
      }
    }
  }

  // If we're still here, we have a cache miss. We need to fetch the
  // value from disk, and then also put it in the cache:
  int ret = TaxonomyReader.INVALID_ORDINAL;
  DocsEnum docs = MultiFields.getTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(cp.toString(delimiter)), 0);
  if (docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
    ret = docs.docID();
    
    // we only store the fact that a category exists, not its inexistence.
    // This is required because the caches are shared with new DTR instances
    // that are allocated from doOpenIfChanged. Therefore, if we only store
    // information about found categories, we cannot accidently tell a new
    // generation of DTR that a category does not exist.
    synchronized (ordinalCache) {
      ordinalCache.put(cp, Integer.valueOf(ret));
    }
  }

  return ret;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:46,代码来源:DirectoryTaxonomyReader.java

示例8: 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);
   
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:70,代码来源:TestFilteredQuery.java


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