PhraseQuery and WildcardQuery

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PhraseQuery and WildcardQuery

Sergey Polzunov-2
Hi all

I've got this error when trying to search query like q=+myFiled:"some
value"*

org.apache.solr.core.SolrException: Query parsing error: Cannot parse
'+myFiled:"some value"*': '*' or '?' not allowed as first character in
WildcardQuery
        at org.apache.solr.search.QueryParsing.parseQuery(QueryParsing.java:104)
        at org.apache.solr.request.StandardRequestHandler.handleRequestBody(StandardRequestHandler.java:109)
...
Caused by: org.apache.lucene.queryParser.ParseException: Cannot parse
'+firstName:"some value"*': '*' or '?' not allowed as first character
in WildcardQuery
        at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:150)
        at org.apache.solr.search.QueryParsing.parseQuery(QueryParsing.java:94)
...

So is there any way to use wildcard with phrase query?

p.s. unexpected - this query works just fine: q=+myFiled:some\ value*
      so I can just escape all control symbols and space - and I'll get what
I want.
      But there are no info about space escaping at
http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters


Thank you in advance


--
Best regards,
Traut
Reply | Threaded
Open this post in threaded view
|

Re: PhraseQuery and WildcardQuery

hossman
: I've got this error when trying to search query like q=+myFiled:"some
: value"*
:
: org.apache.solr.core.SolrException: Query parsing error: Cannot parse
: '+myFiled:"some value"*': '*' or '?' not allowed as first character in
: WildcardQuery
        ...

...this is where the subtleties of the Lucene QueryParser come into place
... where concepts like "word", "term", and "phrase" all collide.  No, you
cannot use wildcards with a quoted phrase query.  

: p.s. unexpected - this query works just fine: q=+myFiled:some\ value*
:       so I can just escape all control symbols and space - and I'll get what

be carefully ... that's probably not doing what you think it's doing.  
it's searching for a documents which contain a single term that starts
with the characters "some value" ... if you indexed with a tokenizer that
splits on whitespace, or does any lowercasing, or does anything
interesting at all in the analyzer, this won't match those docs.  

This is generally true for prefix queries, but people might be confused
and think what they are getting with that syntax is a search for something
matching "some" followed by a prefix query for "value*" ... if you indexed
a doc containg "some the values" with a StopFilter to get rid of "the",
that doc won't match your query.

I say this jsut to clarify for people who see this thread: that syntax
trick might work fine for you if you know you have a very special case, but
it probably won't do what many people expect it to.

:       But there are no info about space escaping at
: http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters

Hmmm...  i'll file bug on that.




-Hoss

Reply | Threaded
Open this post in threaded view
|

Re: PhraseQuery and WildcardQuery

Sergey Polzunov-2
Thank you for the clarification.

On Jan 8, 2008 10:43 AM, Chris Hostetter <[hidden email]> wrote:

> : I've got this error when trying to search query like q=+myFiled:"some
> : value"*
> :
> : org.apache.solr.core.SolrException: Query parsing error: Cannot parse
> : '+myFiled:"some value"*': '*' or '?' not allowed as first character in
> : WildcardQuery
>        ...
>
> ...this is where the subtleties of the Lucene QueryParser come into place
> ... where concepts like "word", "term", and "phrase" all collide.  No, you
> cannot use wildcards with a quoted phrase query.
>
> : p.s. unexpected - this query works just fine: q=+myFiled:some\ value*
> :       so I can just escape all control symbols and space - and I'll get
> what
>
> be carefully ... that's probably not doing what you think it's doing.
> it's searching for a documents which contain a single term that starts
> with the characters "some value" ... if you indexed with a tokenizer that
> splits on whitespace, or does any lowercasing, or does anything
> interesting at all in the analyzer, this won't match those docs.
>
> This is generally true for prefix queries, but people might be confused
> and think what they are getting with that syntax is a search for something
> matching "some" followed by a prefix query for "value*" ... if you indexed
> a doc containg "some the values" with a StopFilter to get rid of "the",
> that doc won't match your query.
>
> I say this jsut to clarify for people who see this thread: that syntax
> trick might work fine for you if you know you have a very special case,
> but
> it probably won't do what many people expect it to.
>
> :       But there are no info about space escaping at
> :
> http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
>
> Hmmm...  i'll file bug on that.
>
>
>
>
> -Hoss
>
>


--
Best regards,
Traut