Reputation: 33
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
Upvotes: 3
Views: 2896
Reputation: 855
Please try to pass the string array that contains multiple field names and search text in the below method. It will return the solrnet query for search with multiple filed name with OR condition.
public ISolrQuery BuildQuery(string[] SearchFields, string SearchText)
{
try
{
AbstractSolrQuery firstQuery = new SolrQueryByField(SearchFields[0], SearchText) { Quoted = false };
for (var i = 1; i < parameters.SearchFields.Length; i++)
{
firstQuery = firstQuery || new SolrQueryByField(SearchFields[i], SearchText) { Quoted = false };
}
return firstQuery;
}
Upvotes: 1
Reputation: 99730
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\""))
Upvotes: 8