Search in sources :

Example 1 with MutableValue

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

the class GroupConverter method fromMutable.

static Collection<SearchGroup<BytesRef>> fromMutable(SchemaField field, Collection<SearchGroup<MutableValue>> values) {
    if (values == null) {
        return null;
    }
    FieldType fieldType = field.getType();
    List<SearchGroup<BytesRef>> result = new ArrayList<>(values.size());
    for (SearchGroup<MutableValue> original : values) {
        SearchGroup<BytesRef> converted = new SearchGroup<BytesRef>();
        converted.sortValues = original.sortValues;
        if (original.groupValue.exists) {
            BytesRefBuilder binary = new BytesRefBuilder();
            fieldType.readableToIndexed(original.groupValue.toString(), binary);
            converted.groupValue = binary.get();
        } else {
            converted.groupValue = null;
        }
        result.add(converted);
    }
    return result;
}
Also used : BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) SearchGroup(org.apache.lucene.search.grouping.SearchGroup) ArrayList(java.util.ArrayList) MutableValue(org.apache.lucene.util.mutable.MutableValue) BytesRef(org.apache.lucene.util.BytesRef) FieldType(org.apache.solr.schema.FieldType)

Example 2 with MutableValue

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

the class GroupConverter method toMutable.

static Collection<SearchGroup<MutableValue>> toMutable(SchemaField field, Collection<SearchGroup<BytesRef>> values) {
    FieldType fieldType = field.getType();
    List<SearchGroup<MutableValue>> result = new ArrayList<>(values.size());
    for (SearchGroup<BytesRef> original : values) {
        SearchGroup<MutableValue> converted = new SearchGroup<MutableValue>();
        // ?
        converted.sortValues = original.sortValues;
        NumberType type = fieldType.getNumberType();
        final MutableValue v;
        switch(type) {
            case INTEGER:
                MutableValueInt mutableInt = new MutableValueInt();
                if (original.groupValue == null) {
                    mutableInt.value = 0;
                    mutableInt.exists = false;
                } else {
                    mutableInt.value = (Integer) fieldType.toObject(field, original.groupValue);
                }
                v = mutableInt;
                break;
            case FLOAT:
                MutableValueFloat mutableFloat = new MutableValueFloat();
                if (original.groupValue == null) {
                    mutableFloat.value = 0;
                    mutableFloat.exists = false;
                } else {
                    mutableFloat.value = (Float) fieldType.toObject(field, original.groupValue);
                }
                v = mutableFloat;
                break;
            case DOUBLE:
                MutableValueDouble mutableDouble = new MutableValueDouble();
                if (original.groupValue == null) {
                    mutableDouble.value = 0;
                    mutableDouble.exists = false;
                } else {
                    mutableDouble.value = (Double) fieldType.toObject(field, original.groupValue);
                }
                v = mutableDouble;
                break;
            case LONG:
                MutableValueLong mutableLong = new MutableValueLong();
                if (original.groupValue == null) {
                    mutableLong.value = 0;
                    mutableLong.exists = false;
                } else {
                    mutableLong.value = (Long) fieldType.toObject(field, original.groupValue);
                }
                v = mutableLong;
                break;
            case DATE:
                MutableValueDate mutableDate = new MutableValueDate();
                if (original.groupValue == null) {
                    mutableDate.value = 0;
                    mutableDate.exists = false;
                } else {
                    mutableDate.value = ((Date) fieldType.toObject(field, original.groupValue)).getTime();
                }
                v = mutableDate;
                break;
            default:
                throw new AssertionError();
        }
        converted.groupValue = v;
        result.add(converted);
    }
    return result;
}
Also used : SearchGroup(org.apache.lucene.search.grouping.SearchGroup) ArrayList(java.util.ArrayList) MutableValue(org.apache.lucene.util.mutable.MutableValue) MutableValueLong(org.apache.lucene.util.mutable.MutableValueLong) FieldType(org.apache.solr.schema.FieldType) MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) NumberType(org.apache.solr.schema.NumberType) MutableValueFloat(org.apache.lucene.util.mutable.MutableValueFloat) MutableValueDouble(org.apache.lucene.util.mutable.MutableValueDouble) MutableValueInt(org.apache.lucene.util.mutable.MutableValueInt) BytesRef(org.apache.lucene.util.BytesRef)

Example 3 with MutableValue

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

the class TestGrouping method createSecondPassCollector.

// Basically converts searchGroups from MutableValue to BytesRef if grouping by ValueSource
@SuppressWarnings("unchecked")
private TopGroupsCollector<?> createSecondPassCollector(FirstPassGroupingCollector<?> firstPassGroupingCollector, String groupField, Collection<SearchGroup<BytesRef>> searchGroups, Sort groupSort, Sort sortWithinGroup, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException {
    if (firstPassGroupingCollector.getGroupSelector().getClass().isAssignableFrom(TermGroupSelector.class)) {
        GroupSelector<BytesRef> selector = (GroupSelector<BytesRef>) firstPassGroupingCollector.getGroupSelector();
        return new TopGroupsCollector<>(selector, searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
    } else {
        ValueSource vs = new BytesRefFieldSource(groupField);
        List<SearchGroup<MutableValue>> mvalSearchGroups = new ArrayList<>(searchGroups.size());
        for (SearchGroup<BytesRef> mergedTopGroup : searchGroups) {
            SearchGroup<MutableValue> sg = new SearchGroup<>();
            MutableValueStr groupValue = new MutableValueStr();
            if (mergedTopGroup.groupValue != null) {
                groupValue.value.copyBytes(mergedTopGroup.groupValue);
            } else {
                groupValue.exists = false;
            }
            sg.groupValue = groupValue;
            sg.sortValues = mergedTopGroup.sortValues;
            mvalSearchGroups.add(sg);
        }
        ValueSourceGroupSelector selector = new ValueSourceGroupSelector(vs, new HashMap<>());
        return new TopGroupsCollector<>(selector, mvalSearchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
    }
}
Also used : ArrayList(java.util.ArrayList) MutableValue(org.apache.lucene.util.mutable.MutableValue) BytesRefFieldSource(org.apache.lucene.queries.function.valuesource.BytesRefFieldSource) ValueSource(org.apache.lucene.queries.function.ValueSource) MutableValueStr(org.apache.lucene.util.mutable.MutableValueStr) BytesRef(org.apache.lucene.util.BytesRef)

Example 4 with MutableValue

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

the class FilterFieldSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals = source.getValues(context, readerContext);
    return new FunctionValues() {

        @Override
        public byte byteVal(int doc) throws IOException {
            return vals.byteVal(doc);
        }

        @Override
        public short shortVal(int doc) throws IOException {
            return vals.shortVal(doc);
        }

        @Override
        public float floatVal(int doc) throws IOException {
            return vals.floatVal(doc);
        }

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

        @Override
        public long longVal(int doc) throws IOException {
            return vals.longVal(doc);
        }

        @Override
        public double doubleVal(int doc) throws IOException {
            return vals.doubleVal(doc);
        }

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

        @Override
        public Object objectVal(int doc) throws IOException {
            return exists(doc) ? vals.objectVal(doc) : null;
        }

        @Override
        public boolean exists(int doc) throws IOException {
            Object other = vals.objectVal(doc);
            return other != null && !missValue.equals(other);
        }

        @Override
        public String toString(int doc) throws IOException {
            return NAME + '(' + vals.toString(doc) + ')';
        }

        @Override
        public ValueFiller getValueFiller() {
            return new ValueFiller() {

                private final ValueFiller delegateFiller = vals.getValueFiller();

                private final MutableValue mval = delegateFiller.getValue();

                @Override
                public MutableValue getValue() {
                    return mval;
                }

                @Override
                public void fillValue(int doc) throws IOException {
                    delegateFiller.fillValue(doc);
                    mval.exists = exists(doc);
                }
            };
        }
    };
}
Also used : FunctionValues(org.apache.lucene.queries.function.FunctionValues) MutableValue(org.apache.lucene.util.mutable.MutableValue)

Example 5 with MutableValue

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

the class GroupConverter method fromMutable.

static TopGroups<BytesRef> fromMutable(SchemaField field, TopGroups<MutableValue> values) {
    if (values == null) {
        return null;
    }
    FieldType fieldType = field.getType();
    @SuppressWarnings("unchecked") GroupDocs<BytesRef>[] groupDocs = new GroupDocs[values.groups.length];
    for (int i = 0; i < values.groups.length; i++) {
        GroupDocs<MutableValue> original = values.groups[i];
        final BytesRef groupValue;
        if (original.groupValue.exists) {
            BytesRefBuilder binary = new BytesRefBuilder();
            fieldType.readableToIndexed(original.groupValue.toString(), binary);
            groupValue = binary.get();
        } else {
            groupValue = null;
        }
        groupDocs[i] = new GroupDocs<BytesRef>(original.score, original.maxScore, original.totalHits, original.scoreDocs, groupValue, original.groupSortValues);
    }
    return new TopGroups<BytesRef>(values.groupSort, values.withinGroupSort, values.totalHitCount, values.totalGroupedHitCount, groupDocs, values.maxScore);
}
Also used : BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) MutableValue(org.apache.lucene.util.mutable.MutableValue) TopGroups(org.apache.lucene.search.grouping.TopGroups) GroupDocs(org.apache.lucene.search.grouping.GroupDocs) BytesRef(org.apache.lucene.util.BytesRef) FieldType(org.apache.solr.schema.FieldType)

Aggregations

MutableValue (org.apache.lucene.util.mutable.MutableValue)5 BytesRef (org.apache.lucene.util.BytesRef)4 ArrayList (java.util.ArrayList)3 FieldType (org.apache.solr.schema.FieldType)3 SearchGroup (org.apache.lucene.search.grouping.SearchGroup)2 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)2 FunctionValues (org.apache.lucene.queries.function.FunctionValues)1 ValueSource (org.apache.lucene.queries.function.ValueSource)1 BytesRefFieldSource (org.apache.lucene.queries.function.valuesource.BytesRefFieldSource)1 GroupDocs (org.apache.lucene.search.grouping.GroupDocs)1 TopGroups (org.apache.lucene.search.grouping.TopGroups)1 MutableValueDate (org.apache.lucene.util.mutable.MutableValueDate)1 MutableValueDouble (org.apache.lucene.util.mutable.MutableValueDouble)1 MutableValueFloat (org.apache.lucene.util.mutable.MutableValueFloat)1 MutableValueInt (org.apache.lucene.util.mutable.MutableValueInt)1 MutableValueLong (org.apache.lucene.util.mutable.MutableValueLong)1 MutableValueStr (org.apache.lucene.util.mutable.MutableValueStr)1 NumberType (org.apache.solr.schema.NumberType)1