: I wanted to know if Solr has some functionality to group results based on : the field that matched the query. : : So if I have id, name and manufacturer in my document structure, I want to : know how many results are there because its manufacturer matched the q and : how many results are there because q matched the name field.
there's a difference between *grouping* results by a query, and *counting* which sbset of your request match your query. in generla, it sounds like you are probably currently using something like dismax or edismax to search across multiple fields, ala... ? defType=dismax & qf=name manufacturer & q=user input if you want to count how many of each of those docs match the user input in either name or manuacturer, you can use "facet.query" and take advantage of local params to refer back to the users main query input... & facet=true & facet.query={!field f=manufacturer v=$q} & facet.query={!field f=name v=$q} ...however i'ts important to note that those counts won't neccessary add upto your numFound because some docs may match on multiple fields ... you may also not get any counts if your main query string is something complex, in qhich case you may want to ignore the local param (v=$q) and explicitly specify what the various facet.queries are. likewise, if you truely want to *group* the results based on querying on a specific field, you can use group.query instead... https://wiki.apache.org/solr/FieldCollapsing -Hoss