基于 Solr 规则的提升

Solr rule based boost

我正在使用 Solr-5.0.0。我正在搜索字段 product_name。 我需要添加一些规则才能获得相关结果。

  1. 如果我搜索一个词,如果存在完全匹配,它应该排在第一位。 例如:如果我搜索 laptop ,它应该首先 return 与 laptop 精确 product_name

  2. 如果我搜索一个以上的词,它应该遵守规则 1。随着最短的词长距离名称排在第一位。 例如:如果我搜索 dell laptop,它应该先 return Dell laptop 而不是 dell inspiron laptop.

  3. 如果我搜索单词,它 return 结果不应包含 withwithout 个单词。 例如:在搜索 laptop bag 时,它不应首先给出 dell laptop with bagdell laptop with bag 结果。

如何在查询时获得这些基于规则的搜索相关结果?

我的申请在 java,所以 Java 回答很感激。

首先,您应该使用 dismax or edismax query parser instead of the default (lucene).

然后您可以使用不同的参数提高相关性:

  1. :使用 qf 提升你的 product_name 场。
  2. :使用 pf 提升您的 product_name 字段,其中 q 参数中的所有术语都非常接近。
  3. :使用bq to boost documents where the words with or without don't appear. See here。例如:bq=(*:* -with -without)^999