You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Arun Rangarajan <ar...@gmail.com> on 2014/03/01 00:52:52 UTC

Boost query syntax error

The Solr function query documentation (
https://wiki.apache.org/solr/FunctionQuery#exists) says:

exists(query({!v='year:2012'})) will return true for docs with year=2012

I have a document like:

{
  id: 1,
  user_type: ADMIN,
  like_score: 1
}
id, user_type and like_score are all indexed and stored files, with id
being int, user_type being string and like_score being int.

I issue a query like this:

q={!boost b=if(true,10,1)}id:1&rows=1&fl=*,score
which works.

But this query does not work:

q={!boost
b=if(exists(query({!v='user_type:ADMIN'})),10,1)}id:1&rows=1&fl=*,score
It gives an error like this:

"error":{
  "msg":"org.apache.solr.search.SyntaxError: Cannot parse ')),5,10)}id:1':
Encountered \" \")\" \") \"\" at line 1, column 0.\nWas expecting one of:\n
   <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\"
...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM>
...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\"
...\n    <LPARAMS> ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n
 ",
  "code":400
}
How do I fix the query?

This syntax works:

q={!func}if(exists(query({!v='user_type:ADMIN'})),5,10)&rows=1&fl=*,score
but it doesn't give the multiplicative score I want.

Re: Boost query syntax error

Posted by Arun Rangarajan <ar...@gmail.com>.
All of them work like a charm! Thanks, Chris.


On Mon, Mar 3, 2014 at 1:28 PM, Chris Hostetter <ho...@fucit.org>wrote:

>
> : But this query does not work:
> :
> : q={!boost
> : b=if(exists(query({!v='user_type:ADMIN'})),10,1)}id:1&rows=1&fl=*,score
> : It gives an error like this:
>
> The problem is the way you are trying to nest queries inside of each other
> w/o any sort of quoting -- the parser has no indication that the "b" param
> is "if(exists(query({!v='user_type:ADMIN'})),10,1)" it thinks it'
> "if(exists(query({!v='user_type:ADMIN'" and the rest is confusing it.
>
> If you quote the "b" param to the boost parser, then it should work...
>
>
> http://localhost:8983/solr/select?q={!boost%20b=%22if%28exists%28query%28{!v=%27foo_s:ADMIN%27}%29%29,10,1%29%22}id:1
>
> ...or if you could use variable derefrencing, either of these should
> work...
>
>
> http://localhost:8983/solr/select?q={!boost%20b=$b}id:1&b=if%28exists%28query%28{!v=%27foo_s:ADMIN%27}%29%29,10,1%29
>
> http://localhost:8983/solr/select?q={!boost%20b=if(exists(query($nestedq)),10,1)}id:1&nestedq=foo_s:ADMIN
>
>
> -Hoss
> http://www.lucidworks.com/
>

Re: Boost query syntax error

Posted by Chris Hostetter <ho...@fucit.org>.
: But this query does not work:
: 
: q={!boost
: b=if(exists(query({!v='user_type:ADMIN'})),10,1)}id:1&rows=1&fl=*,score
: It gives an error like this:

The problem is the way you are trying to nest queries inside of each other 
w/o any sort of quoting -- the parser has no indication that the "b" param 
is "if(exists(query({!v='user_type:ADMIN'})),10,1)" it thinks it' 
"if(exists(query({!v='user_type:ADMIN'" and the rest is confusing it.

If you quote the "b" param to the boost parser, then it should work...

http://localhost:8983/solr/select?q={!boost%20b=%22if%28exists%28query%28{!v=%27foo_s:ADMIN%27}%29%29,10,1%29%22}id:1

...or if you could use variable derefrencing, either of these should 
work...

http://localhost:8983/solr/select?q={!boost%20b=$b}id:1&b=if%28exists%28query%28{!v=%27foo_s:ADMIN%27}%29%29,10,1%29
http://localhost:8983/solr/select?q={!boost%20b=if(exists(query($nestedq)),10,1)}id:1&nestedq=foo_s:ADMIN


-Hoss
http://www.lucidworks.com/