Reputation: 5464
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.
Upvotes: 6
Views: 20937
Reputation: 5488
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.
Upvotes: 4
Reputation: 26012
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.
Upvotes: 2