Example usage for org.apache.lucene.queries.function ValueSource createWeight

List of usage examples for org.apache.lucene.queries.function ValueSource createWeight

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function ValueSource createWeight.

Prototype

public void createWeight(Map context, IndexSearcher searcher) throws IOException 

Source Link

Document

Implementations should propagate createWeight to sub-ValueSources which can optionally store weight info in the context.

Usage

From source file:org.apache.solr.analytics.util.valuesource.MultiDoubleFunction.java

License:Apache License

@Override
public void createWeight(Map context, IndexSearcher searcher) throws IOException {
    for (ValueSource source : sources)
        source.createWeight(context, searcher);
}

From source file:org.apache.solr.search.TestIndexSearcher.java

License:Apache License

private String getStringVal(SolrQueryRequest sqr, String field, int doc) throws IOException {
    SchemaField sf = sqr.getSchema().getField(field);
    ValueSource vs = sf.getType().getValueSource(sf, null);
    Map context = ValueSource.newContext(sqr.getSearcher());
    vs.createWeight(context, sqr.getSearcher());
    IndexReaderContext topReaderContext = sqr.getSearcher().getTopReaderContext();
    List<AtomicReaderContext> leaves = topReaderContext.leaves();
    int idx = ReaderUtil.subIndex(doc, leaves);
    AtomicReaderContext leaf = leaves.get(idx);
    FunctionValues vals = vs.getValues(context, leaf);
    return vals.strVal(doc - leaf.docBase);
}

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;//  ww  w.ja  v  a2  s. c  o  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 {/* www  .  j av a 2 s .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();
        }
    }
}