List of usage examples for org.apache.lucene.index SortedDocValues ordValue
public abstract int ordValue() throws IOException;
From source file:org.apache.solr.search.facet.FacetFieldProcessorByArrayDV.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); /** alternate trial implementations // ord/*from w w w .j ava 2 s . co m*/ // FieldUtil.visitOrds(singleDv, disi, (doc,ord)->{counts[ord+1]++;} ); FieldUtil.OrdValues ordValues = FieldUtil.getOrdValues(singleDv, disi); while (ordValues.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { counts[ ordValues.getOrd() + 1]++; } **/ // calculate segment-local counts int doc; if (singleDv instanceof FieldCacheImpl.SortedDocValuesImpl.Iter) { FieldCacheImpl.SortedDocValuesImpl.Iter fc = (FieldCacheImpl.SortedDocValuesImpl.Iter) singleDv; while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { counts[fc.getOrd(doc) + 1]++; } } else { while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (singleDv.advanceExact(doc)) { counts[singleDv.ordValue() + 1]++; } } } // convert segment-local counts to global counts 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.FacetFieldProcessorByArrayDV.java
License:Apache License
private void collectDocs(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int doc;/*from w ww. j a va 2 s . c om*/ while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (singleDv.advanceExact(doc)) { int segOrd = singleDv.ordValue(); collect(doc, segOrd, toGlobal); } } }
From source file:org.apache.solr.search.facet.FacetFieldProcessorByArrayDV.java
License:Apache License
private void collectCounts(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal) throws IOException { int doc;/*from w ww . j av a2 s. co m*/ if (singleDv instanceof FieldCacheImpl.SortedDocValuesImpl.Iter) { FieldCacheImpl.SortedDocValuesImpl.Iter fc = (FieldCacheImpl.SortedDocValuesImpl.Iter) singleDv; while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { int segOrd = fc.getOrd(doc); if (segOrd < 0) continue; int ord = (int) toGlobal.get(segOrd); countAcc.incrementCount(ord, 1); } } else { while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (singleDv.advanceExact(doc)) { int segOrd = singleDv.ordValue(); 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 w ww.ja 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.uninverting.TestFieldCache.java
License:Apache License
public void testDocValuesIntegration() throws Exception { Directory dir = newDirectory();//from w ww . ja va 2 s.co m IndexWriterConfig iwc = newIndexWriterConfig(null); RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc); Document doc = new Document(); doc.add(new BinaryDocValuesField("binary", new BytesRef("binary value"))); doc.add(new SortedDocValuesField("sorted", new BytesRef("sorted value"))); doc.add(new NumericDocValuesField("numeric", 42)); doc.add(new SortedSetDocValuesField("sortedset", new BytesRef("sortedset value1"))); doc.add(new SortedSetDocValuesField("sortedset", new BytesRef("sortedset value2"))); iw.addDocument(doc); DirectoryReader ir = iw.getReader(); iw.close(); LeafReader ar = getOnlyLeafReader(ir); // Binary type: can be retrieved via getTerms() expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getNumerics(ar, "binary", FieldCache.INT_POINT_PARSER); }); BinaryDocValues binary = FieldCache.DEFAULT.getTerms(ar, "binary"); assertEquals(0, binary.nextDoc()); final BytesRef term = binary.binaryValue(); assertEquals("binary value", term.utf8ToString()); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getTermsIndex(ar, "binary"); }); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getDocTermOrds(ar, "binary", null); }); expectThrows(IllegalStateException.class, () -> { new DocTermOrds(ar, null, "binary"); }); Bits bits = FieldCache.DEFAULT.getDocsWithField(ar, "binary", null); assertTrue(bits.get(0)); // Sorted type: can be retrieved via getTerms(), getTermsIndex(), getDocTermOrds() expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getNumerics(ar, "sorted", FieldCache.INT_POINT_PARSER); }); expectThrows(IllegalStateException.class, () -> { new DocTermOrds(ar, null, "sorted"); }); binary = FieldCache.DEFAULT.getTerms(ar, "sorted"); assertEquals(0, binary.nextDoc()); BytesRef scratch = binary.binaryValue(); assertEquals("sorted value", scratch.utf8ToString()); SortedDocValues sorted = FieldCache.DEFAULT.getTermsIndex(ar, "sorted"); assertEquals(0, sorted.nextDoc()); assertEquals(0, sorted.ordValue()); assertEquals(1, sorted.getValueCount()); scratch = sorted.binaryValue(); assertEquals("sorted value", scratch.utf8ToString()); SortedSetDocValues sortedSet = FieldCache.DEFAULT.getDocTermOrds(ar, "sorted", null); assertEquals(0, sortedSet.nextDoc()); assertEquals(0, sortedSet.nextOrd()); assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSet.nextOrd()); assertEquals(1, sortedSet.getValueCount()); bits = FieldCache.DEFAULT.getDocsWithField(ar, "sorted", null); assertTrue(bits.get(0)); // Numeric type: can be retrieved via getInts() and so on NumericDocValues numeric = FieldCache.DEFAULT.getNumerics(ar, "numeric", FieldCache.INT_POINT_PARSER); assertEquals(0, numeric.nextDoc()); assertEquals(42, numeric.longValue()); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getTerms(ar, "numeric"); }); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getTermsIndex(ar, "numeric"); }); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getDocTermOrds(ar, "numeric", null); }); expectThrows(IllegalStateException.class, () -> { new DocTermOrds(ar, null, "numeric"); }); bits = FieldCache.DEFAULT.getDocsWithField(ar, "numeric", null); assertTrue(bits.get(0)); // SortedSet type: can be retrieved via getDocTermOrds() expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getNumerics(ar, "sortedset", FieldCache.INT_POINT_PARSER); }); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getTerms(ar, "sortedset"); }); expectThrows(IllegalStateException.class, () -> { FieldCache.DEFAULT.getTermsIndex(ar, "sortedset"); }); expectThrows(IllegalStateException.class, () -> { new DocTermOrds(ar, null, "sortedset"); }); sortedSet = FieldCache.DEFAULT.getDocTermOrds(ar, "sortedset", null); assertEquals(0, sortedSet.nextDoc()); assertEquals(0, sortedSet.nextOrd()); assertEquals(1, sortedSet.nextOrd()); assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSet.nextOrd()); assertEquals(2, sortedSet.getValueCount()); bits = FieldCache.DEFAULT.getDocsWithField(ar, "sortedset", null); assertTrue(bits.get(0)); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheVsDocValues.java
License:Apache License
private void assertEquals(int maxDoc, SortedDocValues expected, SortedDocValues actual) throws Exception { // can be null for the segment if no docs actually had any SortedDocValues // in this case FC.getDocTermsOrds returns EMPTY if (actual == null) { assertEquals(expected.getValueCount(), 0); return;/*from w w w. j a va 2s . co m*/ } assertEquals(expected.getValueCount(), actual.getValueCount()); // compare ord lists while (true) { int docID = expected.nextDoc(); if (docID == NO_MORE_DOCS) { assertEquals(NO_MORE_DOCS, actual.nextDoc()); break; } assertEquals(docID, actual.nextDoc()); assertEquals(expected.ordValue(), actual.ordValue()); assertEquals(expected.binaryValue(), actual.binaryValue()); } // compare ord dictionary for (long i = 0; i < expected.getValueCount(); i++) { final BytesRef expectedBytes = BytesRef.deepCopyOf(expected.lookupOrd((int) i)); final BytesRef actualBytes = actual.lookupOrd((int) i); assertEquals(expectedBytes, actualBytes); } // compare termsenum assertEquals(expected.getValueCount(), expected.termsEnum(), actual.termsEnum()); }
From source file:org.elasticsearch.join.fetch.ParentJoinFieldSubFetchPhase.java
License:Apache License
private String getSortedDocValue(String field, LeafReader reader, int docId) { try {/*from w ww .ja v a 2s .c om*/ SortedDocValues docValues = reader.getSortedDocValues(field); if (docValues == null || docValues.advanceExact(docId) == false) { return null; } int ord = docValues.ordValue(); BytesRef joinName = docValues.lookupOrd(ord); return joinName.utf8ToString(); } catch (IOException e) { throw ExceptionsHelper.convertToElastic(e); } }