Search in sources :

Example 6 with MutableValueInt

use of org.apache.lucene.util.mutable.MutableValueInt in project lucene-solr by apache.

the class IntDocValues method getValueFiller.

@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 {
            mval.value = intVal(doc);
            mval.exists = exists(doc);
        }
    };
}
Also used : MutableValueInt(org.apache.lucene.util.mutable.MutableValueInt)

Example 7 with MutableValueInt

use of org.apache.lucene.util.mutable.MutableValueInt in project lucene-solr by apache.

the class IntFieldSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final NumericDocValues arr = getNumericDocValues(context, readerContext);
    return new IntDocValues(this) {

        int lastDocID;

        private int getValueForDoc(int doc) throws IOException {
            if (doc < lastDocID) {
                throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc);
            }
            lastDocID = doc;
            int curDocID = arr.docID();
            if (doc > curDocID) {
                curDocID = arr.advance(doc);
            }
            if (doc == curDocID) {
                return (int) arr.longValue();
            } else {
                return 0;
            }
        }

        @Override
        public int intVal(int doc) throws IOException {
            return getValueForDoc(doc);
        }

        @Override
        public String strVal(int doc) throws IOException {
            return Integer.toString(intVal(doc));
        }

        @Override
        public boolean exists(int doc) throws IOException {
            getValueForDoc(doc);
            return arr.docID() == 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 {
                    mval.value = getValueForDoc(doc);
                    mval.exists = arr.docID() == doc;
                }
            };
        }
    };
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) MutableValueInt(org.apache.lucene.util.mutable.MutableValueInt) IntDocValues(org.apache.lucene.queries.function.docvalues.IntDocValues)

Example 8 with MutableValueInt

use of org.apache.lucene.util.mutable.MutableValueInt in project lucene-solr by apache.

the class OrdFieldSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final int off = readerContext.docBase;
    final LeafReader r;
    Object o = context.get("searcher");
    if (o instanceof SolrIndexSearcher) {
        SolrIndexSearcher is = (SolrIndexSearcher) o;
        SchemaField sf = is.getSchema().getFieldOrNull(field);
        if (sf != null && sf.hasDocValues() == false && sf.multiValued() == false && sf.getType().getNumberType() != null) {
            // it's a single-valued numeric field: we must currently create insanity :(
            List<LeafReaderContext> leaves = is.getIndexReader().leaves();
            LeafReader[] insaneLeaves = new LeafReader[leaves.size()];
            int upto = 0;
            for (LeafReaderContext raw : leaves) {
                insaneLeaves[upto++] = Insanity.wrapInsanity(raw.reader(), field);
            }
            r = SlowCompositeReaderWrapper.wrap(new MultiReader(insaneLeaves));
        } else {
            // reuse ordinalmap
            r = ((SolrIndexSearcher) o).getSlowAtomicReader();
        }
    } else {
        IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
        r = SlowCompositeReaderWrapper.wrap(topReader);
    }
    // if it's e.g. tokenized/multivalued, emulate old behavior of single-valued fc
    final SortedDocValues sindex = SortedSetSelector.wrap(DocValues.getSortedSet(r, field), SortedSetSelector.Type.MIN);
    return new IntDocValues(this) {

        private int lastDocID;

        private int getOrdForDoc(int docID) throws IOException {
            if (docID < lastDocID) {
                throw new IllegalArgumentException("docs out of order: lastDocID=" + lastDocID + " docID=" + docID);
            }
            if (docID > sindex.docID()) {
                sindex.advance(docID);
            }
            if (docID == sindex.docID()) {
                return sindex.ordValue();
            } else {
                return -1;
            }
        }

        protected String toTerm(String readableValue) {
            return readableValue;
        }

        @Override
        public int intVal(int doc) throws IOException {
            return getOrdForDoc(doc + off);
        }

        @Override
        public int ordVal(int doc) throws IOException {
            return getOrdForDoc(doc + off);
        }

        @Override
        public int numOrd() {
            return sindex.getValueCount();
        }

        @Override
        public boolean exists(int doc) throws IOException {
            return getOrdForDoc(doc + off) != 0;
        }

        @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 {
                    mval.value = getOrdForDoc(doc);
                    mval.exists = mval.value != 0;
                }
            };
        }
    };
}
Also used : LeafReader(org.apache.lucene.index.LeafReader) MultiReader(org.apache.lucene.index.MultiReader) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SortedDocValues(org.apache.lucene.index.SortedDocValues) SchemaField(org.apache.solr.schema.SchemaField) IndexReader(org.apache.lucene.index.IndexReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) MutableValueInt(org.apache.lucene.util.mutable.MutableValueInt) IntDocValues(org.apache.lucene.queries.function.docvalues.IntDocValues)

Example 9 with MutableValueInt

use of org.apache.lucene.util.mutable.MutableValueInt in project crate by crate.

the class CopyOnWriteHashMap method copyAndPut.

/**
 * Associate <code>key</code> with <code>value</code> and return a new copy
 * of the hash table. The current hash table is not modified.
 */
public CopyOnWriteHashMap<K, V> copyAndPut(K key, V value) {
    if (key == null) {
        throw new IllegalArgumentException("null keys are not supported");
    }
    if (value == null) {
        throw new IllegalArgumentException("null values are not supported");
    }
    final int hash = key.hashCode();
    final MutableValueInt newValue = new MutableValueInt();
    final InnerNode<K, V> newRoot = root.put(key, hash, TOTAL_HASH_BITS, value, newValue);
    final int newSize = size + newValue.value;
    return new CopyOnWriteHashMap<>(newRoot, newSize);
}
Also used : MutableValueInt(org.apache.lucene.util.mutable.MutableValueInt)

Aggregations

MutableValueInt (org.apache.lucene.util.mutable.MutableValueInt)9 IntDocValues (org.apache.lucene.queries.function.docvalues.IntDocValues)4 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 SortedDocValues (org.apache.lucene.index.SortedDocValues)2 BytesRef (org.apache.lucene.util.BytesRef)2 HashMap (java.util.HashMap)1 List (java.util.List)1 IndexReader (org.apache.lucene.index.IndexReader)1 LeafReader (org.apache.lucene.index.LeafReader)1 MultiReader (org.apache.lucene.index.MultiReader)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1 ValueSourceScorer (org.apache.lucene.queries.function.ValueSourceScorer)1 SortedSetFieldSource (org.apache.lucene.queries.function.valuesource.SortedSetFieldSource)1 SearchGroup (org.apache.lucene.search.grouping.SearchGroup)1 SentinelIntSet (org.apache.lucene.util.SentinelIntSet)1 MutableValue (org.apache.lucene.util.mutable.MutableValue)1 MutableValueDate (org.apache.lucene.util.mutable.MutableValueDate)1