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;
}
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;
}
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);
}
}
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);
}
};
}
};
}
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);
}
Aggregations