@Override public Query getRangeQuery( QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) { Analyzer multiAnalyzer = getMultiTermAnalyzer(); BytesRef lower = analyzeMultiTerm(field.getName(), part1, multiAnalyzer); BytesRef upper = analyzeMultiTerm(field.getName(), part2, multiAnalyzer); return new TermRangeQuery(field.getName(), lower, upper, minInclusive, maxInclusive); }
@Override public SortField getSortField(SchemaField field, boolean top) { field.checkSortability(); Object missingValue = null; boolean sortMissingLast = field.sortMissingLast(); boolean sortMissingFirst = field.sortMissingFirst(); switch (type) { case INTEGER: if (sortMissingLast) { missingValue = top ? Integer.MIN_VALUE : Integer.MAX_VALUE; } else if (sortMissingFirst) { missingValue = top ? Integer.MAX_VALUE : Integer.MIN_VALUE; } return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_INT_PARSER, top) .setMissingValue(missingValue); case FLOAT: if (sortMissingLast) { missingValue = top ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY; } else if (sortMissingFirst) { missingValue = top ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY; } return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_FLOAT_PARSER, top) .setMissingValue(missingValue); case DATE: // fallthrough case LONG: if (sortMissingLast) { missingValue = top ? Long.MIN_VALUE : Long.MAX_VALUE; } else if (sortMissingFirst) { missingValue = top ? Long.MAX_VALUE : Long.MIN_VALUE; } return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER, top) .setMissingValue(missingValue); case DOUBLE: if (sortMissingLast) { missingValue = top ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } else if (sortMissingFirst) { missingValue = top ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; } return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_DOUBLE_PARSER, top) .setMissingValue(missingValue); default: throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + field.name); } }
@Override public ValueSource getValueSource(SchemaField field, QParser qparser) { field.checkFieldCacheSource(qparser); switch (type) { case INTEGER: return new IntFieldSource(field.getName(), FieldCache.NUMERIC_UTILS_INT_PARSER); case FLOAT: return new FloatFieldSource(field.getName(), FieldCache.NUMERIC_UTILS_FLOAT_PARSER); case DATE: return new TrieDateFieldSource(field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER); case LONG: return new LongFieldSource(field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER); case DOUBLE: return new DoubleFieldSource(field.getName(), FieldCache.NUMERIC_UTILS_DOUBLE_PARSER); default: throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + field.name); } }
@Override public Fieldable createField(SchemaField field, String externalVal, float boost) { boolean indexed = field.indexed(); boolean stored = field.stored(); if (!indexed && !stored) { if (log.isTraceEnabled()) log.trace("Ignoring unindexed/unstored field: " + field); return null; } final NumericField f = new NumericField( field.getName(), precisionStep, stored ? Field.Store.YES : Field.Store.NO, indexed); switch (type) { case INTEGER: f.setIntValue(Integer.parseInt(externalVal)); break; case FLOAT: f.setFloatValue(Float.parseFloat(externalVal)); break; case LONG: f.setLongValue(Long.parseLong(externalVal)); break; case DOUBLE: f.setDoubleValue(Double.parseDouble(externalVal)); break; case DATE: f.setLongValue(dateField.parseMath(null, externalVal).getTime()); break; default: throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type); } f.setOmitNorms(field.omitNorms()); f.setIndexOptions(getIndexOptions(field, externalVal)); f.setBoost(boost); return f; }
@Override public ValueSource getValueSource(SchemaField field) { return new RandomValueSource(field.getName()); }
@Override public SortField getSortField(SchemaField field, boolean reverse) { return new SortField(field.getName(), randomComparatorSource, reverse); }
@Override public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) { return parseFieldQuery(parser, getQueryAnalyzer(), field.getName(), externalVal); }
@Override public Query getRangeQuery( QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) { int ps = precisionStep; Query query = null; switch (type) { case INTEGER: query = NumericRangeQuery.newIntRange( field.getName(), ps, min == null ? null : Integer.parseInt(min), max == null ? null : Integer.parseInt(max), minInclusive, maxInclusive); break; case FLOAT: query = NumericRangeQuery.newFloatRange( field.getName(), ps, min == null ? null : Float.parseFloat(min), max == null ? null : Float.parseFloat(max), minInclusive, maxInclusive); break; case LONG: query = NumericRangeQuery.newLongRange( field.getName(), ps, min == null ? null : Long.parseLong(min), max == null ? null : Long.parseLong(max), minInclusive, maxInclusive); break; case DOUBLE: query = NumericRangeQuery.newDoubleRange( field.getName(), ps, min == null ? null : Double.parseDouble(min), max == null ? null : Double.parseDouble(max), minInclusive, maxInclusive); break; case DATE: query = NumericRangeQuery.newLongRange( field.getName(), ps, min == null ? null : dateField.parseMath(null, min).getTime(), max == null ? null : dateField.parseMath(null, max).getTime(), minInclusive, maxInclusive); break; default: throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field"); } return query; }