List of usage examples for org.apache.lucene.queries.function FunctionValues longVal
public long longVal(int doc) throws IOException
From source file:org.apache.solr.analytics.util.valuesource.FilterFieldSource.java
License:Apache License
@Override public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { final FunctionValues vals = source.getValues(context, readerContext); return new FunctionValues() { @Override//from ww w . jav a 2 s. c o m public byte byteVal(int doc) { return vals.byteVal(doc); } @Override public short shortVal(int doc) { return vals.shortVal(doc); } @Override public float floatVal(int doc) { return vals.floatVal(doc); } @Override public int intVal(int doc) { return vals.intVal(doc); } @Override public long longVal(int doc) { return vals.longVal(doc); } @Override public double doubleVal(int doc) { return vals.doubleVal(doc); } @Override public String strVal(int doc) { return vals.strVal(doc); } @Override public Object objectVal(int doc) { return exists(doc) ? vals.objectVal(doc) : null; } @Override public boolean exists(int doc) { Object other = vals.objectVal(doc); return other != null && !missValue.equals(other); } @Override public String toString(int doc) { 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) { delegateFiller.fillValue(doc); mval.exists = exists(doc); } }; } }; }
From source file:org.apache.solr.schema.DocValuesTest.java
License:Apache License
public void testDocValues() throws IOException { assertU(adoc("id", "1")); commit();//from www . j av a 2s. c o m SolrCore core = h.getCoreInc(); try { final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true); final SolrIndexSearcher searcher = searcherRef.get(); try { final AtomicReader reader = searcher.getAtomicReader(); 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.getAtomicReader().leaves().get(0)); assertEquals(1f, values.floatVal(0), 0f); assertEquals(1f, values.objectVal(0)); values = intDv.getType().getValueSource(intDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0)); assertEquals(2, values.intVal(0)); assertEquals(2, values.objectVal(0)); values = doubleDv.getType().getValueSource(doubleDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0)); assertEquals(3d, values.doubleVal(0), 0d); assertEquals(3d, values.objectVal(0)); values = longDv.getType().getValueSource(longDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0)); assertEquals(4L, values.longVal(0)); assertEquals(4L, values.objectVal(0)); } finally { searcherRef.decref(); } } finally { core.close(); } }
From source file:org.apache.solr.search.function.SolrComparisonBoolFunction.java
License:Apache License
@Override public boolean compare(int doc, FunctionValues lhs, FunctionValues rhs) throws IOException { // TODO consider a separate FunctionValues impl, one for Long, one for Double // performs the safest possible numeric comparison, if both lhs and rhs are Longs, then // we perform a Long comparison to avoid the issues with precision when casting to doubles boolean lhsAnInt = (lhs instanceof LongDocValues || lhs instanceof IntDocValues); boolean rhsAnInt = (rhs instanceof LongDocValues || rhs instanceof IntDocValues); if (lhsAnInt && rhsAnInt) { return cmp.compare(Long.compare(lhs.longVal(doc), rhs.longVal(doc))); } else {//from ww w. ja va 2s .c om return cmp.compare(Double.compare(lhs.doubleVal(doc), rhs.doubleVal(doc))); } }
From source file:org.apache.solr.search.ValueSourceParser.java
License:Apache License
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { String first = fp.parseArg(); String second = fp.parseArg(); if (first == null) first = "NOW"; Date d1 = getDate(fp, first); ValueSource v1 = d1 == null ? getValueSource(fp, first) : null; Date d2 = getDate(fp, second); ValueSource v2 = d2 == null ? getValueSource(fp, second) : null; // d constant // v field // dd constant // dv subtract field from constant // vd subtract constant from field // vv subtract fields final long ms1 = (d1 == null) ? 0 : d1.getTime(); final long ms2 = (d2 == null) ? 0 : d2.getTime(); // "d,dd" handle both constant cases if (d1 != null && v2 == null) { return new LongConstValueSource(ms1 - ms2); }/* ww w. j a v a 2 s .c o m*/ // "v" just the date field if (v1 != null && v2 == null && d2 == null) { return v1; } // "dv" if (d1 != null && v2 != null) return new DualFloatFunction(new LongConstValueSource(ms1), v2) { @Override protected String name() { return "ms"; } @Override protected float func(int doc, FunctionValues aVals, FunctionValues bVals) { return ms1 - bVals.longVal(doc); } }; // "vd" if (v1 != null && d2 != null) return new DualFloatFunction(v1, new LongConstValueSource(ms2)) { @Override protected String name() { return "ms"; } @Override protected float func(int doc, FunctionValues aVals, FunctionValues bVals) { return aVals.longVal(doc) - ms2; } }; // "vv" if (v1 != null && v2 != null) return new DualFloatFunction(v1, v2) { @Override protected String name() { return "ms"; } @Override protected float func(int doc, FunctionValues aVals, FunctionValues bVals) { return aVals.longVal(doc) - bVals.longVal(doc); } }; return null; // shouldn't happen }
From source file:org.apache.solr.update.IndexFingerprint.java
License:Apache License
public static IndexFingerprint getFingerprint(SolrIndexSearcher searcher, LeafReaderContext ctx, Long maxVersion) throws IOException { SchemaField versionField = VersionInfo.getAndCheckVersionField(searcher.getSchema()); ValueSource vs = versionField.getType().getValueSource(versionField, null); Map funcContext = ValueSource.newContext(searcher); vs.createWeight(funcContext, searcher); IndexFingerprint f = new IndexFingerprint(); f.maxVersionSpecified = maxVersion;/*from w ww . j ava 2s .co m*/ f.maxDoc = ctx.reader().maxDoc(); f.numDocs = ctx.reader().numDocs(); int maxDoc = ctx.reader().maxDoc(); Bits liveDocs = ctx.reader().getLiveDocs(); FunctionValues fv = vs.getValues(funcContext, ctx); for (int doc = 0; doc < maxDoc; doc++) { if (liveDocs != null && !liveDocs.get(doc)) continue; long v = fv.longVal(doc); f.maxVersionEncountered = Math.max(v, f.maxVersionEncountered); if (v <= f.maxVersionSpecified) { f.maxInHash = Math.max(v, f.maxInHash); f.versionsHash += Hash.fmix64(v); f.numVersions++; } } return f; }
From source file:org.apache.solr.update.VersionInfo.java
License:Apache License
public Long getVersionFromIndex(BytesRef idBytes) { // TODO: we could cache much of this and invalidate during a commit. // TODO: most DocValues classes are threadsafe - expose which. RefCounted<SolrIndexSearcher> newestSearcher = ulog.uhandler.core.getRealtimeSearcher(); try {/*from w ww . j a v a 2s.c o m*/ SolrIndexSearcher searcher = newestSearcher.get(); long lookup = searcher.lookupId(idBytes); if (lookup < 0) return null; ValueSource vs = versionField.getType().getValueSource(versionField, null); Map context = ValueSource.newContext(searcher); vs.createWeight(context, searcher); FunctionValues fv = vs.getValues(context, searcher.getTopReaderContext().leaves().get((int) (lookup >> 32))); long ver = fv.longVal((int) lookup); return ver; } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading version from index", e); } finally { if (newestSearcher != null) { newestSearcher.decref(); } } }