Lucene:如何提升某些特定领域 [英] Lucene: how to boost some specific field

查看:65
本文介绍了Lucene:如何提升某些特定领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就我而言,文档具有两个字段,例如标题"和视图". 视图"代表人们访问此文档的次数.例如:标题":"iphone",观看次数":"10". 我必须制定一种策略,为视图分配一些权重,例如,相关性分数是根据score(title)* 0.8 + score(views)* 0.2计算得出的. lucene可以做到这一点吗?我想知道是否存在与此问题相关的算法.

In my case, documents have two fields, for example, "title" and "views". "views" is represented the num of times that people have visited this document. like: "title":"iphone", "views":"10". I have to develop a strategy that will assign some weights to views, such as the relevance score is calculated by score(title)*0.8+score(views)*0.2. Does lucene can do this? And I want to know whether there are some algorithms related to this question.

推荐答案

这是您可以执行的操作:

Here is how you can do that:

Query titleQuery, viewsQuery;

titleQuery.setBoost(0.8);
viewsQuery.setBoost(0.2);
BooleanQuery query = new BooleanQuery();
query.add(titleQuery, Occur.MUST); // or Occur.SHOULD if this clause is optional
query.add(viewsQuery, Occur.SHOULD); // or Occur.MUST if this clause is required

// use query to search documents

分数将与0.8*score(titleQuery) + 0.2*score(viewsQuery)成正比(与乘法常数成正比).

The score will be proportional to 0.8*score(titleQuery) + 0.2*score(viewsQuery) (to a multiplicative constant).

要利用您的views字段,您可能需要使用

To leverage your views field, you will probably need to use a ValueSourceQuery.

这篇关于Lucene:如何提升某些特定领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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