I'm working on eCommerce site which is based on ASP.NET MVC3 C#. I've implemented SolrNet in it. There are two fields like "CategoryId" and "ProductName" . I want to search keyword in particular CategoryIDs. Note that products are mapped in multiple category. So basically I'm trying to search using solr admin by making below query but did not get exact result.
(CategoryID:26 AND Name:Gigabyte) OR (CategoryID:118 AND Name:Gigabyte) OR (CategoryID:121 AND Name:Gigabyte)
What is wrong in query? What will be query if I want to search same product name in limited category?
I would take advantage of the Filter Query in Solr to limit the results by the CategoryID in the example you have given. So from the Solr Admin page, click on the Full Interface link under the "Make a Query" section and enter the following:
Query String:
Name:Gigabyte
Filter Query:
(CategoryId:26 OR CategoryId:118 OR CategoryId:121)
You can do the same thing from SolrNet via the following:
ISolrOperations<Item> solr = ...
var items = solr.Query(new SolrQueryByField("name","Gigabyte", new QueryOptions {
FilterQueries = new ISolrQuery[] {
new SolrQueryByField("CategoryID", 26),
new SolrQueryByField("CategoryID", 118),
new SolrQueryByField("CategoryID", 121),
}
});