Java Code Examples for org.apache.lucene.queries.function.ValueSource#getValues()

The following examples show how to use org.apache.lucene.queries.function.ValueSource#getValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VersionInfo.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the latest version from the index, searched by the given id (bytes) as seen from the realtime searcher.
 * Returns null if no document can be found in the index for the given id.
 */
@SuppressWarnings({"unchecked"})
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 {
    SolrIndexSearcher searcher = newestSearcher.get();
    long lookup = searcher.lookupId(idBytes);
    if (lookup < 0) return null; // this means the doc doesn't exist in the index yet

    ValueSource vs = versionField.getType().getValueSource(versionField, null);
    @SuppressWarnings({"rawtypes"})
    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();
    }
  }
}
 
Example 2
Source File: VersionInfo.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the highest version from the index, or 0L if no versions can be found in the index.
 */
@SuppressWarnings({"unchecked"})
public Long getMaxVersionFromIndex(IndexSearcher searcher) throws IOException {

  final String versionFieldName = versionField.getName();

  log.debug("Refreshing highest value of {} for {} version buckets from index", versionFieldName, buckets.length);
  // if indexed, then we have terms to get the max from
  if (versionField.indexed()) {
    if (versionField.getType().isPointField()) {
      return getMaxVersionFromIndexedPoints(searcher);
    } else {
      return getMaxVersionFromIndexedTerms(searcher);
    }
  }
  // else: not indexed, use docvalues via value source ...
  
  long maxVersionInIndex = 0L;
  ValueSource vs = versionField.getType().getValueSource(versionField, null);
  @SuppressWarnings({"rawtypes"})
  Map funcContext = ValueSource.newContext(searcher);
  vs.createWeight(funcContext, searcher);
  // TODO: multi-thread this
  for (LeafReaderContext ctx : searcher.getTopReaderContext().leaves()) {
    int maxDoc = ctx.reader().maxDoc();
    FunctionValues fv = vs.getValues(funcContext, ctx);
    for (int doc = 0; doc < maxDoc; doc++) {
      long v = fv.longVal(doc);
      maxVersionInIndex = Math.max(v, maxVersionInIndex);
    }
  }
  return maxVersionInIndex;
}
 
Example 3
Source File: DocBasedVersionConstraintsProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private static FunctionValues getFunctionValues(LeafReaderContext segmentContext,
                                        SchemaField field,
                                        SolrIndexSearcher searcher) throws IOException {
  ValueSource vs = field.getType().getValueSource(field, null);
  @SuppressWarnings({"rawtypes"})
  Map context = ValueSource.newContext(searcher);
  vs.createWeight(context, searcher);
  return vs.getValues(context, segmentContext);
}
 
Example 4
Source File: TestIndexSearcher.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private String getStringVal(SolrQueryRequest sqr, String field, int doc) throws IOException {
  SchemaField sf = sqr.getSchema().getField(field);
  ValueSource vs = sf.getType().getValueSource(sf, null);
  @SuppressWarnings({"rawtypes"})
  Map context = ValueSource.newContext(sqr.getSearcher());
  vs.createWeight(context, sqr.getSearcher());
  IndexReaderContext topReaderContext = sqr.getSearcher().getTopReaderContext();
  List<LeafReaderContext> leaves = topReaderContext.leaves();
  int idx = ReaderUtil.subIndex(doc, leaves);
  LeafReaderContext leaf = leaves.get(idx);
  FunctionValues vals = vs.getValues(context, leaf);
  return vals.strVal(doc-leaf.docBase);
}
 
Example 5
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes" })
private FunctionValues functionValues(NamedList initArgs, String arg) throws Exception {
  FunctionQParser fqp = mockFunctionQParser(arg);
  XJoinValueSourceParser vsp = new XJoinValueSourceParser();
  vsp.init(initArgs);
  ValueSource vs = vsp.parse(fqp);
  return vs.getValues(null, searcher.getSlowAtomicReader().getContext());
}
 
Example 6
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes" })
private FunctionValues functionValues(NamedList initArgs, String arg) throws Exception {
  FunctionQParser fqp = mockFunctionQParser(arg);
  XJoinValueSourceParser vsp = new XJoinValueSourceParser();
  vsp.init(initArgs);
  ValueSource vs = vsp.parse(fqp);
  return vs.getValues(null, searcher.getLeafReader().getContext());
}
 
Example 7
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes" })
private FunctionValues functionValues(NamedList initArgs, String arg) throws Exception {
  FunctionQParser fqp = mockFunctionQParser(arg);
  XJoinValueSourceParser vsp = new XJoinValueSourceParser();
  vsp.init(initArgs);
  ValueSource vs = vsp.parse(fqp);
  return vs.getValues(null, searcher.getAtomicReader().getContext());
}