lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexandre Rafalovitch <>
Subject Re: Is it possible to escape some texts from Solr query?
Date Tue, 04 Sep 2018 15:23:12 GMT
As Erick said, you need to be looking into Query Parsers. There are
many, depending on what search you are actually allowing your users to
do. You probably know lucene/default, dismax and edismax, but there
are many more:

For example, you could allow a lot of flexibility but choose specific
operators allowed with Simple Query Parser:

Or, in the other extreme, you could allow to search against a single
field only with Field Query Parser:

You may also benefit from dereferencing to ensure the full query is
not overridden:
, possibly combined with invariants for the handler definition:


On 4 September 2018 at 11:11, Erick Erickson <> wrote:
> This is a query _parsing_ issue, way before a tokenizer ever gets to
> it. The problem of course is that AND is an operator in the query
> language, so your problem is how to distinguish it from the value of a
> field.
> You can always quote the input for id, as in id:"AND" which you could
> do for everything you put in that field. You'll have he same problem
> with OR and NOT BTW.
> Best,
> Erick
> On Tue, Sep 4, 2018 at 3:10 AM girish.vignesh <> wrote:
>> One of the ID attribute which we are using to query is AND so our looks like
>> http://localhost:8983/solr//select?fq=id:AND&wt=json
>> This throws below mentioned exception
>> error: { metadata: [ "error-class", "org.apache.solr.common.SolrException",
>> "root-error-class", "org.apache.solr.parser.ParseException" ], msg:
>> " Cannot parse 'id:AND': Encountered "
>> "AND "" at line 1
>> I can escape AND by using below mentioned queries
>> http://localhost:8983/solr//select?fq=entityId:\AND&wt=json
>> http://localhost:8983/solr//select?fq=entityId:%22AND%22&wt=json
>> Question: I do not want to handle this while making a query. Is there any
>> other way to handle this at Solr config level using tokenizer or some other
>> way. This way I do not have to handle this at multiple places.
>> --
>> Sent from:

View raw message