根据字段值对Solr多值字段进行排序 [英] Sorting Solr multivalue fields based on field values

查看:595
本文介绍了根据字段值对Solr多值字段进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个具有单独架构的Solr实例.

I have multiple Solr instances with separate schemas.

我需要按排序顺序接收多值字段,例如按类型:火车站,机场,城市地区等:

I need to receive multivalue field in sorted order, e.g. by type: train_station, airport, city_district, and so on:

q=köln&sort=query({!v="type:(airport OR train_station)"}) desc

我想在train_station类型之前查看机场类型文档.现在,我总是总是在顶部获得train_station类型.

I would like to see airport type document before train_station type. For now I am always getting train_station type at the top.

我应该如何编写查询?

推荐答案

由于IDF,您在顶部获得train_station.

You are getting train_stations at the top because of the IDF.

要解决此问题的快速方法是使用范围查询(其优点是具有恒定的分数)并提高查询效率:q=köln&sort=query({!v="type:([airport TO airport]^3 OR [train_station TO train_station]^2)"}) desc.

A quick hack to fix it would be to use a range query (which has the advantage of having constant scores) and query boosts: q=köln&sort=query({!v="type:([airport TO airport]^3 OR [train_station TO train_station]^2)"}) desc.

这样,在类型字段中具有airport的文档将得到3分,在类型字段中具有train_station的文档将得到2分,并且具有airporttrain_station的文档在他们的字段类型中得分为2 + 3 = 5(乘以常数).

This way, documents which have airport in their type field will have a score of 3, documents which have train_station in their type field will have a score of 2 and documents which have airport and train_station in their field type will have a score of 2+3=5 (to a multiplicative constant).

一种更优雅(更有效)的方式是编写自定义查询解析器(甚至是函数查询).

A more elegant (and effective) way of doing this would be to write a custom query parser (or even a function query).

这篇关于根据字段值对Solr多值字段进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆