我们有一个要求,需要按特定字段对记录进行分组,并获取相应数字字段的总和
前任。 select userid, sum(click_count) from user_action group by userid;
我们尝试使用 apache solr 来做到这一点,发现有两种方法可以做到这一点:
使用字段折叠功能(http://blog.jteam.nl/2009/10/20/result-grouping-field-collapsing-with-solr/ http://blog.jteam.nl/2009/10/20/result-grouping-field-collapsing-with-solr/)但发现有两个问题:
1.1.这不是发布的一部分,而是作为补丁提供,因此我们不确定是否可以在生产中使用它。
1.2.我们不会取回总和,但会计算个人数量,我们需要在客户端对其进行求和。
使用统计组件以及分面搜索(http://wiki.apache.org/solr/StatsComponent http://wiki.apache.org/solr/StatsComponent)。这满足了我们的要求,但对于非常大的数据集来说还不够快。
我只是想知道是否有人知道任何其他方法来实现这一目标。
感谢任何帮助。
Thanks,
Terance.
为什么不使用 StatsComponent? - Solr 1.4 及以上版本可用。
$ curl 'http://search/select?q=*&rows=0&stats=on&stats.field=click_count' |
tidy -xml -indent -quiet -wrap 2000000
<?xml version="1.0" encoding="utf-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">17</int>
<lst name="params">
<str name="q">*</str>
<str name="stats">on</str>
<arr name="stats.field">
<str>click_count</str>
</arr>
<str name="rows">0</str>
</lst>
</lst>
<result name="response" numFound="577" start="0" />
<lst name="stats">
<lst name="stats_fields">
<lst name="click_count">
<double name="min">1.0</double>
<double name="max">3487.0</double>
<double name="sum">47912.0</double>
<long name="count">577</long>
<long name="missing">0</long>
<double name="sumOfSquares">4.0208702E7</double>
<double name="mean">83.0363951473137</double>
<double name="stddev">250.79824725438448</double>
</lst>
</lst>
</lst>
</response>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)