List of usage examples for org.apache.lucene.index SortedDocValues SortedDocValues
protected SortedDocValues()
From source file:lucene.security.index.SecureAtomicReader.java
License:Apache License
@Override public SortedDocValues getSortedDocValues(String field) throws IOException { final SortedDocValues sortedDocValues = in.getSortedDocValues(field); if (sortedDocValues == null) { return null; }//from w ww . j a v a 2 s. c o m 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); } } }; }
From source file:org.apache.blur.lucene.codec.DiskDocValuesProducer.java
License:Apache License
@Override public SortedDocValues getSorted(FieldInfo field) throws IOException { final int valueCount = (int) binaries.get(field.number).count; final BinaryDocValues binary = getBinary(field); Tracer trace = Trace.trace("getSorted - BlockPackedReader - create"); final BlockPackedReader ordinals; try {/*from www . j a va2 s. c om*/ NumericEntry entry = ords.get(field.number); IndexInput data = this.data.clone(); data.seek(entry.offset); ordinals = new BlockPackedReader(data, entry.packedIntsVersion, entry.blockSize, entry.count, true); } finally { trace.done(); } return new SortedDocValues() { @Override public int getOrd(int docID) { return (int) ordinals.get(docID); } @Override public void lookupOrd(int ord, BytesRef result) { binary.get(ord, result); } @Override public int getValueCount() { return valueCount; } }; }
From source file:org.codelibs.elasticsearch.search.MultiValueMode.java
License:Apache License
/** * Return a {SortedDocValues} instance that can be used to sort documents * with this mode and the provided values. * * Allowed Modes: MIN, MAX//from w ww . java2 s . com */ public SortedDocValues select(final RandomAccessOrds values) { if (values.getValueCount() >= Integer.MAX_VALUE) { throw new UnsupportedOperationException( "fields containing more than " + (Integer.MAX_VALUE - 1) + " unique terms are unsupported"); } final SortedDocValues singleton = DocValues.unwrapSingleton(values); if (singleton != null) { return singleton; } else { return new SortedDocValues() { @Override public int getOrd(int docID) { return pick(values, docID); } @Override public BytesRef lookupOrd(int ord) { return values.lookupOrd(ord); } @Override public int getValueCount() { return (int) values.getValueCount(); } }; } }
From source file:org.codelibs.elasticsearch.search.MultiValueMode.java
License:Apache License
/** * Return a {SortedDocValues} instance that can be used to sort root documents * with this mode, the provided values and filters for root/inner documents. * * For every root document, the values of its inner documents will be aggregated. * * Allowed Modes: MIN, MAX/*from w ww . j a v a 2s.co m*/ * * NOTE: Calling the returned instance on docs that are not root docs is illegal * The returned instance can only be evaluate the current and upcoming docs */ public SortedDocValues select(final RandomAccessOrds values, final BitSet rootDocs, final DocIdSetIterator innerDocs) throws IOException { if (rootDocs == null || innerDocs == null) { return select(DocValues.emptySortedSet()); } final SortedDocValues selectedValues = select(values); return new SortedDocValues() { int lastSeenRootDoc = 0; int lastEmittedOrd = -1; @Override public BytesRef lookupOrd(int ord) { return selectedValues.lookupOrd(ord); } @Override public int getValueCount() { return selectedValues.getValueCount(); } @Override public int getOrd(int rootDoc) { assert rootDocs.get(rootDoc) : "can only sort root documents"; assert rootDoc >= lastSeenRootDoc : "can only evaluate current and upcoming root docs"; if (rootDoc == lastSeenRootDoc) { return lastEmittedOrd; } try { final int prevRootDoc = rootDocs.prevSetBit(rootDoc - 1); final int firstNestedDoc; if (innerDocs.docID() > prevRootDoc) { firstNestedDoc = innerDocs.docID(); } else { firstNestedDoc = innerDocs.advance(prevRootDoc + 1); } lastSeenRootDoc = rootDoc; return lastEmittedOrd = pick(selectedValues, innerDocs, firstNestedDoc, rootDoc); } catch (IOException e) { throw new RuntimeException(e); } } }; }
From source file:org.elasticsearch.search.MultiValueModeTests.java
License:Apache License
public void testSingleValuedOrds() throws Exception { final int numDocs = scaledRandomIntBetween(1, 100); final int[] array = new int[numDocs]; for (int i = 0; i < array.length; ++i) { if (randomBoolean()) { array[i] = randomInt(1000);//from www . ja v a 2 s. c om } else { array[i] = -1; } } final SortedDocValues singleValues = new SortedDocValues() { @Override public int getOrd(int docID) { return array[docID]; } @Override public BytesRef lookupOrd(int ord) { throw new UnsupportedOperationException(); } @Override public int getValueCount() { return 1 << 20; } }; final RandomAccessOrds multiValues = (RandomAccessOrds) DocValues.singleton(singleValues); verify(multiValues, numDocs); final FixedBitSet rootDocs = randomRootDocs(numDocs); final FixedBitSet innerDocs = randomInnerDocs(rootDocs); verify(multiValues, numDocs, rootDocs, innerDocs); }
From source file:org.meresco.lucene.search.JoinFieldComparator.java
License:Open Source License
@Override protected SortedDocValues getSortedDocValues(AtomicReaderContext context, String field) throws IOException { if (context != null) return super.getSortedDocValues(context, field); return new SortedDocValues() { @Override//from w w w . ja v a2s.c o m public int getOrd(int docID) { return -1; } @Override public int lookupTerm(BytesRef key) { return -1; } @Override public BytesRef lookupOrd(int ord) { return null; } @Override public int getValueCount() { return 0; } }; }