2016-08-12 20 views
0

我正在使用Spring Solr和Groovy。Spring Solr助推問題

當我嘗試提高結果時遇到問題。

解釋一下,考慮一個簡化的在線購物域,其索引實體是Product。

用戶有一個shoppingBasket和一個wishList,每個都是簡單的產品代碼清單(即列表<字符串>)。首先處理兩個列表以確保它們是獨特和獨特的。

一個簡單的搜索可能是產品文本中的關鍵字字符串(使用copyField製作的複合字段,包含其描述和標題)。

要求是讓結果列出每個產品的關鍵字在其文本中與首先顯示的shoppingBasket中顯示的任何商品相匹配,然後是wishList中的所有商品,然後是其他任何商品。

遇到的問題是,儘管wishList和shoppingBasket分組發生了一些提升,但wishByList匹配之前並不總是顯示shoppingBasket匹配。

根據不同的產品在每一個列表,有時顯示的順序:

所有的心願一致,所有shoppingBasket匹配,所有其他比賽

,而不是預期:

所有shoppingBasket匹配,所有wishList匹配,所有其他匹配

使用以下標準應用助推:

boostingCriteria = new Criteria('productCode_s').in(shoppingBasket).boost(2.0f) 
boostingCriteria = boostingCriteria.or(
     new Criteria('productCode_s').in(wishList).boost(1.0f)) 

看到這個similar issue我註釋了一個正在被添加到PageRequest中的排序,這沒有什麼區別。

我還使用@Score註釋將分數包括在返回的結果中。檢查這些,我可以看到solr給shoppingBasket或wishList中的所有匹配賦予相同的分數。除了這些列表之外的所有匹配得到另一個較低的分數(它們之間相同)。

嘗試了不同的升壓值(分別爲10000.0f和5000.0f)無濟於事。它確實產生了不同的分數,但它在shoppingBasket或wishList中的所有匹配之間仍然是相同的。

即使將搜索簡化爲僅僅是提升標準,排序仍然沒有。

任何想法,將不勝感激。

回答

0

通過試驗和錯誤我發現解決方案是使用.connect()方法如下。

boostingShoppingBasket = new Criteria('productCode_s').in(shoppingBasket).boost(10.0f).connect() 
boostingWishList = new Criteria('productCode_s').in(wishList).boost(2.0f).connect() 

然後把這些放在一起。

如果還有其他搜索條件也適用(例如,產品描述包含特定的文本),在與連接打包之前,這些必須與提升標準進行「與」運算,以便在更復雜的情況下,我最終會得到以下結果(假設createSearchCriteria(searchCommand)方法返回基本搜索標準):

boostingShoppingBasket = new Criteria('productCode_s').in(shoppingBasket).boost(10.0f) 
boostingShoppingBasket = boostingShoppingBasket.and(createSearchCriteria(searchCommand)).connect() 

boostingWishList = new Criteria('productCode_s').in(wishList).boost(2.0f) 
boostingWishList = boostingWishList.and(createSearchCriteria(searchCommand)).connect() 

Criteria criteria = createSearchCriteria(searchCommand) 
    .or(boostingShoppingBasket).or(boostingWishList)