2010-06-03 28 views
7

我們必須在這裏我們通過一個特定的領域需要我們組的記錄,並採取相應的數字字段Apache Solr實現:數據的總和源於組由

e.x.之和的要求根據用戶標識從user_action組中選擇用戶標識符,總和(click_count);

我們正在努力做到這一點使用Apache Solr實現,發現有2種方式這樣做的:

  1. 使用字段倒塌功能(http://blog.jteam.nl/2009/10/20/result-grouping-field-collapsing-with-solr/),但發現兩個問題與此: 1.1。這不是版本的一部分,可以作爲補丁提供,所以我們不確定我們是否可以在生產中使用它。 1.2。我們沒有收回這筆款項,而是單獨計算,我們需要在客戶端進行總結。

  2. 使用Stats Component和分面搜索(http://wiki.apache.org/solr/StatsComponent)。這符合我們的要求,但對於非常大的數據集來說還不夠快。

我只是想知道是否有人知道任何其他方式來實現這一點。 感謝任何幫助。

謝謝,

Terance。

+0

數據集有多大?你是否分割索引? – 2010-06-03 17:36:47

+0

我認爲你應該嘗試以第二種方式進行基準測試。從Solr 1.4開始,分面非常快。 – 2010-06-06 06:30:13

回答

5

爲什麼不使用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>