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 "Rathor, Piyush (US - Philadelphia)" <pr...@DELOITTE.com> on 2018/09/27 04:39:08 UTC

Solr Search Special Characters

Hi All,



We are facing some issues in search with special characters. Can you please help in query if the search is done using following characters:

•             “&”

               Example – Tata & Sons

•             AND

               Example – Tata AND Sons

•             (

               Example – People (Pvt) Ltd

•             )

               Example – People (Pvt) Ltd





Thanks & Regards

Piyush Rathor

Consultant

Deloitte Digital (Salesforce.com / Force.com)

Deloitte Consulting Pvt. Ltd.

Office: +1 (615) 209 4980

Mobile : +1 (302) 397 1491

prathor@deloitte.com | www.deloitte.com



Please consider the environment before printing.



This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, you should delete this message and any disclosure, copying, or distribution of this message, or the taking of any action based on it, by you is strictly prohibited.

v.E.1

Re: Solr Search Special Characters

Posted by Balanathagiri Ayyasamypalanivel <ba...@gmail.com>.
Hi,
You can escape all the characters by using \ .
Ex :
\&
\-


But it will not work only for "&" special character if you directly try in
browser.
It will work when use solr apis in the code.

Regards,
Bala.


On Thu, Sep 27, 2018, 6:52 AM Shawn Heisey <ap...@elyograg.org> wrote:

> On 9/26/2018 10:39 PM, Rathor, Piyush (US - Philadelphia) wrote:
> > We are facing some issues in search with special characters. Can you
> please help in query if the search is done using following characters:
> >
> > •             “&”
> > •             AND
> > •             (
> > •             )
>
> There are two ways.  One is to escape them.  The escaping character in
> Solr is a backslash.
>
> \&
> AN\D
> \(
> \)
>
> The other is to use a technique or a query parser that treats all
> characters as literal.  Putting information inside double quotes
> sometimes works, but this also makes the query a phrase query, which
> might produce incorrect results.  One query parser that treats all
> characters literally is the field parser:
>
>
> https://lucene.apache.org/solr/guide/6_6/other-parsers.html#OtherParsers-FieldQueryParser
>
> If you use escaping, you don't have to change your query parser, which
> can completely change how your query text is interpreted.  Sometimes
> changing the query parser is the best option, sometimes it isn't.
>
> URL encoding the characters as Atita suggests won't help. That's
> something you have to do anyway just to get certain characters to be
> successfully sent in a URL.  Most Solr clients for programming languages
> will do the URL encoding for you.
>
> Thanks,
> Shawn
>
>

Re: Solr Search Special Characters

Posted by Shawn Heisey <ap...@elyograg.org>.
On 9/26/2018 10:39 PM, Rathor, Piyush (US - Philadelphia) wrote:
> We are facing some issues in search with special characters. Can you please help in query if the search is done using following characters:
>
> •             “&”
> •             AND
> •             (
> •             )

There are two ways.  One is to escape them.  The escaping character in 
Solr is a backslash.

\&
AN\D
\(
\)

The other is to use a technique or a query parser that treats all 
characters as literal.  Putting information inside double quotes 
sometimes works, but this also makes the query a phrase query, which 
might produce incorrect results.  One query parser that treats all 
characters literally is the field parser:

https://lucene.apache.org/solr/guide/6_6/other-parsers.html#OtherParsers-FieldQueryParser

If you use escaping, you don't have to change your query parser, which 
can completely change how your query text is interpreted.  Sometimes 
changing the query parser is the best option, sometimes it isn't.

URL encoding the characters as Atita suggests won't help. That's 
something you have to do anyway just to get certain characters to be 
successfully sent in a URL.  Most Solr clients for programming languages 
will do the URL encoding for you.

Thanks,
Shawn


Re: Solr Search Special Characters

Posted by Atita Arora <at...@gmail.com>.
Hi Piyush,

This sounds like an encoding problem.
Can you try q= Tata%20%26%20Sons ?

I believe for '&' you can use %26 in your query. (refer to
https://meyerweb.com , encode your queries and try them if they work as
expected)
You can you also try debug=true to see what query is actually sent.

I am sure you must have checked =>
http://lucene.apache.org/core/6_5_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Escaping_Special_Characters
too.

Atita



On Thu, Sep 27, 2018 at 6:39 AM Rathor, Piyush (US - Philadelphia) <
prathor@deloitte.com> wrote:

> Hi All,
>
>
>
> We are facing some issues in search with special characters. Can you
> please help in query if the search is done using following characters:
>
> •             “&”
>
>                Example – Tata & Sons
>
> •             AND
>
>                Example – Tata AND Sons
>
> •             (
>
>                Example – People (Pvt) Ltd
>
> •             )
>
>                Example – People (Pvt) Ltd
>
>
>
>
>
> Thanks & Regards
>
> Piyush Rathor
>
> Consultant
>
> Deloitte Digital (Salesforce.com / Force.com)
>
> Deloitte Consulting Pvt. Ltd.
>
> Office: +1 (615) 209 4980
>
> Mobile : +1 (302) 397 1491
>
> prathor@deloitte.com | www.deloitte.com
>
>
>
> Please consider the environment before printing.
>
>
>
> This message (including any attachments) contains confidential information
> intended for a specific individual and purpose, and is protected by law. If
> you are not the intended recipient, you should delete this message and any
> disclosure, copying, or distribution of this message, or the taking of any
> action based on it, by you is strictly prohibited.
>
> v.E.1
>