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

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

Introduction

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

Prototype

public static Map newContext(IndexSearcher searcher) 

Source Link

Document

Returns a new non-threadsafe context map.

Usage

From source file:alba.solr.core.DynamicQuery.java

License:Apache License

@Override
public DelegatingCollector getFilterCollector(IndexSearcher idxS) {

    Map fcontext = ValueSource.newContext(idxS);

    DynamicDelegatingCollector ddg = new DynamicDelegatingCollector(this, fcontext, function, functionParams,
            functionResultsCache);/*from  w ww . j  a  va2 s.  c om*/

    ddg.setFunction(function, functionParams, functionParamValueSource);
    return ddg;

}

From source file:org.apache.solr.response.transform.ValueSourceAugmenter.java

License:Apache License

@Override
public void setContext(TransformContext context) {
    try {/*  w w w . j  a  va2 s.  c o  m*/
        IndexReader reader = qparser.getReq().getSearcher().getIndexReader();
        readerContexts = reader.leaves();
        docValuesArr = new FunctionValues[readerContexts.size()];

        searcher = qparser.getReq().getSearcher();
        fcontext = ValueSource.newContext(searcher);
        this.valueSource.createWeight(fcontext, searcher);
    } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
    }
}

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

License:Apache License

@Override
public DelegatingCollector getFilterCollector(IndexSearcher searcher) {
    Map fcontext = ValueSource.newContext(searcher);
    return new FunctionRangeCollector(fcontext);
}

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;/*  w  ww. j  ava 2  s.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  w w .  j a va2s .c  om
        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();
        }
    }
}

From source file:org.opensextant.solrtexttagger.TaggerRequestHandler.java

License:Open Source License

public ValueSourceAccessor(IndexSearcher searcher, ValueSource valueSource) {
    readerContexts = searcher.getIndexReader().leaves();
    this.valueSource = valueSource;
    docValuesArr = new FunctionValues[readerContexts.size()];
    fContext = ValueSource.newContext(searcher);
}

From source file:org.vootoo.search.CollectorFilterQuery.java

License:Apache License

@Override
public DelegatingCollector getFilterCollector(IndexSearcher searcher) {
    @SuppressWarnings("rawtypes")
    Map fcontext = ValueSource.newContext(searcher);
    return new FilterCollector(valueSourceFilter.getCollectorFilterable(), fcontext);
}