Java Code Examples for org.apache.lucene.queries.function.FunctionValues#strVal()

The following examples show how to use org.apache.lucene.queries.function.FunctionValues#strVal() . 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: ConcatStringFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected String func(int doc, FunctionValues[] valsArr) throws IOException {
  StringBuilder sb = new StringBuilder();
  for (FunctionValues val : valsArr) {
    String v = val.strVal(doc);
    if(v == null){
      return null;
    } else {
      sb.append(v);
    }
  }
  return sb.toString();
}
 
Example 2
Source File: GeohashHaversineFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected double distance(int doc, FunctionValues gh1DV, FunctionValues gh2DV) throws IOException {
  double result = 0;
  String h1 = gh1DV.strVal(doc);
  String h2 = gh2DV.strVal(doc);
  if (h1 != null && h2 != null && h1.equals(h2) == false){
    //TODO: If one of the hashes is a literal value source, seems like we could cache it
    //and avoid decoding every time
    Point p1 = GeohashUtils.decode(h1,ctx);
    Point p2 = GeohashUtils.decode(h2,ctx);
    result = ctx.getDistCalc().distance(p1, p2) * degreesToDist;
  } else if (h1 == null || h2 == null){
    result = Double.MAX_VALUE;
  }
  return result;
}
 
Example 3
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);
}