Jimtronic
Jimtronic

Reputation: 1209

Using another field value as default in a solr function query

I'm trying to run the following query:

/solr/select?q=_val_:query("{!dismax qf=text v='solr rocks'}", my_field)

But, specifying my_field as the default value throws the error:

java.lang.NumberFormatException: For input string: "my_field"

Additionally, these queries also fail:

/solr/select?q=_val_:query("{!dismax qf=text v='solr rocks'}", ceil(my_field))
/solr/select?q=_val_:query("{!dismax qf=text v='solr rocks'}", ceil(1.0))

Can we not specify another field or function as the default in function queries? Is there another way to accomplish what I'm trying to do?

I'm using Solr 3.1.

Upvotes: 1

Views: 973

Answers (2)

Jimtronic
Jimtronic

Reputation: 1209

I did find an alternate way to mimic the desired logic:

/solr/select?q=_val_:sum(query("{!dismax qf=text v='solr rocks'}"),product(map(query("{!dismax qf=text v='solr rocks'}",-1),0,100,0,1), my_field))

A little roundabout way to do it, but works fine.

Upvotes: 0

jpountz
jpountz

Reputation: 9964

According to the code of the ValueSourceParser for QueryValueSource (line 261), the 2nd argument of query can only be a float. So 3 or 4.5 would work, but my_field or ceil(1.0) which are ValueSources instead of constants would not.

I don't know what your use case is, but would taking max(query("{!dismax qf=text v='solr rocks'}"), my_field) be good enough? (Provided that my_field has positive values, the result would only differ from what you are trying to do when the score of the query is lower than the value of my_field)

Otherwise, if you really need this feature, it should be fairly easy to implement your own function based on QueryValueSource in order to take a ValueSource as the 2nd argument instead of a float.

Upvotes: 1

Related Questions