简体   繁体   English

按特定顺序对Lucene.net搜索结果进行排序

[英]Sorting Lucene.net search results in a specific order

We use Lucene.Net for a product search on a website. 我们使用Lucene.Net在网站上进行产品搜索。 For a category we fetch all products which have an exact match for field category with the categories unique id. 对于类别,我们获取所有与字段类别完全匹配且类别唯一ID完全匹配的产品。

For one client we have a requirement for the products to be listed in a specific order when there are no other criteria. 对于一个客户,如果没有其他条件,我们要求按照特定顺序列出产品。 These are arranged per category and a product can appear in multiple categories. 这些按类别排列,并且产品可以出现在多个类别中。 So we can't just have an global order field. 因此,我们不能只拥有一个全球订单字段。 My first thought for a solution that would work with out of the box Lucene.net was to have a field for each category on the products which will contain the sort order. 我首先想到的一种与开箱即用的Lucene.net兼容的解决方案是为产品上的每个类别都有一个字段,其中将包含排序顺序。 But this won't scale well if there are lots of categories. 但是,如果类别很多,这将无法很好地扩展。

Once a search term is entered or a facet is selected we then order the products by the best match using the regular scoring system. 输入搜索词或选择构面后,我们将使用常规评分系统按最匹配的顺序订购产品。 But when there is just a term query for a category we'd like to be able to sort them by a specific order. 但是,当仅对类别进行术语查询时,我们希望能够按特定顺序对它们进行排序。

Is there a way of doing this with a custom scorer that could accept a list of IDs or similar and score them based on that? 有没有一种方法可以使用自定义计分器来接受ID或类似ID的列表并根据其对它们进行计分? Essentially what we need to do is order the Lucene search results by an order specified in a database table or other external source. 本质上,我们需要做的是按照数据库表或其他外部源中指定的顺序对Lucene搜索结果进行排序。

This not an out of the box solution, we're using Open Search Server which I believe is a wrapper around the same search engine. 这不是开箱即用的解决方案,我们使用的是Open Search Server,我认为它是同一搜索引擎的包装。 We had similar requirements along with a whole bunch of other requirements (complex filtering/permissions/security) which drove us to cache the results from the search engine in a database (it would page through the results on a background thread and persist them to the DB), after that you can do joins between the search results and other tables in your db and do indexed sorts to your hearts content. 我们有类似的要求以及其他一系列要求(复杂的过滤/权限/安全性),这促使我们将搜索引擎的结果缓存到数据库中(它将在后台线程中分页结果并将其持久保存到数据库中。 DB),之后您可以在搜索结果和数据库中的其他表之间进行联接,并对您的内容进行索引排序。 Just a thought... 只是一个想法...

In a similar solution for a high traffic website, we did the sorting ourselves. 在高流量网站的类似解决方案中,我们自行进行了排序。 Lucene would find the results, then we sorted them on the fly and gave a paged result. Lucene将找到结果,然后我们对它们进行即时排序并给出分页的结果。 Most .net Sorting algorithms are efficient enough, but we used a Radix Sort ( http://en.wikipedia.org/wiki/Radix_sort ) to get it to perform to our liking. 大多数.net排序算法都足够有效,但是我们使用了Radix Sort( http://en.wikipedia.org/wiki/Radix_sort )使它能够按我们的喜好执行。


I'm using Elasticsearch which is based on Lucene, and the way I'm doing it , is to boost the fields that you want the elements to be ordered by. 我正在使用基于Lucene的Elasticsearch,并且这样做的方法是增强希望元素排序的字段。
a Second method is pure Javascript http://isotope.metafizzy.co/ , the elements are rendered on the fly then ordered by javascript , please see some examples , It might help you! 第二种方法是纯Javascript http://isotope.metafizzy.co/ ,动态渲染元素,然后按javascript排序,请参见一些示例,它可能会对您有所帮助! EDIT : ALL Relies on your logic : if you want to order by category : boost the category ! 编辑:全部取决于您的逻辑:如果要按类别订购:提升类别!

Scenario : user ask for category : Mobile , with normal scoring system let's say you have this results 场景:用户要求类别:移动,使用常规评分系统,假设您获得了此结果
: user looking for nokia :用户正在寻找诺基亚

product1 : category :car , title: nokia car ,score :3.34 产品1:类别:汽车,标题:诺基亚汽车,得分:3.34
product2 : category :appliance , title : cool nokia appliance : score 3.32 产品2:类别:电器,标题:酷诺基亚电器:得分3.32
product3 : category :mobile , title : Nokia 3310 : score 2.32 产品3:类别:手机,标题:诺基亚3310:得分2.32
product4 : category :mobile , title : Nokia 6600 : score 2.31 产品4:类别:移动设备,标题:诺基亚6600:得分2.31


now if the field category is boosted , You will have this : 现在,如果将字段类别提升,您将具有:
product1 : category :mobile , title: Nokia 3310 ,score :6.35 产品1:类别:移动电话,标题:诺基亚3310,得分:6.35
product2 : category :mobile , title : Nokia 6600 : score 6.32 产品2:类别:移动设备,标题:诺基亚6600:得分6.32
product3 : category :appliance , title : other nokia : score 2.32 产品3:类别:电器,标题:其他诺基亚:得分2.32
product4 : category :car , title : nokia car : score 2.31 产品4:类别:汽车,标题:诺基亚汽车:得分2.31

scores I used are arbitrary 我使用的分数是任意的

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

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