You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by utuncdemir <ca...@gmail.com> on 2009/08/28 09:51:12 UTC

ParseException

Hello

When search term has word 'OR', Lucene throws an ParseException but here the
term 'OR' is not searched for to be interpreted by condition in query
intentionally.The needs is simple to get the lucene document which has text
for example ' Holland OR Germany '.in other words when i search for 'Holland
OR Germany' for example, i dont want the lucene documents which contains
either text 'Holland' or 'Germany'.I want simply the document which has
exactly containing the text ' Holland OR Germany '.I want the 'OR' term
interpreted as usual string not search operator in Lucene.

When i try same with Luke, also i am having same problem there.

How can i avoid this and make Lucene interpret search operators in its own
implementation as simple text ? 

Thank you in advance.
-- 
View this message in context: http://www.nabble.com/ParseException-tp25185575p25185575.html
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: ParseException

Posted by Adriano Crestani <ad...@gmail.com>.
I tested the solution I gave to you with KeywordAnalyzer and it works as
expected, it's generating a 'field:a field:or field:b' query from the query
'a \OR b'. The same happens for the SimpleAnalyzer.

Now, the problem with StandardAnalyzer, it's actually removing the term 'or'
and 'a' if you type it in the query, because they are english stopwords. To
fix it, use a different set of stopwords that do not contain 'or' or 'a' in
it.

Below is the code I'm using to reproduce your problem using lucene code from
the trunk:

    QueryParser qp = new QueryParser("field", new StandardAnalyzer(new
String[0]));

    Query q = qp.parse("a \\OR b");
    System.out.println(q);

    Outputs: field:a field:or field:b

    QueryParser qp = new QueryParser("field", new StandardAnalyzer();

    Query q = qp.parse("a \\OR b");
    System.out.println(q);

    Outputs: field:b

    QueryParser qp = new QueryParser("field", new KeywordAnalyzer());

    Query q = qp.parse("a \\OR b");
    System.out.println(q);

    Outputs: field:a field:or field:b

    QueryParser qp = new QueryParser("field", new SimpleAnalyzer());

    Query q = qp.parse("a \\OR b");
    System.out.println(q);

    Outputs: field:a field:or field:b

On Mon, Aug 31, 2009 at 8:50 AM, utuncdemir <ca...@gmail.com> wrote:

>
> Thank you for reply but it works in case only Analyzer is SimpleAnalyzer.It
> doesnt throw exception but also can not find results too in case the
> analyzer is either KeywordAnalyzer or StandartAnalyzer..do you have a clue
> that what can be cause of this ? Is it bug maybe or is it the
> implementation
> of these analyzers so it is working as how it should ?
>
>
> Adriano Crestani-2 wrote:
> >
> > Hi,
> >
> > You can escape the query parser keywords: Holland \OR Germany
> >
> > This way the query parser will interpret it as as term instead of a
> > boolean
> > operator.
> >
> > Regards,
> > Adriano Crestani
> >
> > On Fri, Aug 28, 2009 at 3:51 AM, utuncdemir <ca...@gmail.com> wrote:
> >
> >>
> >> Hello
> >>
> >> When search term has word 'OR', Lucene throws an ParseException but here
> >> the
> >> term 'OR' is not searched for to be interpreted by condition in query
> >> intentionally.The needs is simple to get the lucene document which has
> >> text
> >> for example ' Holland OR Germany '.in other words when i search for
> >> 'Holland
> >> OR Germany' for example, i dont want the lucene documents which contains
> >> either text 'Holland' or 'Germany'.I want simply the document which has
> >> exactly containing the text ' Holland OR Germany '.I want the 'OR' term
> >> interpreted as usual string not search operator in Lucene.
> >>
> >> When i try same with Luke, also i am having same problem there.
> >>
> >> How can i avoid this and make Lucene interpret search operators in its
> >> own
> >> implementation as simple text ?
> >>
> >> Thank you in advance.
> >> --
> >> View this message in context:
> >> http://www.nabble.com/ParseException-tp25185575p25185575.html
> >> Sent from the Lucene - Java Developer mailing list archive at
> Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> >> For additional commands, e-mail: java-dev-help@lucene.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/ParseException-tp25185575p25222972.html
> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>
>

Re: ParseException

Posted by utuncdemir <ca...@gmail.com>.
Thank you for reply but it works in case only Analyzer is SimpleAnalyzer.It
doesnt throw exception but also can not find results too in case the
analyzer is either KeywordAnalyzer or StandartAnalyzer..do you have a clue
that what can be cause of this ? Is it bug maybe or is it the implementation
of these analyzers so it is working as how it should ?


Adriano Crestani-2 wrote:
> 
> Hi,
> 
> You can escape the query parser keywords: Holland \OR Germany
> 
> This way the query parser will interpret it as as term instead of a
> boolean
> operator.
> 
> Regards,
> Adriano Crestani
> 
> On Fri, Aug 28, 2009 at 3:51 AM, utuncdemir <ca...@gmail.com> wrote:
> 
>>
>> Hello
>>
>> When search term has word 'OR', Lucene throws an ParseException but here
>> the
>> term 'OR' is not searched for to be interpreted by condition in query
>> intentionally.The needs is simple to get the lucene document which has
>> text
>> for example ' Holland OR Germany '.in other words when i search for
>> 'Holland
>> OR Germany' for example, i dont want the lucene documents which contains
>> either text 'Holland' or 'Germany'.I want simply the document which has
>> exactly containing the text ' Holland OR Germany '.I want the 'OR' term
>> interpreted as usual string not search operator in Lucene.
>>
>> When i try same with Luke, also i am having same problem there.
>>
>> How can i avoid this and make Lucene interpret search operators in its
>> own
>> implementation as simple text ?
>>
>> Thank you in advance.
>> --
>> View this message in context:
>> http://www.nabble.com/ParseException-tp25185575p25185575.html
>> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-dev-help@lucene.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/ParseException-tp25185575p25222972.html
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: ParseException

Posted by Adriano Crestani <ad...@gmail.com>.
Hi,

You can escape the query parser keywords: Holland \OR Germany

This way the query parser will interpret it as as term instead of a boolean
operator.

Regards,
Adriano Crestani

On Fri, Aug 28, 2009 at 3:51 AM, utuncdemir <ca...@gmail.com> wrote:

>
> Hello
>
> When search term has word 'OR', Lucene throws an ParseException but here
> the
> term 'OR' is not searched for to be interpreted by condition in query
> intentionally.The needs is simple to get the lucene document which has text
> for example ' Holland OR Germany '.in other words when i search for
> 'Holland
> OR Germany' for example, i dont want the lucene documents which contains
> either text 'Holland' or 'Germany'.I want simply the document which has
> exactly containing the text ' Holland OR Germany '.I want the 'OR' term
> interpreted as usual string not search operator in Lucene.
>
> When i try same with Luke, also i am having same problem there.
>
> How can i avoid this and make Lucene interpret search operators in its own
> implementation as simple text ?
>
> Thank you in advance.
> --
> View this message in context:
> http://www.nabble.com/ParseException-tp25185575p25185575.html
> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>
>