You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by Grant Ingersoll <gs...@apache.org> on 2009/11/17 13:08:41 UTC

Passing string constants to functions

Any idea on how to pass string constants to a function?

When I do I get:
java.lang.RuntimeException: Exception during query
        at org.apache.solr.util.AbstractSolrTestCase.assertQ(AbstractSolrTestCase.java:218)
        at org.apache.solr.util.AbstractSolrTestCase.assertQ(AbstractSolrTestCase.java:201)
        at org.apache.solr.search.function.distance.DistanceFunctionTest.testHaversine(DistanceFunctionTest.java:55)
Caused by: org.apache.solr.common.SolrException: undefined field tv8nj9qj92me
        at org.apache.solr.schema.IndexSchema.getField(IndexSchema.java:1077)
        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:249)
        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:173)
        at org.apache.solr.search.ValueSourceParser$20.parse(ValueSourceParser.java:341)
        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:245)
        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:173)
        at org.apache.solr.search.FunctionQParser.parse(FunctionQParser.java:40)
        at org.apache.solr.search.QParser.getQuery(QParser.java:131)
        at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:89)
        at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:174)
        at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131)

FWIW, tv8nj9qj92me is a geohash.

The code in question is:
protected ValueSource parseValueSource(boolean doConsumeDelimiter) throws ParseException {
    ValueSource valueSource;
    
    int ch = sp.peek();
    if (ch>='0' && ch<='9'  || ch=='.' || ch=='+' || ch=='-') {
      valueSource = new ConstValueSource(sp.getFloat());
    }
    else {
      String id = sp.getId();
      if (sp.opt("(")) {
        // a function... look it up.
        ValueSourceParser argParser = req.getCore().getValueSourceParser(id);
        if (argParser==null) {
          throw new ParseException("Unknown function " + id + " in FunctionQuery(" + sp + ")");
        }
        valueSource = argParser.parse(this);
        sp.expect(")");
      }
      else {
        SchemaField f = req.getSchema().getField(id);     //  <<<<<<<<<<<<<<<<<<<   Exception here.
        valueSource = f.getType().getValueSource(f, this);
      }
    }
    
    if (doConsumeDelimiter)
      consumeArgumentDelimiter();
    
    return valueSource;
  }


Seems like we could change this to allow the id to be a constant and pass it along if it isn't a field and wrap it in a literal (new function) or constant.  Thoughts?

-Grant


Re: Passing string constants to functions

Posted by Grant Ingersoll <gs...@apache.org>.
https://issues.apache.org/jira/browse/SOLR-1569

On Nov 17, 2009, at 7:08 AM, Grant Ingersoll wrote:

> Any idea on how to pass string constants to a function?
> 
> When I do I get:
> java.lang.RuntimeException: Exception during query
>        at org.apache.solr.util.AbstractSolrTestCase.assertQ(AbstractSolrTestCase.java:218)
>        at org.apache.solr.util.AbstractSolrTestCase.assertQ(AbstractSolrTestCase.java:201)
>        at org.apache.solr.search.function.distance.DistanceFunctionTest.testHaversine(DistanceFunctionTest.java:55)
> Caused by: org.apache.solr.common.SolrException: undefined field tv8nj9qj92me
>        at org.apache.solr.schema.IndexSchema.getField(IndexSchema.java:1077)
>        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:249)
>        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:173)
>        at org.apache.solr.search.ValueSourceParser$20.parse(ValueSourceParser.java:341)
>        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:245)
>        at org.apache.solr.search.FunctionQParser.parseValueSource(FunctionQParser.java:173)
>        at org.apache.solr.search.FunctionQParser.parse(FunctionQParser.java:40)
>        at org.apache.solr.search.QParser.getQuery(QParser.java:131)
>        at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:89)
>        at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:174)
>        at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131)
> 
> FWIW, tv8nj9qj92me is a geohash.
> 
> The code in question is:
> protected ValueSource parseValueSource(boolean doConsumeDelimiter) throws ParseException {
>    ValueSource valueSource;
> 
>    int ch = sp.peek();
>    if (ch>='0' && ch<='9'  || ch=='.' || ch=='+' || ch=='-') {
>      valueSource = new ConstValueSource(sp.getFloat());
>    }
>    else {
>      String id = sp.getId();
>      if (sp.opt("(")) {
>        // a function... look it up.
>        ValueSourceParser argParser = req.getCore().getValueSourceParser(id);
>        if (argParser==null) {
>          throw new ParseException("Unknown function " + id + " in FunctionQuery(" + sp + ")");
>        }
>        valueSource = argParser.parse(this);
>        sp.expect(")");
>      }
>      else {
>        SchemaField f = req.getSchema().getField(id);     //  <<<<<<<<<<<<<<<<<<<   Exception here.
>        valueSource = f.getType().getValueSource(f, this);
>      }
>    }
> 
>    if (doConsumeDelimiter)
>      consumeArgumentDelimiter();
> 
>    return valueSource;
>  }
> 
> 
> Seems like we could change this to allow the id to be a constant and pass it along if it isn't a field and wrap it in a literal (new function) or constant.  Thoughts?
> 
> -Grant
> 

--------------------------
Grant Ingersoll
http://www.lucidimagination.com/

Search the Lucene ecosystem (Lucene/Solr/Nutch/Mahout/Tika/Droids) using Solr/Lucene:
http://www.lucidimagination.com/search