2012-10-05 26 views
2

我們正在運行Solr 3.6並試圖對結果集應用條件排序。爲了澄清,數據是一組出價,並且我們希望添加按當前用戶的出價排序的選項,因此它不能用作常規排序(因爲對於運行查詢的每個用戶,出價都會不同)。Solr中的條件排序3.6

在結果集中的文件包括「CurrentUserId」和「CurrentBid」字段,所以我認爲,我們需要像下面的排序:

排序=((CurrentUserId = 12345)CurrentBid:0)說明

這僅僅是僞代碼,但這個想法是,如果currentUserId Solr中的用戶ID(12345在這個例子中)匹配,然後排序CurrentBid,否則,只是使用0.1

好像做按查詢排序可能是實現這一目標(或者至少構成解決方案的一部分)的方式,使用類似於以下NG查詢:

http://localhost:8080/solr/select/?q=:&sort=query(CurrentUserId:10330 AND CurrentBid:[1 TO *])+desc

這似乎並不雖然要爲我工作,並導致以下錯誤:

sort param could not be parsed as a query, and is not a field that exists in the index: ...

Solr documentation表示查詢功能,可用於作爲從Solr 1.4開始的排序參數,所以這看起來應該起作用。

任何有關如何實現這一目標的建議將不勝感激。

回答

3

根據您提供的Solr的文檔鏈接,

Any type of subquery is supported through either parameter dereferencing $otherparam or direct specification of the query string in the LocalParams via "v".

因此,基於這些示例和您的查詢,我認爲一個或兩個以下的應工作:

http://localhost:8080/solr/select/?q=:&sort=query($qq)+desc&qq=(CurrentUserId:10330 AND CurrentBid:[1 TO *])

http://localhost:8080/solr/select/?q=:&sort=query({v='CurrentUserId:10330 AND CurrentBid:[1 TO *]'})+desc

+0

這工作,讓我更接近解決方案。還需要弄清楚投標中的因素如何影響排序順序,但我現在認爲這個答案已被接受,因爲這是一個好的開始。謝謝你的幫助。 – Mun