List of usage examples for org.apache.lucene.search DocIdSetIterator NO_MORE_DOCS
int NO_MORE_DOCS
To view the source code for org.apache.lucene.search DocIdSetIterator NO_MORE_DOCS.
Click Source Link
From source file:org.neo4j.kernel.api.impl.index.collector.DocValuesCollectorTest.java
License:Open Source License
@Test public void shouldCollectOneMatchingDocsPerSegment() throws Exception { // given/* www . j av a 2 s . com*/ DocValuesCollector collector = new DocValuesCollector(); IndexReaderStub readerStub = indexReaderWithMaxDocs(42); // when collector.doSetNextReader(readerStub.getContext()); collector.collect(1); collector.collect(3); collector.doSetNextReader(readerStub.getContext()); collector.collect(5); collector.collect(9); // then assertEquals(4, collector.getTotalHits()); List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs(); assertEquals(2, allMatchingDocs.size()); DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0); assertSame(readerStub.getContext(), matchingDocs.context); assertEquals(2, matchingDocs.totalHits); DocIdSetIterator idIterator = matchingDocs.docIdSet.iterator(); assertEquals(1, idIterator.nextDoc()); assertEquals(3, idIterator.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc()); matchingDocs = allMatchingDocs.get(1); assertSame(readerStub.getContext(), matchingDocs.context); assertEquals(2, matchingDocs.totalHits); idIterator = matchingDocs.docIdSet.iterator(); assertEquals(5, idIterator.nextDoc()); assertEquals(9, idIterator.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc()); }
From source file:org.neo4j.kernel.api.impl.index.DocValuesCollector.java
License:Open Source License
private void replayTo(Collector collector) throws IOException { for (MatchingDocs docs : getMatchingDocs()) { LeafCollector leafCollector = collector.getLeafCollector(docs.context); Scorer scorer;/*from w w w . j a va 2s . com*/ DocIdSetIterator disi = docs.docIdSet.iterator(); if (isKeepScores()) { scorer = new ReplayingScorer(docs.scores); } else { scorer = new ConstantScoreScorer(null, Float.NaN, disi); } leafCollector.setScorer(scorer); int doc; while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { leafCollector.collect(doc); } } }
From source file:org.neo4j.kernel.api.impl.index.DocValuesCollectorTest.java
License:Open Source License
@Test public void shouldCollectAllHitsPerSegment() throws Exception { // given// w w w.j a va2 s .c om DocValuesCollector collector = new DocValuesCollector(); IndexReaderStub readerStub = indexReaderWithMaxDocs(42); // when collector.doSetNextReader(readerStub.getContext()); collector.collect(1); collector.collect(3); collector.collect(5); collector.collect(9); // then assertEquals(4, collector.getTotalHits()); List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs(); assertEquals(1, allMatchingDocs.size()); DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0); assertSame(readerStub.getContext(), matchingDocs.context); assertEquals(4, matchingDocs.totalHits); DocIdSetIterator disi = matchingDocs.docIdSet.iterator(); assertEquals(1, disi.nextDoc()); assertEquals(3, disi.nextDoc()); assertEquals(5, disi.nextDoc()); assertEquals(9, disi.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, disi.nextDoc()); }
From source file:org.neo4j.kernel.api.impl.index.DocValuesCollectorTest.java
License:Open Source License
@Test public void shouldCollectOneMatchingDocsPerSegment() throws Exception { // given/*from w ww .j a v a2s .co m*/ DocValuesCollector collector = new DocValuesCollector(); IndexReaderStub readerStub = indexReaderWithMaxDocs(42); // when collector.doSetNextReader(readerStub.getContext()); collector.collect(1); collector.collect(3); collector.doSetNextReader(readerStub.getContext()); collector.collect(5); collector.collect(9); // then assertEquals(4, collector.getTotalHits()); List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs(); assertEquals(2, allMatchingDocs.size()); DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0); assertSame(readerStub.getContext(), matchingDocs.context); assertEquals(2, matchingDocs.totalHits); DocIdSetIterator disi = matchingDocs.docIdSet.iterator(); assertEquals(1, disi.nextDoc()); assertEquals(3, disi.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, disi.nextDoc()); matchingDocs = allMatchingDocs.get(1); assertSame(readerStub.getContext(), matchingDocs.context); assertEquals(2, matchingDocs.totalHits); disi = matchingDocs.docIdSet.iterator(); assertEquals(5, disi.nextDoc()); assertEquals(9, disi.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, disi.nextDoc()); }
From source file:org.neo4j.kernel.api.impl.index.LucenePartitionAllDocumentsReader.java
License:Open Source License
@Override public Iterator<Document> iterator() { return new PrefetchingIterator<Document>() { DocIdSetIterator idIterator = iterateAllDocs(); @Override// w w w. j a va2s .co m protected Document fetchNextOrNull() { try { int doc = idIterator.nextDoc(); if (doc == DocIdSetIterator.NO_MORE_DOCS) { return null; } return getDocument(doc); } catch (IOException e) { throw new LuceneDocumentRetrievalException("Can't fetch document id from lucene index.", e); } } }; }
From source file:org.opengrok.indexer.index.IndexDatabase.java
License:Open Source License
/** * Verify TABSIZE, and evaluate AnalyzerGuru version together with ZVER -- * or return a value to indicate mismatch. * @param file the source file object// w w w. j av a 2s . c o m * @param path the source file path * @return {@code false} if a mismatch is detected */ private boolean checkSettings(File file, String path) throws IOException { RuntimeEnvironment env = RuntimeEnvironment.getInstance(); boolean outIsXrefWriter = false; int reqTabSize = project != null && project.hasTabSizeSetting() ? project.getTabSize() : 0; Integer actTabSize = settings.getTabSize(); if (actTabSize != null && !actTabSize.equals(reqTabSize)) { LOGGER.log(Level.FINE, "Tabsize mismatch: {0}", path); return false; } int n = 0; postsIter = uidIter.postings(postsIter); while (postsIter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { ++n; // Read a limited-fields version of the document. Document doc = reader.document(postsIter.docID(), CHECK_FIELDS); if (doc == null) { LOGGER.log(Level.FINER, "No Document: {0}", path); continue; } long reqGuruVersion = AnalyzerGuru.getVersionNo(); Long actGuruVersion = settings.getAnalyzerGuruVersion(); /* * For an older OpenGrok index that does not yet have a defined, * stored analyzerGuruVersion, break so that no extra work is done. * After a re-index, the guru version check will be active. */ if (actGuruVersion == null) { break; } AbstractAnalyzer fa = null; String fileTypeName; if (actGuruVersion.equals(reqGuruVersion)) { fileTypeName = doc.get(QueryBuilder.TYPE); if (fileTypeName == null) { // (Should not get here, but break just in case.) LOGGER.log(Level.FINEST, "Missing TYPE field: {0}", path); break; } AnalyzerFactory fac = AnalyzerGuru.findByFileTypeName(fileTypeName); if (fac != null) { fa = fac.getAnalyzer(); } } else { /* * If the stored guru version does not match, re-verify the * selection of analyzer or return a value to indicate the * analyzer is now mis-matched. */ LOGGER.log(Level.FINER, "Guru version mismatch: {0}", path); fa = getAnalyzerFor(file, path); fileTypeName = fa.getFileTypeName(); String oldTypeName = doc.get(QueryBuilder.TYPE); if (!fileTypeName.equals(oldTypeName)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Changed {0} to {1}: {2}", new Object[] { oldTypeName, fileTypeName, path }); } return false; } } // Verify Analyzer version, or return a value to indicate mismatch. long reqVersion = AnalyzerGuru.getAnalyzerVersionNo(fileTypeName); Long actVersion = settings.getAnalyzerVersion(fileTypeName); if (actVersion == null || !actVersion.equals(reqVersion)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "{0} version mismatch: {1}", new Object[] { fileTypeName, path }); } return false; } if (fa != null) { outIsXrefWriter = isXrefWriter(fa); } // The versions checks have passed. break; } if (n < 1) { LOGGER.log(Level.FINER, "Missing index Documents: {0}", path); return false; } // If the economy mode is on, this should be treated as a match. if (!env.isGenerateHtml()) { if (xrefExistsFor(path)) { LOGGER.log(Level.FINEST, "Extraneous {0} , removing its xref file", path); removeXrefFile(path); } return true; } return (!outIsXrefWriter || xrefExistsFor(path)); }
From source file:org.opengrok.indexer.search.context.OGKUnifiedHighlighter.java
License:Apache License
/** * Produces original text by reading from OpenGrok source content relative * to {@link RuntimeEnvironment#getSourceRootPath()} and returns the content * for each document if the timestamp matches -- or else just {@code null} * for a missing file or a timestamp mismatch (as "the returned Strings must * be identical to what was indexed.")/* w w w . j av a2 s . co m*/ * <p> * "This method must load fields for at least one document from the given * {@link DocIdSetIterator} but need not return all of them; by default the * character lengths are summed and this method will return early when * {@code cacheCharsThreshold} is exceeded. Specifically if that number is * 0, then only one document is fetched no matter what. Values in the array * of {@link CharSequence} will be {@code null} if no value was found." * @return a defined instance * @throws IOException if an I/O error occurs */ @Override protected List<CharSequence[]> loadFieldValues(String[] fields, DocIdSetIterator docIter, int cacheCharsThreshold) throws IOException { List<CharSequence[]> docListOfFields = new ArrayList<>( cacheCharsThreshold == 0 ? 1 : (int) Math.min(64, docIter.cost())); int sumChars = 0; do { int docId = docIter.nextDoc(); if (docId == DocIdSetIterator.NO_MORE_DOCS) { break; } Document doc = searcher.doc(docId); String path = doc.get(QueryBuilder.PATH); String storedU = doc.get(QueryBuilder.U); String content = getRepoFileContent(path, storedU); CharSequence[] seqs = new CharSequence[fields.length]; Arrays.fill(seqs, content); docListOfFields.add(seqs); if (content != null) { sumChars += content.length(); } } while (sumChars <= cacheCharsThreshold && cacheCharsThreshold != 0); return docListOfFields; }
From source file:org.opengrok.suggest.query.customized.CustomSloppyPhraseScorer.java
License:Apache License
/** map each term to the single group that contains it */ private HashMap<Term, Integer> termGroups(LinkedHashMap<Term, Integer> tord, ArrayList<FixedBitSet> bb) throws IOException { HashMap<Term, Integer> tg = new HashMap<>(); Term[] t = tord.keySet().toArray(new Term[0]); for (int i = 0; i < bb.size(); i++) { // i is the group no. FixedBitSet bits = bb.get(i);//from ww w.j av a2s .c o m for (int ord = bits.nextSetBit(0); ord != DocIdSetIterator.NO_MORE_DOCS; ord = ord + 1 >= bits.length() ? DocIdSetIterator.NO_MORE_DOCS : bits.nextSetBit(ord + 1)) { tg.put(t[ord], i); } } return tg; }
From source file:org.opengrok.suggest.query.customized.CustomSloppyPhraseScorerTest.java
License:Open Source License
@SuppressWarnings("unchecked") // for contains() public static void test(final int slop, final int offset, final String[] terms, final Integer[] expectedPositions) throws IOException { Directory dir = new ByteBuffersDirectory(); try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) { Document doc = new Document(); doc.add(new TextField("test", "zero one two three four five six seven eight nine ten", Field.Store.NO)); iw.addDocument(doc);//w w w . j a v a 2 s. c o m } CustomPhraseQuery query = new CustomPhraseQuery(slop, "test", terms); query.offset = offset; try (IndexReader ir = DirectoryReader.open(dir)) { IndexSearcher is = new IndexSearcher(ir); Weight w = query.createWeight(is, false, 1); LeafReaderContext context = ir.getContext().leaves().get(0); Scorer scorer = w.scorer(context); TwoPhaseIterator it = scorer.twoPhaseIterator(); int correctDoc = -1; int docId; while ((docId = it.approximation().nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (it.matches()) { correctDoc = docId; } } BitIntsHolder bs = (BitIntsHolder) ((PhraseScorer) scorer).getPositions(correctDoc); assertThat(toSet(bs), contains(expectedPositions)); } }
From source file:org.opengrok.suggest.SuggesterSearcher.java
License:Open Source License
private int getPhraseScore(final ComplexQueryData data, final int docBase, final PostingsEnum postingsEnum) throws IOException { int weight = 0; while (postingsEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { int docId = postingsEnum.docID(); if (data.documentIds.has(docBase + docId)) { IntsHolder positions = data.scorer.getPositions(docBase + docId); if (positions == null) { continue; }//from w w w. ja v a 2s . co m int freq = postingsEnum.freq(); for (int i = 0; i < freq; i++) { int pos = postingsEnum.nextPosition(); if (positions.has(pos)) { weight++; } } } } return weight; }