I am storing the following document in Solr:
doc {
id: string; // this is a unique string that looks like an md5 result
job_id: string; // this also looks like an md5 result -- this is not unique
doc_id: number; // this is a long number -- this is not unique
text: string; // this is stored, indexed text -- this is not unique
}
Now what I want to do is count the number of docs (doc_id) that have the text foo in them. So if this was SQL I would want to issue something like this:
SELECT count(distinct doc_id)
FROM Doc
WHERE text like '%foo%';
Thanks in advance.
To make it work (using Result Grouping/Filed collapsing) you need some conditions to fulfil.
Then you can make request like that:
/select/?q=foo&rows=0&group=true&group.field=doc_id_str&group.limit=0&group.ngroups&group.format=simple&wt=json
This query works for me. How would it work for you, depends on your index and size of it. Please ask if you need some more guidance.
Similar operation to count (distinct fieldName)
is not possible in Solr right now. There are issues (SOLR-1814 and SOLR-2242) related to this problem in Jira. Maybe reading comments in the issues will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With