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 Indika Tantrigoda <in...@gmail.com> on 2010/03/28 15:39:37 UTC

Filter query with special character using SolrJ client

Hello,

I am trying to get filter querying to work on search.
When the filter query contains no special character or is a single word the
filter query parameter returns the result as expected.
However when I run filter query where special characters are present no
results are results.

e.g Cameras & Photos, I removed the & character as well (Cameras and Photos)
and still no results are returned.

However for a string like Electronics the results are returned as expected.

I am using the string field to store and index the field that I want to
filter and SolrJ as the client.

>From the documentation I read solrJ automatically escapes special
characters.

Any help regarding this is much appreciated.

Regards,
Indika

Re: Filter query with special character using SolrJ client

Posted by Indika Tantrigoda <in...@gmail.com>.
Thank you very much for the explanation.

Regards,
Indika

On 29 March 2010 22:28, Chris Hostetter <ho...@fucit.org> wrote:

>
> : It works, thanks. Just implemented the code...:):):)
> :
> : Could you explain what "{!field f=yourStringField}Cameras & Photos" does.
>
> {!field} says that the string should be parsed using the FIeldQParser.
> the FieldQParser takes an 'f' local param telling it what field you want
> to use, and the rest of the string is the exact value you want to
> passed to the analyzer for thet field 'f'  ... it's a query parser that
> supports no markup of any kind, and only produces basic
> PhraseQueries or TermQueries (there's also the "raw" QParser for when you
> absolutely know you only want TermQueries) ...
>
>
> http://wiki.apache.org/solr/SolrQuerySyntax#Other_built-in_useful_query_parsers
>
> http://lucene.apache.org/solr/api/org/apache/solr/search/FieldQParserPlugin.html
>
>
> -Hoss
>
>

Re: Filter query with special character using SolrJ client

Posted by Chris Hostetter <ho...@fucit.org>.
: It works, thanks. Just implemented the code...:):):)
: 
: Could you explain what "{!field f=yourStringField}Cameras & Photos" does.

{!field} says that the string should be parsed using the FIeldQParser.  
the FieldQParser takes an 'f' local param telling it what field you want 
to use, and the rest of the string is the exact value you want to 
passed to the analyzer for thet field 'f'  ... it's a query parser that 
supports no markup of any kind, and only produces basic 
PhraseQueries or TermQueries (there's also the "raw" QParser for when you 
absolutely know you only want TermQueries) ...

http://wiki.apache.org/solr/SolrQuerySyntax#Other_built-in_useful_query_parsers
http://lucene.apache.org/solr/api/org/apache/solr/search/FieldQParserPlugin.html


-Hoss


Re: Filter query with special character using SolrJ client

Posted by Indika Tantrigoda <in...@gmail.com>.
It works, thanks. Just implemented the code...:):):)

Could you explain what "{!field f=yourStringField}Cameras & Photos" does.

Regards,
Indika


On 29 March 2010 21:55, Chris Hostetter <ho...@fucit.org> wrote:

>
> : Since the names of the string fields are not predefined I might have to
> : find a method to do this automatically.
>
> if the fields are strings, and you are only looking for "exact" matches
> (ie: you don't need any special query parser syntax) use the "field"
> QParser....
>
> : > SolrQuery.addFilterQuery("yourStringField:Cameras\\ \\&\\ Photos")
>
> solrQuery.addFilterQuery("{!field f=yourStringField}Cameras & Photos")
>
>
> -Hoss
>
>

Re: Filter query with special character using SolrJ client

Posted by Chris Hostetter <ho...@fucit.org>.
: Since the names of the string fields are not predefined I might have to
: find a method to do this automatically.

if the fields are strings, and you are only looking for "exact" matches 
(ie: you don't need any special query parser syntax) use the "field" 
QParser....

: > SolrQuery.addFilterQuery("yourStringField:Cameras\\ \\&\\ Photos")

solrQuery.addFilterQuery("{!field f=yourStringField}Cameras & Photos")


-Hoss


Re: Filter query with special character using SolrJ client

Posted by Indika Tantrigoda <in...@gmail.com>.
Thanks for the info. I'll have a try and see how the results are.
Since the names of the string fields are not predefined I might have to
find a method to do this automatically.

I'll try a few more workarounds and see what the results turn out to be.

Regards,
Indika

On 29 March 2010 06:57, Ahmet Arslan <io...@yahoo.com> wrote:

>
> > I am trying to get filter querying to work on search.
> > When the filter query contains no special character or is a
> > single word the
> > filter query parameter returns the result as expected.
> > However when I run filter query where special characters
> > are present no
> > results are results.
> >
> > e.g Cameras & Photos, I removed the & character as
> > well (Cameras and Photos)
> > and still no results are returned.
> >
> > However for a string like Electronics the results are
> > returned as expected.
> >
> > I am using the string field to store and index the field
> > that I want to
> > filter and SolrJ as the client.
> >
> > From the documentation I read solrJ automatically escapes
> > special
> > characters.
>
> With SolrJ you don't need to urlencode. However you still need to escape
> special query syntax parameters. Can you try this:
>
> SolrQuery.addFilterQuery("yourStringField:Cameras\\ \\&\\ Photos")
>
>
>
>

Re: Filter query with special character using SolrJ client

Posted by Ahmet Arslan <io...@yahoo.com>.
> I am trying to get filter querying to work on search.
> When the filter query contains no special character or is a
> single word the
> filter query parameter returns the result as expected.
> However when I run filter query where special characters
> are present no
> results are results.
> 
> e.g Cameras & Photos, I removed the & character as
> well (Cameras and Photos)
> and still no results are returned.
> 
> However for a string like Electronics the results are
> returned as expected.
> 
> I am using the string field to store and index the field
> that I want to
> filter and SolrJ as the client.
> 
> From the documentation I read solrJ automatically escapes
> special
> characters.

With SolrJ you don't need to urlencode. However you still need to escape special query syntax parameters. Can you try this:

SolrQuery.addFilterQuery("yourStringField:Cameras\\ \\&\\ Photos")