public void testDocValues() throws IOException { assertU(adoc("id", "1")); assertU(commit()); try (SolrCore core = h.getCoreInc()) { final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true); final SolrIndexSearcher searcher = searcherRef.get(); try { final LeafReader reader = searcher.getLeafReader(); assertEquals(1, reader.numDocs()); final FieldInfos infos = reader.getFieldInfos(); assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("floatdv").getDocValuesType()); assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("intdv").getDocValuesType()); assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("doubledv").getDocValuesType()); assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("longdv").getDocValuesType()); assertEquals(DocValuesType.SORTED, infos.fieldInfo("stringdv").getDocValuesType()); assertEquals((long) Float.floatToIntBits(1), reader.getNumericDocValues("floatdv").get(0)); assertEquals(2L, reader.getNumericDocValues("intdv").get(0)); assertEquals(Double.doubleToLongBits(3), reader.getNumericDocValues("doubledv").get(0)); assertEquals(4L, reader.getNumericDocValues("longdv").get(0)); final IndexSchema schema = core.getLatestSchema(); final SchemaField floatDv = schema.getField("floatdv"); final SchemaField intDv = schema.getField("intdv"); final SchemaField doubleDv = schema.getField("doubledv"); final SchemaField longDv = schema.getField("longdv"); FunctionValues values = floatDv .getType() .getValueSource(floatDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(1f, values.floatVal(0), 0f); assertEquals(1f, values.objectVal(0)); values = intDv .getType() .getValueSource(intDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(2, values.intVal(0)); assertEquals(2, values.objectVal(0)); values = doubleDv .getType() .getValueSource(doubleDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(3d, values.doubleVal(0), 0d); assertEquals(3d, values.objectVal(0)); values = longDv .getType() .getValueSource(longDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(4L, values.longVal(0)); assertEquals(4L, values.objectVal(0)); } finally { searcherRef.decref(); } } }
// Handle additional arguments... protected void setArgs(IndexSchema schema, Map<String, String> args) { // default to STORED, INDEXED, OMIT_TF_POSITIONS and MULTIVALUED depending on schema version properties = (STORED | INDEXED); float schemaVersion = schema.getVersion(); if (schemaVersion < 1.1f) properties |= MULTIVALUED; if (schemaVersion > 1.1f) properties |= OMIT_TF_POSITIONS; if (schemaVersion < 1.3) { args.remove("compressThreshold"); } if (schemaVersion >= 1.6f) properties |= USE_DOCVALUES_AS_STORED; this.args = Collections.unmodifiableMap(args); Map<String, String> initArgs = new HashMap<>(args); initArgs.remove(CLASS_NAME); // consume the class arg trueProperties = FieldProperties.parseProperties(initArgs, true, false); falseProperties = FieldProperties.parseProperties(initArgs, false, false); properties &= ~falseProperties; properties |= trueProperties; for (String prop : FieldProperties.propertyNames) initArgs.remove(prop); init(schema, initArgs); String positionInc = initArgs.get(POSITION_INCREMENT_GAP); if (positionInc != null) { Analyzer analyzer = getIndexAnalyzer(); if (analyzer instanceof SolrAnalyzer) { ((SolrAnalyzer) analyzer).setPositionIncrementGap(Integer.parseInt(positionInc)); } else { throw new RuntimeException( "Can't set " + POSITION_INCREMENT_GAP + " on custom analyzer " + analyzer.getClass()); } analyzer = getQueryAnalyzer(); if (analyzer instanceof SolrAnalyzer) { ((SolrAnalyzer) analyzer).setPositionIncrementGap(Integer.parseInt(positionInc)); } else { throw new RuntimeException( "Can't set " + POSITION_INCREMENT_GAP + " on custom analyzer " + analyzer.getClass()); } initArgs.remove(POSITION_INCREMENT_GAP); } this.postingsFormat = initArgs.remove(POSTINGS_FORMAT); this.docValuesFormat = initArgs.remove(DOC_VALUES_FORMAT); if (initArgs.size() > 0) { throw new RuntimeException( "schema fieldtype " + typeName + "(" + this.getClass().getName() + ")" + " invalid arguments:" + initArgs); } }
@Override protected void init(IndexSchema schema, Map<String, String> args) { properties |= TOKENIZED; if (schema.getVersion() > 1.1F && // only override if it's not explicitly true 0 == (trueProperties & OMIT_TF_POSITIONS)) { properties &= ~OMIT_TF_POSITIONS; } if (schema.getVersion() > 1.3F) { autoGeneratePhraseQueries = false; } else { autoGeneratePhraseQueries = true; } String autoGeneratePhraseQueriesStr = args.remove("autoGeneratePhraseQueries"); if (autoGeneratePhraseQueriesStr != null) autoGeneratePhraseQueries = Boolean.parseBoolean(autoGeneratePhraseQueriesStr); super.init(schema, args); }
public void inform(IndexSchema schema) { FieldType doubleType = schema.getFieldTypeByName(doubleFieldName); if (doubleType == null) { throw new RuntimeException("Can not find double: " + doubleFieldName); } if (!(doubleType instanceof TrieDoubleField)) { throw new RuntimeException("double must be TrieDoubleField: " + doubleType); } // Just set these, delegate everything else to the field type int p = (INDEXED | TOKENIZED | OMIT_NORMS | OMIT_TF_POSITIONS); List<SchemaField> fields = new ArrayList<SchemaField>(schema.getFields().values()); for (SchemaField sf : fields) { if (sf.getType() == this) { String name = sf.getName(); schema .getFields() .put( name + TwoDoublesFieldInfo.SUFFIX_X, new SchemaField(name + TwoDoublesFieldInfo.SUFFIX_X, doubleType, p, null)); schema .getFields() .put( name + TwoDoublesFieldInfo.SUFFIX_Y, new SchemaField(name + TwoDoublesFieldInfo.SUFFIX_Y, doubleType, p, null)); } } TrieField df = (TrieField) doubleType; NumericFieldInfo info = new NumericFieldInfo(); info.setPrecisionStep(df.getPrecisionStep()); info.store = true; // TODO properties &... spatialStrategy = new TwoDoublesStrategy(ctx, info, FieldCache.NUMERIC_UTILS_DOUBLE_PARSER); spatialStrategy.setIgnoreIncompatibleGeometry(ignoreIncompatibleGeometry); }
protected void init(IndexSchema schema, Map<String, String> args) { restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST); String ftypeS = getArg("valType", args); if (ftypeS != null) { ftype = schema.getFieldTypes().get(ftypeS); if (ftype == null || !(ftype instanceof FloatField)) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Only float (FloatField) is currently supported as external field type. got " + ftypeS); } } keyFieldName = args.remove("keyField"); String defValS = args.remove("defVal"); defVal = defValS == null ? 0 : Float.parseFloat(defValS); this.schema = schema; }
public ValueSource getValueSource(SchemaField field, QParser parser) { // default key field to unique key SchemaField keyField = keyFieldName == null ? schema.getUniqueKeyField() : schema.getField(keyFieldName); return new FileFloatSource(field, keyField, defVal, parser); }