gpt4 book ai didi

solr - Solr 中的计数

转载 作者:行者123 更新时间:2023-12-04 15:01:40 27 4
gpt4 key购买 nike

我将以下文档存储在 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%';

提前致谢。

最佳答案

要使其工作(使用 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

    这个查询对我有用。它如何为您工作,取决于您的索引和它的大小。
    请询问您是否需要更多指导。

    关于solr - Solr 中的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12587832/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com