Solr 自定义排序[1]

需求:商品排序,无库存的商品排在后面(排序)。

搜索:

 默认搜索:                                            df:

      

可以看出左图第1个、第6个库存为0.

现在的需求是想将这两个库存为0的商品排在最后面。

edismax-》bf:product(map(store,1,9999999,1),100) ,效果如右图。

store map的规则:

store=0,v(store)=0;

store>0,v(store)=1;(默认store的最大值999999999)

product*100,为了突显加权的效果。(可忽略)

观察打分的细节:

 <str name="92011786">
12.634275 = (MATCH) sum of:
  2.0679202 = (MATCH) sum of:
    1.2457463 = (MATCH) weight(searchField:165 in 18377) [DefaultSimilarity], result of:
      1.2457463 = score(doc=18377,freq=2.0 = termFreq=2.0
), product of:
        0.77180904 = queryWeight, product of:
          7.3044024 = idf(docFreq=78, maxDocs=43211)
          0.105663545 = queryNorm
        1.6140602 = fieldWeight in 18377, product of:
          1.4142135 = tf(freq=2.0), with freq of:
            2.0 = termFreq=2.0
          7.3044024 = idf(docFreq=78, maxDocs=43211)
          0.15625 = fieldNorm(doc=18377)
    0.82217383 = (MATCH) weight(searchField:清爽 in 18377) [DefaultSimilarity], result of:
      0.82217383 = score(doc=18377,freq=2.0 = termFreq=2.0
), product of:
        0.6270135 = queryWeight, product of:
          5.934057 = idf(docFreq=310, maxDocs=43211)
          0.105663545 = queryNorm
        1.3112538 = fieldWeight in 18377, product of:
          1.4142135 = tf(freq=2.0), with freq of:
            2.0 = termFreq=2.0
          5.934057 = idf(docFreq=310, maxDocs=43211)
          0.15625 = fieldNorm(doc=18377)
  10.566355 = (MATCH) FunctionQuery(product(map(int(store),1.0,9999999.0,const(1)),const(100))), product of:
    100.0 = product(map(int(store)=10,min=1.0,max=9999999.0,target=const(1)),const(100))
    1.0 = boost
    0.105663545 = queryNorm
</str>

从上可以大致看出总分12.634275为文本分2.0679202加上库存加分10.566355。



扩展阅读:

http://wiki.apache.org/solr/DisMax

DisMax is an abbreviation Disjunction Max, and is a popular query mode with Solr.

Simply put, it‘s your choice for all user generated queries.

Out of the box, Solr uses the standard Solr query parser which is pretty stupid, understanding only syntactically correct boolean queries like "title:foo OR body:foo", it can only search one field by default, and it may very well throw an exception in your face if you put in some characters it does not like.

Therefore a new, more robust query mode was needed and the DisMax and ExtendedDisMax Query Parsers were born. They are designed to process simple user entered phrases (without heavy syntax) and search for the individual words across several fields using different weighting (boosts) based on the significance of each field, and it should never throw an exception.

Disjunction refers to the fact that your search is executed across multiple fields, e.g. title, body and keywords, with different relevance weights

Max means that if your word "foo" matches both title and body, the max score of these two (probably title match) is added to the score, not the sum of the two as a simple OR query would do. This gives more control over your ranking.

DisMax is usually the short name for the actual query parser, so don‘t be confused. The old DisMax parser has been around for some time, while the new and more advanced ExtendedDisMax parser was introduced in  Solr3.1 as experimental.

There is a Lucid Imagination Blog post that explains the origins and conceptual behavior of dismax functionality.



FunctionQuery:

http://wiki.apache.org/solr/FunctionQuery#map

ExtendedDisMax[edisMax]:

http://wiki.apache.org/solr/ExtendedDisMax

时间: 2024-08-09 22:53:49

Solr 自定义排序[1]的相关文章

一步一步跟我学习lucene(13)---lucene搜索之自定义排序的实现原理和编写自己的自定义排序工具

自定义排序说明 我们在做lucene搜索的时候,可能会需要排序功能,虽然lucene内置了多种类型的排序,但是如果在需要先进行某些值的运算然后在排序的时候就有点显得无能为力了: 要做自定义查询,我们就要研究lucene已经实现的排序功能,lucene的所有排序都是要继承FieldComparator,然后重写内部实现,这里以IntComparator为例子来查看其实现: IntComparator相关实现 其类的声明为 public static class IntComparator exte

solr特点三: 基于Solr实现排序定制化参考

排序实现有N种形式,最低成本.最快响应时间是目标 一份索引,支持N种排序策略并且在线互不干扰是要考虑的每一种实现,处理的场景是不同的,不要千篇一律 020排序,从索引到效果,有不少坑,这篇文章没有细说,原因是有些内容不好公开 几点基础概念回顾 (1)排序定制化不同于实现业务排序. 实现业务排序可以是查阶段,通过boost.各种func 组合.离线score等单独或者组合实现排序目标,        或者索引构建阶段的 field boost.document boost        或者索引构

定制对ArrayList的sort方法的自定义排序

java中的ArrayList需要通过collections类的sort方法来进行排序 如果想自定义排序方式则需要有类来实现Comparator接口并重写compare方法 调用sort方法时将ArrayList对象与实现Commparator接口的类的对象作为参数 示例: // 外部类的方式 import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.uti

MapReduce 学习4 ---- 自定义分区、自定义排序、自定义组分

1. map任务处理 1.3 对输出的key.value进行分区. 分区的目的指的是把相同分类的<k,v>交给同一个reducer任务处理. public static class MyPartitioner<Text, LongWritable> extends Partitioner<Text, LongWritable>{ static HashMap<String,Integer> map = null; static{ map = new Hash

Java集合框架实现自定义排序

Java集合框架针对不同的数据结构提供了多种排序的方法,虽然很多时候我们可以自己实现排序,比如数组等,但是灵活的使用JDK提供的排序方法,可以提高开发效率,而且通常JDK的实现要比自己造的轮子性能更优化. 一 .使用Arrays对数组进行排序 Java API对Arrays类的说明是:此类包含用来操作数组(比如排序和搜索)的各种方法. 1.使用Arrays排序:Arrays使用非常简单,直接调用sort()即可 int[] arr = new int[] {5,8,-2,0,10}; Array

php多维数组自定义排序 uasort()

php内置的排序函数很多:正反各种排: 常用的排序函数: sort() - 以升序对数组排序rsort() - 以降序对数组排序asort() - 根据值,以升序对关联数组进行排序ksort() - 根据键,以升序对关联数组进行排序arsort() - 根据值,以降序对关联数组进行排序krsort() - 根据键,以降序对关联数组进行排序 基本都能满足需求了:关于这些函数的使用方法就不多啰嗦了: 但是在项目的实际开发中还是会有些更加苛刻的排序需求:今天要介绍的排序函数是: uasort() ua

Hadoop之--&gt;自定义排序

data: 3 33 23 12 22 11 1 --------------------- 需求: 1 12 12 23 13 23 3 package sort; import java.io.IOException; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path

Lucene - CustomScoreQuery 自定义排序

在某些场景需要做自定义排序(非单值字段排序.非文本相关度排序),除了自己重写collect.weight,可以借助CustomScoreQuery. 场景:根据tag字段中标签的数量进行排序(tag字段中,标签的数量越多得分越高) public class CustomScoreTest { public static void main(String[] args) throws IOException { Directory dir = new RAMDirectory(); Analyze

python 自定义排序函数

自定义排序函数 Python内置的 sorted()函数可对list进行排序: >>>sorted([36, 5, 12, 9, 21]) [5, 9, 12, 21, 36] 但 sorted()也是一个高阶函数,它可以接收一个比较函数来实现自定义排序,比较函数的定义是,传入两个待比较的元素 x, y,如果 x 应该排在 y 的前面,返回 -1,如果 x 应该排在 y 的后面,返回 1.如果 x 和 y 相等,返回 0. 因此,如果我们要实现倒序排序,只需要编写一个reversed_c