You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Igor Blanco <ib...@binovo.es.INVALID> on 2023/05/05 09:05:25 UTC

Syntax errors with block join query parser when using parenthesis for grouping subqueries or fields

I'm using SOLR 9.2.1

I have a parent document with a couple of subdocuments, something like this:

    {

    id: "1",

    contexts: [

         {

            id: "CTX1",

            context: "hola"

        },{

            id: "CTX2",

            context: "adios"

       }

    ]

    }

When I try to execute this query:

    ({!parent which="*:* -_nest_path_:*"}(context:(hol? AND h?la)) AND
    {!parent which="*:* -_nest_path_:*"}(context:(adios)))

I expected to receive document with id 1 as a response, but instead i 
receive this syntax error:

org.apache.solr.search.SyntaxError: Cannot parse '(context:(hol?': 
Encountered \"<EOF>\" at line 1, column 14.\nWas expecting one of:\n    
<AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n 
<BAREOPER> ...\n    \"(\" ...\n    \")\" ...\n    \"*\" ...\n    \"^\" 
...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n    
<PREFIXTERM> ...\n <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" 
...\n    \"{\" ...\n    <LPARAMS> ...\n    \"filter(\" ...\n    <NUMBER> 
...\n


It explicitly says that found and <EOF> but that's not true, it is 
followed by and AND which is one of the expected values.

As further information, I've been able to narrow the query to the point 
where this clause works but gives an empty result:

{!parent which="*:* -_nest_path_:*"}context:(hola) AND id:1

But this one throws the mentioned syntax error:

id:1 AND {!parent which="*:* -_nest_path_:*"}context:(hola)

After reading the documentation more thoroughly I think I found the 
explanation of why the first query is returning an empty result here: 
https://solr.apache.org/guide/8_0/the-standard-query-parser.html

It says:

    /Gotcha: Be careful not to start your query with {! at the very
    beginning, which changes the parsing of the entire query string,
    which may not be what you want if there are additional clauses./

So the first query is using the block join query parser for everything 
and effectively the second clause after the AND is searching for id with 
value 1 in the children not the parent so the condition is never met and 
nothing is returned.

The second one instead is using the standard parser for the first clause 
and the block join query parser for the second. In fact removing the

Is this a bug or am I misinterpreting how different query parsers can be 
combined in a query?

-- 


      IgorBlanco

Director desarrollo a medida | Neurrirako garapenen zuzendaria

Binovo IT Human Project




	943 569 206 <tel:943 569 206> | 690229375 <tel:690229375>

	iblanco@binovo.es <ma...@binovo.es>

	binovo.es <//binovo.es>

	Astigarragako Bidea, 2 - 2º izda. Oficina 10-11, 20180 Oiartzun




	
youtube <https://www.youtube.com/user/CANALBINOVO/> 	
	linkedin <https://www.linkedin.com/company/binovo-it-human-project/> 	

Re: Syntax errors with block join query parser when using parenthesis for grouping subqueries or fields

Posted by Mikhail Khludnev <mk...@apache.org>.
>  should I report the observed behaviour as a bug?
I don't think it will go anywhere productive.

On Fri, May 5, 2023 at 1:11 PM Igor Blanco <ib...@binovo.es.invalid>
wrote:

> Adding extra parameters is quite inconvinient for me because I'm
> building a system that builds the queries based on differente inputs
> from the user (a filter panel with a wide variety of conditions).
>
> But following your advice I just inlined the subqueries in the "v"
> parameter after escaping the single quotes and it seems to work as
> expected.
>
> So once more you are my savior, thanks a lot.
>
> Although this works, should I report the observed behaviour as a bug?
>
> El 5/5/23 a las 11:33, Mikhail Khludnev escribió:
> > Hello.
> > This syntax is rather tricky. What's working most times is to extracting
> > subqueries into separate parameters:
> > q=+{!parent which="*:* -_nest_path_:*" v=$sub0} +{!parent which="*:*
> > -_nest_path_:*" v=$sub1}&sub0=context:(+hol? +h?la)&sub1=context:(adios)
> >
> > On Fri, May 5, 2023 at 12:05 PM Igor Blanco<ib...@binovo.es.invalid>
> > wrote:
> >
> >> I'm using SOLR 9.2.1
> >>
> >> I have a parent document with a couple of subdocuments, something like
> >> this:
> >>
> >>      {
> >>
> >>      id: "1",
> >>
> >>      contexts: [
> >>
> >>           {
> >>
> >>              id: "CTX1",
> >>
> >>              context: "hola"
> >>
> >>          },{
> >>
> >>              id: "CTX2",
> >>
> >>              context: "adios"
> >>
> >>         }
> >>
> >>      ]
> >>
> >>      }
> >>
> >> When I try to execute this query:
> >>
> >>      ({!parent which="*:* -_nest_path_:*"}(context:(hol? AND h?la)) AND
> >>      {!parent which="*:* -_nest_path_:*"}(context:(adios)))
> >>
> >> I expected to receive document with id 1 as a response, but instead i
> >> receive this syntax error:
> >>
> >> org.apache.solr.search.SyntaxError: Cannot parse '(context:(hol?':
> >> Encountered \"<EOF>\" at line 1, column 14.\nWas expecting one of:\n
> >> <AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n
> >> <BAREOPER> ...\n    \"(\" ...\n    \")\" ...\n    \"*\" ...\n    \"^\"
> >> ...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n
> >> <PREFIXTERM> ...\n <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\"
> >> ...\n    \"{\" ...\n    <LPARAMS> ...\n    \"filter(\" ...\n    <NUMBER>
> >> ...\n
> >>
> >>
> >> It explicitly says that found and <EOF> but that's not true, it is
> >> followed by and AND which is one of the expected values.
> >>
> >> As further information, I've been able to narrow the query to the point
> >> where this clause works but gives an empty result:
> >>
> >> {!parent which="*:* -_nest_path_:*"}context:(hola) AND id:1
> >>
> >> But this one throws the mentioned syntax error:
> >>
> >> id:1 AND {!parent which="*:* -_nest_path_:*"}context:(hola)
> >>
> >> After reading the documentation more thoroughly I think I found the
> >> explanation of why the first query is returning an empty result here:
> >> https://solr.apache.org/guide/8_0/the-standard-query-parser.html
> >>
> >> It says:
> >>
> >>      /Gotcha: Be careful not to start your query with {! at the very
> >>      beginning, which changes the parsing of the entire query string,
> >>      which may not be what you want if there are additional clauses./
> >>
> >> So the first query is using the block join query parser for everything
> >> and effectively the second clause after the AND is searching for id with
> >> value 1 in the children not the parent so the condition is never met and
> >> nothing is returned.
> >>
> >> The second one instead is using the standard parser for the first clause
> >> and the block join query parser for the second. In fact removing the
> >>
> >> Is this a bug or am I misinterpreting how different query parsers can be
> >> combined in a query?
> >>
> >> --
> >>
> >>
> >>        IgorBlanco
> >>
> >> Director desarrollo a medida | Neurrirako garapenen zuzendaria
> >>
> >> Binovo IT Human Project
> >>
> >>
> >>
> >>
> >>          943 569 206<tel:943 569 206>  | 690229375<tel:690229375>
> >>
> >>          iblanco@binovo.es  <ma...@binovo.es>
> >>
> >>          binovo.es <//binovo.es>
> >>
> >>          Astigarragako Bidea, 2 - 2º izda. Oficina 10-11, 20180 Oiartzun
> >>
> >>
> >>
> >>
> >>
> >> youtube<https://www.youtube.com/user/CANALBINOVO/>
> >>          linkedin<
> https://www.linkedin.com/company/binovo-it-human-project/>
> >>
> >
> --
>
>
>       IgorBlanco
>
> Director desarrollo a medida | Neurrirako garapenen zuzendaria
>
> Binovo IT Human Project
>
>
>
>
>         943 569 206 <tel:943 569 206> | 690229375 <tel:690229375>
>
>         iblanco@binovo.es <ma...@binovo.es>
>
>         binovo.es <//binovo.es>
>
>         Astigarragako Bidea, 2 - 2º izda. Oficina 10-11, 20180 Oiartzun
>
>
>
>
>
> youtube <https://www.youtube.com/user/CANALBINOVO/>
>         linkedin <
> https://www.linkedin.com/company/binovo-it-human-project/>
>


-- 
Sincerely yours
Mikhail Khludnev
https://t.me/MUST_SEARCH
A caveat: Cyrillic!

Re: Syntax errors with block join query parser when using parenthesis for grouping subqueries or fields

Posted by Igor Blanco <ib...@binovo.es.INVALID>.
Adding extra parameters is quite inconvinient for me because I'm 
building a system that builds the queries based on differente inputs 
from the user (a filter panel with a wide variety of conditions).

But following your advice I just inlined the subqueries in the "v" 
parameter after escaping the single quotes and it seems to work as expected.

So once more you are my savior, thanks a lot.

Although this works, should I report the observed behaviour as a bug?

El 5/5/23 a las 11:33, Mikhail Khludnev escribió:
> Hello.
> This syntax is rather tricky. What's working most times is to extracting
> subqueries into separate parameters:
> q=+{!parent which="*:* -_nest_path_:*" v=$sub0} +{!parent which="*:*
> -_nest_path_:*" v=$sub1}&sub0=context:(+hol? +h?la)&sub1=context:(adios)
>
> On Fri, May 5, 2023 at 12:05 PM Igor Blanco<ib...@binovo.es.invalid>
> wrote:
>
>> I'm using SOLR 9.2.1
>>
>> I have a parent document with a couple of subdocuments, something like
>> this:
>>
>>      {
>>
>>      id: "1",
>>
>>      contexts: [
>>
>>           {
>>
>>              id: "CTX1",
>>
>>              context: "hola"
>>
>>          },{
>>
>>              id: "CTX2",
>>
>>              context: "adios"
>>
>>         }
>>
>>      ]
>>
>>      }
>>
>> When I try to execute this query:
>>
>>      ({!parent which="*:* -_nest_path_:*"}(context:(hol? AND h?la)) AND
>>      {!parent which="*:* -_nest_path_:*"}(context:(adios)))
>>
>> I expected to receive document with id 1 as a response, but instead i
>> receive this syntax error:
>>
>> org.apache.solr.search.SyntaxError: Cannot parse '(context:(hol?':
>> Encountered \"<EOF>\" at line 1, column 14.\nWas expecting one of:\n
>> <AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n
>> <BAREOPER> ...\n    \"(\" ...\n    \")\" ...\n    \"*\" ...\n    \"^\"
>> ...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n
>> <PREFIXTERM> ...\n <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\"
>> ...\n    \"{\" ...\n    <LPARAMS> ...\n    \"filter(\" ...\n    <NUMBER>
>> ...\n
>>
>>
>> It explicitly says that found and <EOF> but that's not true, it is
>> followed by and AND which is one of the expected values.
>>
>> As further information, I've been able to narrow the query to the point
>> where this clause works but gives an empty result:
>>
>> {!parent which="*:* -_nest_path_:*"}context:(hola) AND id:1
>>
>> But this one throws the mentioned syntax error:
>>
>> id:1 AND {!parent which="*:* -_nest_path_:*"}context:(hola)
>>
>> After reading the documentation more thoroughly I think I found the
>> explanation of why the first query is returning an empty result here:
>> https://solr.apache.org/guide/8_0/the-standard-query-parser.html
>>
>> It says:
>>
>>      /Gotcha: Be careful not to start your query with {! at the very
>>      beginning, which changes the parsing of the entire query string,
>>      which may not be what you want if there are additional clauses./
>>
>> So the first query is using the block join query parser for everything
>> and effectively the second clause after the AND is searching for id with
>> value 1 in the children not the parent so the condition is never met and
>> nothing is returned.
>>
>> The second one instead is using the standard parser for the first clause
>> and the block join query parser for the second. In fact removing the
>>
>> Is this a bug or am I misinterpreting how different query parsers can be
>> combined in a query?
>>
>> --
>>
>>
>>        IgorBlanco
>>
>> Director desarrollo a medida | Neurrirako garapenen zuzendaria
>>
>> Binovo IT Human Project
>>
>>
>>
>>
>>          943 569 206<tel:943 569 206>  | 690229375<tel:690229375>
>>
>>          iblanco@binovo.es  <ma...@binovo.es>
>>
>>          binovo.es <//binovo.es>
>>
>>          Astigarragako Bidea, 2 - 2º izda. Oficina 10-11, 20180 Oiartzun
>>
>>
>>
>>
>>
>> youtube<https://www.youtube.com/user/CANALBINOVO/>
>>          linkedin< https://www.linkedin.com/company/binovo-it-human-project/>
>>
>
-- 


      IgorBlanco

Director desarrollo a medida | Neurrirako garapenen zuzendaria

Binovo IT Human Project




	943 569 206 <tel:943 569 206> | 690229375 <tel:690229375>

	iblanco@binovo.es <ma...@binovo.es>

	binovo.es <//binovo.es>

	Astigarragako Bidea, 2 - 2º izda. Oficina 10-11, 20180 Oiartzun




	
youtube <https://www.youtube.com/user/CANALBINOVO/> 	
	linkedin <https://www.linkedin.com/company/binovo-it-human-project/> 	

Re: Syntax errors with block join query parser when using parenthesis for grouping subqueries or fields

Posted by Mikhail Khludnev <mk...@apache.org>.
Hello.
This syntax is rather tricky. What's working most times is to extracting
subqueries into separate parameters:
q=+{!parent which="*:* -_nest_path_:*" v=$sub0} +{!parent which="*:*
-_nest_path_:*" v=$sub1}&sub0=context:(+hol? +h?la)&sub1=context:(adios)

On Fri, May 5, 2023 at 12:05 PM Igor Blanco <ib...@binovo.es.invalid>
wrote:

> I'm using SOLR 9.2.1
>
> I have a parent document with a couple of subdocuments, something like
> this:
>
>     {
>
>     id: "1",
>
>     contexts: [
>
>          {
>
>             id: "CTX1",
>
>             context: "hola"
>
>         },{
>
>             id: "CTX2",
>
>             context: "adios"
>
>        }
>
>     ]
>
>     }
>
> When I try to execute this query:
>
>     ({!parent which="*:* -_nest_path_:*"}(context:(hol? AND h?la)) AND
>     {!parent which="*:* -_nest_path_:*"}(context:(adios)))
>
> I expected to receive document with id 1 as a response, but instead i
> receive this syntax error:
>
> org.apache.solr.search.SyntaxError: Cannot parse '(context:(hol?':
> Encountered \"<EOF>\" at line 1, column 14.\nWas expecting one of:\n
> <AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n
> <BAREOPER> ...\n    \"(\" ...\n    \")\" ...\n    \"*\" ...\n    \"^\"
> ...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n
> <PREFIXTERM> ...\n <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\"
> ...\n    \"{\" ...\n    <LPARAMS> ...\n    \"filter(\" ...\n    <NUMBER>
> ...\n
>
>
> It explicitly says that found and <EOF> but that's not true, it is
> followed by and AND which is one of the expected values.
>
> As further information, I've been able to narrow the query to the point
> where this clause works but gives an empty result:
>
> {!parent which="*:* -_nest_path_:*"}context:(hola) AND id:1
>
> But this one throws the mentioned syntax error:
>
> id:1 AND {!parent which="*:* -_nest_path_:*"}context:(hola)
>
> After reading the documentation more thoroughly I think I found the
> explanation of why the first query is returning an empty result here:
> https://solr.apache.org/guide/8_0/the-standard-query-parser.html
>
> It says:
>
>     /Gotcha: Be careful not to start your query with {! at the very
>     beginning, which changes the parsing of the entire query string,
>     which may not be what you want if there are additional clauses./
>
> So the first query is using the block join query parser for everything
> and effectively the second clause after the AND is searching for id with
> value 1 in the children not the parent so the condition is never met and
> nothing is returned.
>
> The second one instead is using the standard parser for the first clause
> and the block join query parser for the second. In fact removing the
>
> Is this a bug or am I misinterpreting how different query parsers can be
> combined in a query?
>
> --
>
>
>       IgorBlanco
>
> Director desarrollo a medida | Neurrirako garapenen zuzendaria
>
> Binovo IT Human Project
>
>
>
>
>         943 569 206 <tel:943 569 206> | 690229375 <tel:690229375>
>
>         iblanco@binovo.es <ma...@binovo.es>
>
>         binovo.es <//binovo.es>
>
>         Astigarragako Bidea, 2 - 2º izda. Oficina 10-11, 20180 Oiartzun
>
>
>
>
>
> youtube <https://www.youtube.com/user/CANALBINOVO/>
>         linkedin <
> https://www.linkedin.com/company/binovo-it-human-project/>
>


-- 
Sincerely yours
Mikhail Khludnev
https://t.me/MUST_SEARCH
A caveat: Cyrillic!