2011-05-01 67 views
2

我使用Solr製作了基於asp.net的solrnet產品目錄,到目前爲止,所有工作都非常順利。我需要通過添加一些分組選項來擴展搜索結果。Solr/SolrNet分組結果

首先,我將解釋如何架構看起來像:

<field name="product_id" type="string" indexed="true" stored="true" required="true" /> 
<field name="name" type="string" indexed="true" stored="true"/> 
<field name="merchant" type="string" indexed="true" stored="true"/> 
<field name="merchant_id" type="int" indexed="false" stored="true"/> 
<field name="merchant_logo" type="string" indexed="false" stored="true"/> 
<field name="brand" type="string" indexed="true" stored="true"/> 
<field name="brand_id" type="int" indexed="false" stored="true"/> 
<field name="group_id" type="int" indexed="true" stored="true"/> 
<field name="group_name" type="string" indexed="true" stored="true"/> 
<field name="has_group" type="boolean" indexed="true" stored="true"/> 

所以當你看到上面的產品有一個「GROUP_ID」和「組名」我也有一個名爲布爾標誌「有組」在我的模式上。

這裏有一些產品的例子導致

Product A – group id 1 - group Name 1 – has group true 
Product B – group id 1 - group Name 1 – has group true 
Product C – group id 2 - group Name 2 – has group true 
Product D – group id 2 - group Name 2 – has group true 
Product E – has group false 
Product F – has group false 

但是當我展示這些成果,我需要它的組名顯示在頂部的結果組名稱(或ID)的產品。並且不屬於一個組的產品將在組之後列出。

所以我的結果應該是這樣的:

Group Name 1 
Group Name 2 
Product E 
Product F 

事實上,我需要實現分頁一樣,所以換句話說,當有人搜索某一產品,如果產品中含有組名,我會一一列舉在結果和其他產品之上。

這甚至可能嗎?如果可能的話,我需要做些什麼。我已經閱讀過有關Solr中的FieldCollapsing,但我仍然不知道這是否正確的方法http://wiki.apache.org/solr/FieldCollapsing

+0

分組是否影響結果或僅用於顯示? (即只顯示Solr返回的組) – 2011-05-01 16:53:41

+0

當前當我現在搜索產品時,它的工作方式是混合具有組數據的產品和沒有組數據的產品。基本上,當我打印產品結果時,我需要先打印產品組名稱(只有組名),然後再打印其他產品。 Solr本身是否支持分組Solr結果?因爲我需要使用分頁結果以及分面。所以可能是我正在尋找的是用於分組的Solr查詢。 – randika 2011-05-01 18:18:29

+0

我問的是:你需要在整個索引中分組結果嗎?或者只在一個結果頁面內? – 2011-05-01 18:24:18

回答

0

是的,如果您想對整個索引進行分組,您需要field collapsing功能。 SolrNet對此的支持目前已被打破,因爲它是Solr中的一個未發佈的特性,並且自SolrNet首次實施以來發生了很大變化。有關詳細信息和更新,請參閱http://code.google.com/p/solrnet/issues/detail?id=127

+0

好吧,好像SoltNet的分組選項在主幹上不可用,但它仍然可用在solr的基礎上。 - 無論如何,你被問到是否需要這樣做,通過索引或僅用於顯示?你認爲無論如何,我可以將它們從顯示級別分組。謝謝。 – randika 2011-05-03 07:38:57

+0

@randika:如果你想在整個索引中分組,你需要服務器端支持(來自Solr和SolrNet)。如果您只想在單個結果頁中進行分組,則可以使用LINQ輕鬆完成。 – 2011-05-03 12:53:10

+0

嗨Mauricio,由於字段崩潰不可用作爲Solr的穩定版本,因此我們決定不使用它,而是我們決定在同一索引上對「groups」進行索引。所以當我們現在搜索時,我們可以列出產品和組名。所以它的工作。但是我們仍然無法在結果頂部顯示組名。 – randika 2011-05-07 09:27:28