org.apache.solr.search.FunctionQParser Java Examples

The following examples show how to use org.apache.solr.search.FunctionQParser. 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: GeoDistValueSourceParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
  String sfield = fp.getParam(SpatialParams.FIELD);
  if (sfield == null) return null;
  SchemaField sf = fp.getReq().getSchema().getField(sfield);
  FieldType type = sf.getType();
  if (type instanceof AbstractSpatialFieldType) {
    @SuppressWarnings({"rawtypes"})
    AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type;
    return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield), asft.getDistanceUnits());
  }
  ValueSource vs = type.getValueSource(sf, fp);
  if (vs instanceof MultiValueSource) {
    return (MultiValueSource)vs;
  }
  throw new SyntaxError("Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf);
}
 
Example #2
Source File: PercentileAgg.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  List<Double> percentiles = new ArrayList<>();
  ValueSource vs = fp.parseValueSource();
  while (fp.hasMoreArguments()) {
    double val = fp.parseDouble();
    if (val<0 || val>100) {
      throw new SyntaxError("requested percentile must be between 0 and 100.  got " + val);
    }
    percentiles.add(val);
  }

  if (percentiles.isEmpty()) {
    throw new SyntaxError("expected percentile(valsource,percent1[,percent2]*)  EXAMPLE:percentile(myfield,50)");
  }

  return new PercentileAgg(vs, percentiles);
}
 
Example #3
Source File: NvlValueSourceParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  ValueSource source = fp.parseValueSource();
  final float nvl = fp.parseFloat();

  return new SimpleFloatFunction(source) {
    @Override
  protected String name() {
      return "nvl";
    }

    @Override
    protected float func(int doc, FunctionValues vals) throws IOException {
      float v = vals.floatVal(doc);
      if (v == nvlFloatValue) {
        return nvl;
      } else {
        return v;
      }
    }
  };
}
 
Example #4
Source File: LireValueSourceParser.java    From liresolr with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    String field=fp.parseArg();                          // eg. cl_hi
    String featureString = fp.parseArg();
    // System.out.println(featureString);
    byte[] hist= Base64.decodeBase64(featureString);     // eg. FQY5DhMYDg0ODg0PEBEPDg4ODg8QEgsgEBAQEBAgEBAQEBA=
    double maxDistance = Double.MAX_VALUE;
    if (fp.hasMoreArguments()) {                           // if there is a third argument, it's the max value to return if there is none. Note the query cache is not updated upon parameter change.
        maxDistance = Double.parseDouble(fp.parseArg());
    }
    return new LireValueSource(field, hist, maxDistance);
}
 
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.getAtomicReader().getContext());
}
 
Example #6
Source File: XJoinValueSourceParser.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Provide a ValueSource for external process results, which are obtained from the
 * request context (having been placed there by XJoinSearchComponent).
 */
@Override
public ValueSource parse(FunctionQParser fqp) throws SyntaxError {
  String componentName = this.componentName != null ? this.componentName : fqp.parseArg();
  String attribute = this.attribute != null ? this.attribute : fqp.parseArg();
  
  XJoinSearchComponent xJoin = (XJoinSearchComponent)fqp.getReq().getCore().getSearchComponent(componentName);
  String joinField = xJoin.getJoinField();
  XJoinResults<?> results = (XJoinResults<?>)fqp.getReq().getContext().get(xJoin.getResultsTag());
  if (results == null) {
    throw new RuntimeException("No xjoin results in request context");
  }
  return new XJoinValueSource(joinField, results, attribute);
}
 
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.getLeafReader().getContext());
}
 
Example #8
Source File: XJoinValueSourceParser.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Provide a ValueSource for external process results, which are obtained from the
 * request context (having been placed there by XJoinSearchComponent).
 */
@Override
public ValueSource parse(FunctionQParser fqp) throws SyntaxError {
  String componentName = this.componentName != null ? this.componentName : fqp.parseArg();
  String attribute = this.attribute != null ? this.attribute : fqp.parseArg();
  
  XJoinSearchComponent xJoin = (XJoinSearchComponent)fqp.getReq().getCore().getSearchComponent(componentName);
  String joinField = xJoin.getJoinField();
  XJoinResults<?> results = (XJoinResults<?>)fqp.getReq().getContext().get(xJoin.getResultsTag());
  if (results == null) {
    throw new RuntimeException("No xjoin results in request context");
  }
  return new XJoinValueSource(joinField, results, attribute);
}
 
Example #9
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 #10
Source File: XJoinValueSourceParser.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Provide a ValueSource for external process results, which are obtained from the
 * request context (having been placed there by XJoinSearchComponent).
 */
@Override
public ValueSource parse(FunctionQParser fqp) throws SyntaxError {
  String componentName = this.componentName != null ? this.componentName : fqp.parseArg();
  String attribute = this.attribute != null ? this.attribute : fqp.parseArg();
  
  XJoinSearchComponent xJoin = (XJoinSearchComponent)fqp.getReq().getCore().getSearchComponent(componentName);
  String joinField = xJoin.getJoinField();
  XJoinResults<?> results = (XJoinResults<?>)fqp.getReq().getContext().get(xJoin.getResultsTag());
  if (results == null) {
    throw new RuntimeException("No xjoin results in request context");
  }
  return new XJoinValueSource(joinField, results, attribute);
}
 
Example #11
Source File: CountUsageValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  String key = fp.parseArg();
  double val = fp.parseDouble();
  
  AtomicInteger counter = new AtomicInteger();
  if (null != counters.putIfAbsent(key, counter)) {
    throw new IllegalArgumentException("Key has already been used: " + key);
  } 
  return new CountDocsValueSource(counter, val);
}
 
Example #12
Source File: DebugAgg.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  parses.incrementAndGet();
  final String what = fp.hasMoreArguments() ? fp.parseId() : "wrap";

  switch (what) {
    case "wrap": return new DebugAgg(fp);
    case "numShards": return new DebugAggNumShards();
    default: /* No-Op */
  }
  throw new RuntimeException("No idea what to do with " + what);
}
 
Example #13
Source File: ChildFieldValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  
  final String sortFieldName = fp.parseArg();
  final Query query;
  if (fp.hasMoreArguments()){
    query = fp.parseNestedQuery();
  } else {
    query = fp.subQuery(fp.getParam(CommonParams.Q), null).getQuery();
  }
  
  BitSetProducer parentFilter;
  BitSetProducer childFilter;
  SchemaField sf;
  try {
    AllParentsAware bjQ;
    if (!(query instanceof AllParentsAware)) {
      throw new SyntaxError("expect a reference to block join query "+
            AllParentsAware.class.getSimpleName()+" in "+fp.getString());
    }
    bjQ = (AllParentsAware) query;
    
    parentFilter = BlockJoinParentQParser.getCachedBitSetProducer(fp.getReq(), bjQ.getParentQuery());
    childFilter = BlockJoinParentQParser.getCachedBitSetProducer(fp.getReq(), bjQ.getChildQuery());

    if (sortFieldName==null || sortFieldName.equals("")) {
      throw new SyntaxError ("field is omitted in "+fp.getString());
    }
    
    sf = fp.getReq().getSchema().getFieldOrNull(sortFieldName);
    if (null == sf) {
      throw new SyntaxError
        (NAME+" sort param field \""+ sortFieldName+"\" can't be found in schema");
    }
  } catch (SyntaxError e) {
    log.error("can't parse {}", fp.getString(), e);
    throw e;
  }
  return new BlockJoinSortFieldValueSource(childFilter, parentFilter, sf);
}
 
Example #14
Source File: FacetParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Parses simple strings like "avg(x)" in the context of optional local params (may be null) */
private AggValueSource parseStatWithParams(String key, SolrParams localparams, String stat) throws SyntaxError {
  SolrQueryRequest req = getSolrRequest();
  FunctionQParser parser = new FunctionQParser(stat, localparams, req.getParams(), req);
  AggValueSource agg = parser.parseAgg(FunctionQParser.FLAG_DEFAULT);
  return agg;
}
 
Example #15
Source File: GeoDistValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private MultiValueSource parsePoint(FunctionQParser fp) throws SyntaxError {
  String ptStr = fp.getParam(SpatialParams.POINT);
  if (ptStr == null) return null;
  Point point = SpatialUtils.parsePointSolrException(ptStr, SpatialContext.GEO);
  //assume Lat Lon order
  return new VectorValueSource(
      Arrays.<ValueSource>asList(new DoubleConstValueSource(point.getY()), new DoubleConstValueSource(point.getX())));
}
 
Example #16
Source File: MyValueParser.java    From solr-custom-score with Apache License 2.0 4 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fq) throws SyntaxError {
    return new FunctionValueSource(maxYears,money_maxTimes,money_base,fq.parseValueSourceList());
}
 
Example #17
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private FunctionQParser mockFunctionQParser(String arg) throws Exception {
  FunctionQParser fqp = mock(FunctionQParser.class);
  when(fqp.getReq()).thenReturn(sqr);    
  when(fqp.parseArg()).thenReturn(arg);
  return fqp;
}
 
Example #18
Source File: DebugAgg.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public DebugAgg(FunctionQParser fp) throws SyntaxError { 
  super("debug");
  this.localParams = fp.getLocalParams();
  this.inner = fp.hasMoreArguments() ? fp.parseAgg(FunctionQParser.FLAG_IS_AGG) : new CountAgg();
}
 
Example #19
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private FunctionQParser mockFunctionQParser(String arg) throws Exception {
  FunctionQParser fqp = mock(FunctionQParser.class);
  when(fqp.getReq()).thenReturn(sqr);    
  when(fqp.parseArg()).thenReturn(arg);
  return fqp;
}
 
Example #20
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private FunctionQParser mockFunctionQParser(String arg) throws Exception {
  FunctionQParser fqp = mock(FunctionQParser.class);
  when(fqp.getReq()).thenReturn(sqr);    
  when(fqp.parseArg()).thenReturn(arg);
  return fqp;
}