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.apache.solr.search.facet.FacetFieldProcessorByEnumTermsStream.java
License:Apache License
private SimpleOrderedMap<Object> _nextBucket() throws IOException { DocSet termSet = null;//w w w.j a v a2 s . co m try { while (term != null) { if (startTermBytes != null && !StringHelper.startsWith(term, startTermBytes)) { break; } int df = termsEnum.docFreq(); if (df < effectiveMincount) { term = termsEnum.next(); continue; } if (termSet != null) { // termSet.decref(); // OFF-HEAP termSet = null; } int c = 0; if (hasSubFacets || df >= minDfFilterCache) { // use the filter cache if (deState == null) { deState = new SolrIndexSearcher.DocsEnumState(); deState.fieldName = sf.getName(); deState.liveDocs = fcontext.searcher.getSlowAtomicReader().getLiveDocs(); deState.termsEnum = termsEnum; deState.postingsEnum = postingsEnum; deState.minSetSizeCached = minDfFilterCache; } if (hasSubFacets || !countOnly) { DocSet termsAll = fcontext.searcher.getDocSet(deState); termSet = docs.intersection(termsAll); // termsAll.decref(); // OFF-HEAP c = termSet.size(); } else { c = fcontext.searcher.numDocs(docs, deState); } postingsEnum = deState.postingsEnum; resetStats(); if (!countOnly) { collect(termSet, 0); } } else { // We don't need the docset here (meaning no sub-facets). // if countOnly, then we are calculating some other stats... resetStats(); // lazy convert to fastForRandomSet if (fastForRandomSet == null) { fastForRandomSet = docs; if (docs instanceof SortedIntDocSet) { // OFF-HEAP todo: also check for native version SortedIntDocSet sset = (SortedIntDocSet) docs; fastForRandomSet = new HashDocSet(sset.getDocs(), 0, sset.size()); } } // iterate over TermDocs to calculate the intersection postingsEnum = termsEnum.postings(postingsEnum, PostingsEnum.NONE); if (postingsEnum instanceof MultiPostingsEnum) { MultiPostingsEnum.EnumWithSlice[] subs = ((MultiPostingsEnum) postingsEnum).getSubs(); int numSubs = ((MultiPostingsEnum) postingsEnum).getNumSubs(); for (int subindex = 0; subindex < numSubs; subindex++) { MultiPostingsEnum.EnumWithSlice sub = subs[subindex]; if (sub.postingsEnum == null) continue; int base = sub.slice.start; int docid; if (countOnly) { while ((docid = sub.postingsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (fastForRandomSet.exists(docid + base)) c++; } } else { setNextReader(leaves[sub.slice.readerIndex]); while ((docid = sub.postingsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (fastForRandomSet.exists(docid + base)) { c++; collect(docid, 0); } } } } } else { int docid; if (countOnly) { while ((docid = postingsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (fastForRandomSet.exists(docid)) c++; } } else { setNextReader(leaves[0]); while ((docid = postingsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (fastForRandomSet.exists(docid)) { c++; collect(docid, 0); } } } } } if (c < effectiveMincount) { term = termsEnum.next(); continue; } // handle offset and limit if (bucketsToSkip > 0) { bucketsToSkip--; term = termsEnum.next(); continue; } if (freq.limit >= 0 && ++bucketsReturned > freq.limit) { return null; } // set count in case other stats depend on it countAcc.incrementCount(0, c); // OK, we have a good bucket to return... first get bucket value before moving to next term Object bucketVal = sf.getType().toObject(sf, term); TermQuery bucketQuery = hasSubFacets ? new TermQuery(new Term(freq.field, term)) : null; term = termsEnum.next(); SimpleOrderedMap<Object> bucket = new SimpleOrderedMap<>(); bucket.add("val", bucketVal); addStats(bucket, 0); if (hasSubFacets) { processSubs(bucket, bucketQuery, termSet); } // TODO... termSet needs to stick around for streaming sub-facets? return bucket; } } finally { if (termSet != null) { // termSet.decref(); // OFF-HEAP termSet = null; } } // end of the iteration return null; }
From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java
License:Apache License
private void collectPerSeg(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int segMax = singleDv.getValueCount() + 1; final int[] counts = getCountArr(segMax); int doc;//w ww . j a v a2 s . com while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { counts[singleDv.getOrd(doc) + 1]++; } for (int i = 1; i < segMax; i++) { int segCount = counts[i]; if (segCount > 0) { int slot = toGlobal == null ? (i - 1) : (int) toGlobal.get(i - 1); countAcc.incrementCount(slot, segCount); } } }
From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java
License:Apache License
private void collectPerSeg(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int segMax = (int) multiDv.getValueCount(); final int[] counts = getCountArr(segMax); int doc;/*from w w w. j a v a2s.c o m*/ while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { multiDv.setDocument(doc); for (;;) { int segOrd = (int) multiDv.nextOrd(); if (segOrd < 0) break; counts[segOrd]++; } } for (int i = 0; i < segMax; i++) { int segCount = counts[i]; if (segCount > 0) { int slot = toGlobal == null ? (i) : (int) toGlobal.get(i); countAcc.incrementCount(slot, segCount); } } }
From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java
License:Apache License
private void collectDocs(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int doc;/*from www . j a v a 2 s . co m*/ while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { int segOrd = singleDv.getOrd(doc); if (segOrd < 0) continue; collect(doc, segOrd, toGlobal); } }
From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java
License:Apache License
private void collectCounts(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int doc;// ww w .ja v a2s .co m while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { int segOrd = singleDv.getOrd(doc); if (segOrd < 0) continue; int ord = (int) toGlobal.get(segOrd); countAcc.incrementCount(ord, 1); } }
From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java
License:Apache License
private void collectDocs(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int doc;// ww w .j av a 2 s . c o m while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { multiDv.setDocument(doc); for (;;) { int segOrd = (int) multiDv.nextOrd(); if (segOrd < 0) break; collect(doc, segOrd, toGlobal); } } }
From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java
License:Apache License
private void collectCounts(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int doc;//from w ww . j ava 2 s . c om while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { multiDv.setDocument(doc); for (;;) { int segOrd = (int) multiDv.nextOrd(); if (segOrd < 0) break; int ord = (int) toGlobal.get(segOrd); countAcc.incrementCount(ord, 1); } } }
From source file:org.apache.solr.search.facet.FieldUtil.java
License:Apache License
public static void visitOrds(SortedDocValues singleDv, DocIdSetIterator disi, OrdFunc ordFunc) throws IOException { int doc;//from ww w. j a v a 2 s .c o m if (singleDv instanceof FieldCacheImpl.SortedDocValuesImpl.Iter) { FieldCacheImpl.SortedDocValuesImpl.Iter fc = (FieldCacheImpl.SortedDocValuesImpl.Iter) singleDv; while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { ordFunc.handleOrd(doc, fc.getOrd(doc)); } } else { while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (singleDv.advanceExact(doc)) { ordFunc.handleOrd(doc, singleDv.ordValue()); } else { // TODO: optionally pass in missingOrd? } } } }
From source file:org.apache.solr.search.facet.UniqueSlotAcc.java
License:Apache License
private Object getShardHLL(int slot) throws IOException { FixedBitSet ords = arr[slot];/*from ww w.ja v a 2 s .c om*/ if (ords == null) return HLLAgg.NO_VALUES; HLL hll = factory.getHLL(); long maxOrd = ords.length(); Hash.LongPair hashResult = new Hash.LongPair(); for (int ord = -1; ++ord < maxOrd;) { ord = ords.nextSetBit(ord); if (ord == DocIdSetIterator.NO_MORE_DOCS) break; BytesRef val = lookupOrd(ord); // way to avoid recomputing hash across slots? Prob not worth space Hash.murmurhash3_x64_128(val.bytes, val.offset, val.length, 0, hashResult); // idea: if the set is small enough, just send the hashes? We can add at the top // level or even just do a hash table at the top level. hll.addRaw(hashResult.val1); } SimpleOrderedMap map = new SimpleOrderedMap(); map.add("hll", hll.toBytes()); return map; }
From source file:org.apache.solr.search.facet.UniqueSlotAcc.java
License:Apache License
private Object getShardValue(int slot) throws IOException { if (factory != null) return getShardHLL(slot); FixedBitSet ords = arr[slot];/* w w w . j av a 2s . c o m*/ int unique; if (counts != null) { unique = counts[slot]; } else { unique = ords == null ? 0 : ords.cardinality(); } SimpleOrderedMap map = new SimpleOrderedMap(); map.add("unique", unique); map.add("nTerms", nTerms); int maxExplicit = 100; // TODO: make configurable // TODO: share values across buckets if (unique > 0) { List lst = new ArrayList(Math.min(unique, maxExplicit)); long maxOrd = ords.length(); if (ords != null && ords.length() > 0) { for (int ord = 0; lst.size() < maxExplicit;) { ord = ords.nextSetBit(ord); if (ord == DocIdSetIterator.NO_MORE_DOCS) break; BytesRef val = lookupOrd(ord); Object o = field.getType().toObject(field, val); lst.add(o); if (++ord >= maxOrd) break; } } map.add("vals", lst); } return map; }