lucene学习之自定义评分
来源:互联网 发布:mmd极乐净土镜头数据 编辑:程序博客网 时间:2024/05/22 14:52
想要根据城市来自定义评分,原来的输出:
根据【你好.我是jack】 一共找到3文件
编号:0 分数: 1.0 id: 1 city: 北京编号:1 分数: 1.0 id: 2 city: 南京
编号:2 分数: 1.0 id: 3 city: 上海
自己新建的query对象:
public class MyFieldScoreQuery extends CustomScoreQuery{
public MyFieldScoreQuery(Query subQuery) {
super(subQuery);
}
@Override
protected CustomScoreProvider getCustomScoreProvider(LeafReaderContext context){
return new MyCustomScoreProvider(context);
}
}
覆盖customscoreprovider:
public class MyCustomScoreProvider extends CustomScoreProvider{
public MyCustomScoreProvider(LeafReaderContext context) {
super(context);
}
@Override
public float customScore(int doc, float subQueryScore, float valSrcScore) throws IOException {
IndexReader r = context.reader();
Document d = r.document(doc);
float score = subQueryScore;
if("上海".equals(d.get(“city”))){
score = score*100;
}
return score;
}
}
然后输出如下:
根据【你好.我是jack】 一共找到3文件
编号:2 分数: 100.0 id: 3 city: 上海
编号:0 分数: 1.0 id: 1 city: 北京
编号:1 分数: 1.0 id: 2 city: 南京
- lucene学习之自定义评分
- Lucene自定义评分查询
- Lucene的自定义评分
- lucene自定义评分域
- Lucene学习笔记之评分机制
- Lucene 3.6.2入门:高级搜索之自定义评分
- lucene实现自定义的评分
- Lucene 4.10.3自定义评分
- lucene评分
- Android学习之路----自定义RatingBar(评分控件)
- lucene学习之创建自定义排序
- Lucene学习记(1) Lucene的评分机制
- lucene3.6.2之自定义评分
- Lucene4.10使用教程(七):Lucene的自定义评分
- Lucene4.10使用教程(八):Lucene的自定义评分(2)
- Lucene4.10使用教程(七):Lucene的自定义评分
- Lucene4.10使用教程(八):Lucene的自定义评分(2)
- Lucene4.10使用教程(七):Lucene的自定义评分
- 安装完 NTFS for Mac 应用列表里没有
- 微信公众平台OAuth2.0网页授权php示例
- 【Leetcode】:319. Bulb Switcher 问题 in JAVA
- iterator迭代器和指针的区别
- oracle 更改服务端字符集 更改oracle字符集
- lucene学习之自定义评分
- TestNG 学习总结 - 测试结果报告 - HTML和XML报告(十七)
- n internal error occurred during: "Launching portal on Tomcat 7.x (1)". java.lang.NullPointerExcept
- PHP处理密码的几种方式
- javascript如何调用本地exe程序
- Android Studio打包混淆问题总结
- Linphone-android 3.9.1 编译
- 史上最浅显易懂的Git教程!
- 内存溢出和内存泄露、并行和并发、Minor GC和Full GC、Client模式和Server模式的区别