2013-03-14 55 views
2

我有一組文檔,其中包含發件人郵件ID和收件人郵件ID。如何在單個查詢中對兩個方面查詢的結果進行分組。

當我使用方面查詢如facet.field=senderemailid&facet.limit=10&facet.offset=0。所以,我可以得到總沒有通過相應的郵件ID發送郵件的

結果是

< INT NAME = 「[email protected]」> 157 < int>的

< INT NAME =」 [email protected]」> 141 < int>的

< INT名稱= 「[email protected]」> 32 < int>的


同樣,當我使用facet.field=recipientmailid&facet.limit=10&facet.offset=0時,我可以獲得由相應郵件ID收到的郵件總數。

結果是

< INT名稱= 「[email protected]」> 41 < int>的

< INT名稱= 「[email protected]」> 132 < int>的

< int name =「[email protected]」> 92 < int>

一旦我得到結果我使用java代碼來分組結果,即每個電子郵件ID收到多少個電子郵件,併發送了多少個no電子郵件。通過這種方式,我無法實現分頁。由於兩個結果在某些電子郵件ID上不同。

什麼是我的期望是,

< INT NAME = 「[email protected]」>

  <int> 32 <int> 

      <int> 132 <int> 

< INT NAME = 「[email protected]」>

所以一次我可以發送電子郵件&一次性收到電子郵件數。我不需要使用java代碼來分組結果。

是Solr中存在的任何方式來組織結果的Solr本身,這樣我就可以避開Java代碼組的結果,以及我能實現分頁

[注:recipientmailid和senderemailid都是必要的multivalued.If稍後我可以將senderemailid更改爲singlevalued.But收件人郵件Id應爲多值。]

回答

0

您可以多次使用facet.field,並且您將獲得facet結果,但它將是兩個單獨的對象。這樣你可以減少查詢到solr。 O/P將如下所示

"facet_counts":{ 
    "facet_queries":{}, 
    "facet_fields":{ 
     "sender":[ 
     "[email protected]",21, 
     "[email protected]",11, 
     "[email protected]",15, 
     "[email protected]",2], 
     "reciever":[ 
     "[email protected]",21, 
     "[email protected]",12, 
     "[email protected]",13, 
     "[email protected]",4], 

是的,你需要循環遍歷結果集至少一次!! 嘗試facet.pivot。 this可能會幫助你。這是solr4.0功能

相關問題