List of usage examples for org.apache.lucene.index DocValues getSortedSet
public static SortedSetDocValues getSortedSet(LeafReader reader, String field) throws IOException
From source file:org.apache.solr.analytics.function.field.BooleanMultiField.java
License:Apache License
@Override public void doSetNextReader(LeafReaderContext context) throws IOException { docValues = DocValues.getSortedSet(context.reader(), fieldName); // figure out what ord maps to true long numOrds = docValues.getValueCount(); // if no values in the segment, default trueOrd to something other then -1 (missing) int trueOrd = -2; for (int i = 0; i < numOrds; i++) { final BytesRef br = docValues.lookupOrd(i); if (br.length == 1 && br.bytes[br.offset] == 'T') { trueOrd = i;/*from w ww .j ava2 s . co m*/ break; } } this.trueOrd = trueOrd; }
From source file:org.apache.solr.analytics.function.field.DoubleMultiTrieField.java
License:Apache License
@Override public void doSetNextReader(LeafReaderContext context) throws IOException { docValues = DocValues.getSortedSet(context.reader(), fieldName); }
From source file:org.apache.solr.schema.TrieDoubleField.java
License:Apache License
@Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { return new SortedSetFieldSource(f.getName(), choice) { @Override//from w w w. ja v a 2s . c om public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { SortedSetFieldSource thisAsSortedSetFieldSource = this; // needed for nested anon class ref SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field); SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector); return new DoubleDocValues(thisAsSortedSetFieldSource) { private int lastDocID; private boolean setDoc(int docID) throws IOException { if (docID < lastDocID) { throw new IllegalArgumentException( "docs out of order: lastDocID=" + lastDocID + " docID=" + docID); } if (docID > view.docID()) { lastDocID = docID; return docID == view.advance(docID); } else { return docID == view.docID(); } } @Override public double doubleVal(int doc) throws IOException { if (setDoc(doc)) { BytesRef bytes = view.binaryValue(); assert bytes.length > 0; return NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(bytes)); } else { return 0D; } } @Override public boolean exists(int doc) throws IOException { return setDoc(doc); } @Override public ValueFiller getValueFiller() { return new ValueFiller() { private final MutableValueDouble mval = new MutableValueDouble(); @Override public MutableValue getValue() { return mval; } @Override public void fillValue(int doc) throws IOException { if (setDoc(doc)) { mval.exists = true; mval.value = NumericUtils.sortableLongToDouble( LegacyNumericUtils.prefixCodedToLong(view.binaryValue())); } else { mval.exists = false; mval.value = 0D; } } }; } }; } }; }
From source file:org.apache.solr.schema.TrieFloatField.java
License:Apache License
@Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { return new SortedSetFieldSource(f.getName(), choice) { @Override// ww w. ja v a2 s.c o m public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { SortedSetFieldSource thisAsSortedSetFieldSource = this; // needed for nested anon class ref SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field); SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector); return new FloatDocValues(thisAsSortedSetFieldSource) { private int lastDocID; private boolean setDoc(int docID) throws IOException { if (docID < lastDocID) { throw new IllegalArgumentException( "docs out of order: lastDocID=" + lastDocID + " docID=" + docID); } if (docID > view.docID()) { return docID == view.advance(docID); } else { return docID == view.docID(); } } @Override public float floatVal(int doc) throws IOException { if (setDoc(doc)) { BytesRef bytes = view.binaryValue(); assert bytes.length > 0; return NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(bytes)); } else { return 0F; } } @Override public boolean exists(int doc) throws IOException { return setDoc(doc); } @Override public ValueFiller getValueFiller() { return new ValueFiller() { private final MutableValueFloat mval = new MutableValueFloat(); @Override public MutableValue getValue() { return mval; } @Override public void fillValue(int doc) throws IOException { if (setDoc(doc)) { mval.exists = true; mval.value = NumericUtils.sortableIntToFloat( LegacyNumericUtils.prefixCodedToInt(view.binaryValue())); } else { mval.exists = false; mval.value = 0F; } } }; } }; } }; }
From source file:org.apache.solr.schema.TrieIntField.java
License:Apache License
@Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { return new SortedSetFieldSource(f.getName(), choice) { @Override/*ww w. ja v a 2s. co m*/ public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { SortedSetFieldSource thisAsSortedSetFieldSource = this; // needed for nested anon class ref SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field); SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector); return new IntDocValues(thisAsSortedSetFieldSource) { private int lastDocID; private boolean setDoc(int docID) throws IOException { if (docID < lastDocID) { throw new IllegalArgumentException( "docs out of order: lastDocID=" + lastDocID + " docID=" + docID); } if (docID > view.docID()) { lastDocID = docID; return docID == view.advance(docID); } else { return docID == view.docID(); } } @Override public int intVal(int doc) throws IOException { if (setDoc(doc)) { BytesRef bytes = view.binaryValue(); assert bytes.length > 0; return LegacyNumericUtils.prefixCodedToInt(bytes); } else { return 0; } } @Override public boolean exists(int doc) throws IOException { return setDoc(doc); } @Override public ValueFiller getValueFiller() { return new ValueFiller() { private final MutableValueInt mval = new MutableValueInt(); @Override public MutableValue getValue() { return mval; } @Override public void fillValue(int doc) throws IOException { if (setDoc(doc)) { mval.exists = true; mval.value = LegacyNumericUtils.prefixCodedToInt(view.binaryValue()); } else { mval.exists = false; mval.value = 0; } } }; } }; } }; }
From source file:org.apache.solr.schema.TrieLongField.java
License:Apache License
@Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { return new SortedSetFieldSource(f.getName(), choice) { @Override/* w w w . j av a 2s .c o m*/ public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { SortedSetFieldSource thisAsSortedSetFieldSource = this; // needed for nested anon class ref SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field); SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector); return new LongDocValues(thisAsSortedSetFieldSource) { private int lastDocID; private boolean setDoc(int docID) throws IOException { if (docID < lastDocID) { throw new IllegalArgumentException( "docs out of order: lastDocID=" + lastDocID + " docID=" + docID); } if (docID > view.docID()) { lastDocID = docID; return docID == view.advance(docID); } else { return docID == view.docID(); } } @Override public long longVal(int doc) throws IOException { if (setDoc(doc)) { BytesRef bytes = view.binaryValue(); assert bytes.length > 0; return LegacyNumericUtils.prefixCodedToLong(bytes); } else { return 0L; } } @Override public boolean exists(int doc) throws IOException { return setDoc(doc); } @Override public ValueFiller getValueFiller() { return new ValueFiller() { private final MutableValueLong mval = new MutableValueLong(); @Override public MutableValue getValue() { return mval; } @Override public void fillValue(int doc) throws IOException { if (setDoc(doc)) { mval.exists = true; mval.value = LegacyNumericUtils.prefixCodedToLong(view.binaryValue()); } else { mval.exists = false; mval.value = 0L; } } }; } }; } }; }
From source file:org.apache.solr.search.join.BlockJoinFieldFacetAccumulator.java
License:Apache License
private boolean initSegmentData(String fieldName, LeafReaderContext leaf) throws IOException { segmentSSDV = DocValues.getSortedSet(leaf.reader(), fieldName); segmentAccums = ArrayUtil.grow(segmentAccums, (int) segmentSSDV.getValueCount() + 1);//+1 // zero counts, -1 parent Arrays.fill(segmentAccums, 0, (int) segmentSSDV.getValueCount() + 1, 0x00000000ffffffffL); segmentSDV = DocValues.unwrapSingleton(segmentSSDV); return segmentSSDV.getValueCount() != 0;// perhaps we need to count "missings"?? }
From source file:org.apache.solr.search.join.GraphTermsCollector.java
License:Apache License
@Override public void doSetNextReader(LeafReaderContext context) throws IOException { // Grab the updated doc values. docTermOrds = DocValues.getSortedSet(context.reader(), field); base = context.docBase;/*from w ww. jav a 2 s. com*/ baseInParent = context.docBaseInParent; }
From source file:org.apache.solr.uninverting.TestUninvertingReader.java
License:Apache License
/** Tests {@link Type#SORTED_SET_INTEGER} using Integer based fields, with and w/o precision steps */ public void testSortedSetIntegerManyValues() throws IOException { final Directory dir = newDirectory(); final IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null)); final LegacyFieldType NO_TRIE_TYPE = new LegacyFieldType(LegacyIntField.TYPE_NOT_STORED); NO_TRIE_TYPE.setNumericPrecisionStep(Integer.MAX_VALUE); final Map<String, Type> UNINVERT_MAP = new LinkedHashMap<String, Type>(); UNINVERT_MAP.put("notrie_single", Type.SORTED_SET_INTEGER); UNINVERT_MAP.put("notrie_multi", Type.SORTED_SET_INTEGER); UNINVERT_MAP.put("trie_single", Type.SORTED_SET_INTEGER); UNINVERT_MAP.put("trie_multi", Type.SORTED_SET_INTEGER); final Set<String> MULTI_VALUES = new LinkedHashSet<String>(); MULTI_VALUES.add("trie_multi"); MULTI_VALUES.add("notrie_multi"); final int NUM_DOCS = TestUtil.nextInt(random(), 200, 1500); final int MIN = TestUtil.nextInt(random(), 10, 100); final int MAX = MIN + TestUtil.nextInt(random(), 10, 100); final long EXPECTED_VALSET_SIZE = 1 + MAX - MIN; { // (at least) one doc should have every value, so that at least one segment has every value final Document doc = new Document(); for (int i = MIN; i <= MAX; i++) { doc.add(new LegacyIntField("trie_multi", i, Field.Store.NO)); doc.add(new LegacyIntField("notrie_multi", i, NO_TRIE_TYPE)); }//from w w w. j a v a2 s .co m iw.addDocument(doc); } // now add some more random docs (note: starting at i=1 because of previously added doc) for (int i = 1; i < NUM_DOCS; i++) { final Document doc = new Document(); if (0 != TestUtil.nextInt(random(), 0, 9)) { int val = TestUtil.nextInt(random(), MIN, MAX); doc.add(new LegacyIntField("trie_single", val, Field.Store.NO)); doc.add(new LegacyIntField("notrie_single", val, NO_TRIE_TYPE)); } if (0 != TestUtil.nextInt(random(), 0, 9)) { int numMulti = atLeast(1); while (0 < numMulti--) { int val = TestUtil.nextInt(random(), MIN, MAX); doc.add(new LegacyIntField("trie_multi", val, Field.Store.NO)); doc.add(new LegacyIntField("notrie_multi", val, NO_TRIE_TYPE)); } } iw.addDocument(doc); } iw.close(); final DirectoryReader ir = UninvertingReader.wrap(DirectoryReader.open(dir), UNINVERT_MAP); TestUtil.checkReader(ir); final int NUM_LEAVES = ir.leaves().size(); // check the leaves: no more then total set size for (LeafReaderContext rc : ir.leaves()) { final LeafReader ar = rc.reader(); for (String f : UNINVERT_MAP.keySet()) { final SortedSetDocValues v = DocValues.getSortedSet(ar, f); final long valSetSize = v.getValueCount(); assertTrue(f + ": Expected no more then " + EXPECTED_VALSET_SIZE + " values per segment, got " + valSetSize + " from: " + ar.toString(), valSetSize <= EXPECTED_VALSET_SIZE); if (1 == NUM_LEAVES && MULTI_VALUES.contains(f)) { // tighter check on multi fields in single segment index since we know one doc has all of them assertEquals( f + ": Single segment LeafReader's value set should have had exactly expected size", EXPECTED_VALSET_SIZE, valSetSize); } } } // check the composite of all leaves: exact expectation of set size final LeafReader composite = SlowCompositeReaderWrapper.wrap(ir); TestUtil.checkReader(composite); for (String f : MULTI_VALUES) { final SortedSetDocValues v = composite.getSortedSetDocValues(f); final long valSetSize = v.getValueCount(); assertEquals(f + ": Composite reader value set should have had exactly expected size", EXPECTED_VALSET_SIZE, valSetSize); } ir.close(); dir.close(); }
From source file:org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder.java
License:Apache License
private static boolean isSingleValued(IndexReader reader, SortField field) throws IOException { SortField.Type type = IndexSortConfig.getSortFieldType(field); for (LeafReaderContext context : reader.leaves()) { if (type == SortField.Type.STRING) { final SortedSetDocValues values = DocValues.getSortedSet(context.reader(), field.getField()); if (values.cost() > 0 && DocValues.unwrapSingleton(values) == null) { return false; }/* w w w .ja v a 2 s . c o m*/ } else { final SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), field.getField()); if (values.cost() > 0 && DocValues.unwrapSingleton(values) == null) { return false; } } } return true; }