6

我在 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
  }

现在我要做的是计算其中包含文本 foo 的文档(doc_id)的数量。所以如果这是 SQL,我想发出这样的问题:

SELECT count(distinct doc_id)
FROM Doc
WHERE text like '%foo%';

提前致谢。

4

2 回答 2

4

要使其工作(使用Result Grouping/Filed collapsing),您需要满足一些条件。

  • 您必须使您的文本查询 ("%foo%") 在常规搜索中工作
  • doc_id 必须是字符串,您可以拥有该字段的副本并将其称为 doc_id_str

然后你可以提出这样的请求:

/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.

于 2012-09-26T10:21:56.660 回答
2

count (distinct fieldName)目前在 Solr 中无法进行类似的操作。Jira 中存在与此问题相关的问题(SOLR-1814SOLR-2242 )。也许阅读问题中的评论会对您有所帮助。

于 2012-09-26T06:24:29.547 回答