List of usage examples for org.apache.lucene.queries.function.valuesource SortedSetFieldSource SortedSetFieldSource
public SortedSetFieldSource(String field, SortedSetSelector.Type selector)
From source file:org.apache.solr.schema.SortableTextField.java
License:Apache License
@Override public ValueSource getSingleValueSource(MultiValueSelector choice, SchemaField field, QParser parser) { // trivial base case if (!field.multiValued()) { // single value matches any selector return getValueSource(field, parser); }/*www . j ava 2 s . c om*/ // See LUCENE-6709 if (!field.hasDocValues()) { // type defaults to docValues=true, so error msg from perspective that // either type or field must have docValues="false" throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not select '" + choice.toString() + "' value from multivalued field (" + field.getName() + ") when docValues=\"false\", field: " + field.getName()); } SortedSetSelector.Type selectorType = choice.getSortedSetSelectorType(); if (null == selectorType) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, choice.toString() + " is not a supported option for picking a single value" + " from the multivalued field: " + field.getName() + " (type: " + this.getTypeName() + ")"); } return new SortedSetFieldSource(field.getName(), selectorType); }
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.j a va 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 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/*w w w. j av 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 va 2 s .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 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//from www .ja va2 s . 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 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; } } }; } }; } }; }