Search code examples
c#solrnet

Solrnet: problem when search field value is query operator (eq. or, and)


To be more precise I will be working with example...

Clean query is: (type:77 AND (zipCode:12345 OR name:OR))

When querying on Solr Admin page this throws exception:

org.apache.lucene.queryParser.ParseException: Cannot parse...

So on Solr Admin page I changed query to:

(type:"77" AND (zipCode:"12345" OR name:"OR"))

which worked as a charm

Now I have a problem to do the same stuff with solrnet. I am using SolrQueryByField class for querying. When I am working with

new SolrQueryByField("name", "OR")

I get Solrnet.Exceptions.InvalidFieldException which is in accordance with Solr Admin page, but when I am working with

new SolrQueryByField("name", "\"OR\"")

I get wrong results. By inspecting network traffic I found out that http get request is different (for brevity only name field name and value are given):

name%3A%22OR%22 => from Solr Admin page

name%3a%5c%22OR%5c%22 => from solrnet

My question is: what sholud I do to prevent solrnet from adding %5C (backslash) to query string?

Thanks in advance


Solution

  • SolrQueryByField produces quoted/escaped values. If you have some special case where this is not desirable (such as this case) you can use SolrQuery, e.g. :

    Query.Field("type").Is(77) && (Query.Field("zipCode").Is("12345") || Query.Simple("name:\"OR\""))