Java Code Examples for org.apache.lucene.index.SortedDocValues#lookupOrd()
The following examples show how to use
org.apache.lucene.index.SortedDocValues#lookupOrd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LegacyDocValuesIterables.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Converts {@link SortedDocValues} into an {@code Iterable<BytesRef>} for all the values. * * @deprecated Consume {@link SortedDocValues} instead. */ @Deprecated public static Iterable<BytesRef> valuesIterable(final SortedDocValues values) { return new Iterable<BytesRef>() { @Override public Iterator<BytesRef> iterator() { return new Iterator<BytesRef>() { private int nextOrd; @Override public boolean hasNext() { return nextOrd < values.getValueCount(); } @Override public BytesRef next() { try { return values.lookupOrd(nextOrd++); } catch (IOException e) { throw new RuntimeException(e); } } }; } }; }
Example 2
Source File: GlobalOrdinalsQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SortedDocValues values = DocValues.getSorted(context.reader(), joinField); if (values == null) { return Explanation.noMatch("Not a match"); } if (values.advance(doc) != doc) { return Explanation.noMatch("Not a match"); } int segmentOrd = values.ordValue(); BytesRef joinValue = values.lookupOrd(segmentOrd); int ord; if (globalOrds != null) { ord = (int) globalOrds.getGlobalOrds(context.ord).get(segmentOrd); } else { ord = segmentOrd; } if (foundOrds.get(ord) == false) { return Explanation.noMatch("Not a match, join value " + Term.toString(joinValue)); } return Explanation.match(score(), "A match, join value " + Term.toString(joinValue)); }
Example 3
Source File: GlobalOrdinalsWithScoreQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SortedDocValues values = DocValues.getSorted(context.reader(), joinField); if (values == null) { return Explanation.noMatch("Not a match"); } if (values.advance(doc) != doc) { return Explanation.noMatch("Not a match"); } int segmentOrd = values.ordValue(); BytesRef joinValue = values.lookupOrd(segmentOrd); int ord; if (globalOrds != null) { ord = (int) globalOrds.getGlobalOrds(context.ord).get(segmentOrd); } else { ord = segmentOrd; } if (collector.match(ord) == false) { return Explanation.noMatch("Not a match, join value " + Term.toString(joinValue)); } float score = collector.score(ord); return Explanation.match(score, "A match, join value " + Term.toString(joinValue)); }
Example 4
Source File: TestFieldCacheVsDocValues.java From lucene-solr with Apache License 2.0 | 5 votes |
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; } 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()); }
Example 5
Source File: SecureAtomicReader.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortedDocValues getSortedDocValues(String field) throws IOException { final SortedDocValues sortedDocValues = in.getSortedDocValues(field); if (sortedDocValues == null) { return null; } return new SortedDocValues() { @Override public void lookupOrd(int ord, BytesRef result) { sortedDocValues.lookupOrd(ord, result); } @Override public int getValueCount() { return sortedDocValues.getValueCount(); } @Override public int getOrd(int docID) { try { if (_accessControl.hasAccess(ReadType.SORTED_DOC_VALUE, docID)) { return sortedDocValues.getOrd(docID); } return -1; // Default missing value. } catch (IOException e) { throw new RuntimeException(e); } } }; }