算上索尔

时间:2012-09-25 17:09:44

标签: solr

我在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%';

提前致谢。

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:3)

要使其有效(使用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

此查询适用于我。它对你有什么用,取决于你的索引和大小。 请询问您是否需要更多指导。