简体   繁体   English

Spring Solr提振问题

[英]Spring Solr boosting issue

Am using Spring Solr with Groovy. 我在Groovy中使用Spring Solr。

Have an issue when I try to boost results. 当我尝试提高结果时遇到问题。

To explain, consider a simplified online shopping domain, where the indexed entity is Product. 为了说明,考虑一个简化的在线购物域,其中索引实体为产品。

The user has a shoppingBasket and a wishList, each of which are simple Lists of Product codes (ie List<String>). 用户有一个shoppingBasket和wishList,它们都是产品代码的简单列表(即List <String>)。 The two Lists are first processed to ensure they are distinct and unique. 首先处理这两个列表,以确保它们是独特的。

A simple search might be for a keyword String in the Products' text (a composite field made using copyField, containing its description and title). 一个简单的搜索可能是在产品的文本(使用copyField组成的复合字段,包含其描述和标题)中搜索关键字String。

The requirement is for the results to list every Product where the keyword is matched in its text with any of those that are in the shoppingBasket displayed first, then any that are in the wishList, followed by any others. 要求结果是列出每个关键字在文本中与首先显示在shoppingBasket中的关键字匹配的产品,然后列出wishList中的任何关键字,然后列出其他任何产品。

The issue encountered is that although some boosting is taking place and results from the wishList and shoppingBasket each grouped, the shoppingBasket matches are not always displayed ahead of the wishList matches. 遇到的问题是,尽管正在进行一些提升,并且将wishList和shoppingBasket分别分组,但shoppingBasket匹配并不总是显示在wishList匹配之前。

Depending on the products in each List, it sometimes displays in the order: 根据每个列表中的产品,有时会按以下顺序显示:

all wishList matches, all shoppingBasket matches, all other matches 所有wishList匹配项,所有shoppingBasket匹配项,所有其他匹配项

instead of the expected: 而不是预期的:

all shoppingBasket matches, all wishList matches, all other matches 所有shoppingBasket比赛,所有wishList比赛,所有其他比赛

The boosting is applied using these criteria: 提升使用以下标准进行:

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

Having seen this similar issue I commented out a Sort that was being added to the PageRequest, that made no difference. 看到类似的问题后,我评论了要添加到PageRequest中的Sort,这没有什么区别。

I also used the @Score annotation to include the score in the results returned. 我还使用@Score批注将分数包含在返回的结果中。 Inspecting those, I can see that solr gives the same identical score to all matches in either the shoppingBasket or wishList. 检查这些,我可以看到solr对shoppingBasket或wishList中的所有匹配项给出相同的分数。 All matches outside of those lists get another lower score (identical between them). 这些列表之外的所有比赛都获得另一个较低的分数(它们之间相同)。

Have tried different values for the boosts (10000.0f and 5000.0f respectively) to no avail. 尝试使用不同的增强值(分别为10000.0f和5000.0f)无济于事。 It did produce a different score but it was still identical between all matches in either the shoppingBasket or wishList. 它的确产生了不同的得分,但在shoppingBasket或wishList中的所有匹配之间仍然相同。

Even simplifying the search down to just the boosting criteria alone, the ordering is still out. 即使仅将搜索简化为仅增强标准,其排序仍然不可行。

Any ideas would be appreciated. 任何想法,将不胜感激。

Through trial and error I found the solution was to use the .connect() method as follows. 通过反复试验,我发现解决方案是使用.connect()方法,如下所示。

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

Then OR these together. 然后或这些在一起。

Where there were other search criteria to apply too (eg that the product description contained certain text), these had to be ANDed with the boosting criteria before wrapping with the connect, such that in the more complex situation, I'd end up with the following (assuming the createSearchCriteria(searchCommand) method returns the basic search criteria): 如果还有其他搜索条件要应用(例如,产品描述中包含某些文本),则在与连接包装之前,必须将这些条件与提升条件进行“与”运算,这样,在更复杂的情况下,我最终会得到以下内容(假设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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM