I am looking to return the search term hit count through the solr result object when I fire off a query to solr. I have tried using the term vector option in the solrconfig however this has not returned the count back.
I am using pysolr to fire off the requests from my django site, I have written a method in python to do the term count based on the number of tags returned in the highlighting sections of the results object. However this does not scale very well (using regex against millions of document results) hence why I am looking for an alternative solution.
I expect solr to return a dictionary of some kind with the document as the key and the term count as the value, something similar to how it returns highlighted values. If this is possible, what would i need to edit in the solrconfig? If not, is there a better way to do a term count other than using regex?
Current functions doing the count-
comp_doc = []
for k, v in results.iteritems():
reg = re.findall('<em class="highlighting">(.*?)</em>', str(v.values()).lower())
counter = dict(Counter(reg))
comp_dict = {}
comp_dict['terms'] = counter
comp_dict['key'] = k
comp_doc.append(comp_dict)
return comp_doc
Thanks for your help