标签:
Constructor Summary | |
---|---|
CustomScoreQuery(Query subQuery) Create a CustomScoreQuery over input subQuery. |
|
CustomScoreQuery(Query subQuery, Query... scoringQueries) Create a CustomScoreQuery over input subQuery and a FunctionQuery . |
|
CustomScoreQuery(Query subQuery, Query scoringQuery) Create a CustomScoreQuery over input subQuery and a FunctionQuery . |
通过重写getCustomScoreProvider(AtomicReaderContext)修改评分计算方法
1、原有评分*传入的评分域打分
1 Query subquery = new TermQuery(new Term("content", "java"));
2 //评分域
3 ValueSource valueSource = new IntFieldSource("score");
4 FunctionQuery fq = new FunctionQuery(valueSource );//自定义评分query
5 //自定义评分query
6 MyCustomScoreQuery myCustomScoreQuery = new MyCustomScoreQuery(subquery ,fq );
7
8 private class MyCustomScoreQuery extends CustomScoreQuery {
9
10 public MyCustomScoreQuery(Query subQuery , FunctionQuery fq) {
11 super(subQuery ,fq );
12 // TODO Auto-generated constructor stub
13 }
14
15 protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext reader ) throws IOException {
16 return super .getCustomScoreProvider(reader);
17 }
18 }
1 private class MyCustomScoreQuery extends CustomScoreQuery {
2
3 public MyCustomScoreQuery(Query subQuery , FunctionQuery fq) {
4 super(subQuery ,fq );
5 // TODO Auto-generated constructor stub
6 }
7
8 protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext reader ) throws IOException {
9 //return super.getCustomScoreProvider(reader);
10 return new MyCustomScoreProvider(reader);
11 }
12 }
13
14 private class MyCustomScoreProvider extends CustomScoreProvider {
15 public MyCustomScoreProvider(AtomicReaderContext reader){
16 super(reader );
17 }
18
19 public float customScore(int doc, float subQueryScore, float valSrcScore) throws IOException{
20 //return super.customScore(doc, subQueryScore, valSrcScore);
21 return subQueryScore /valSrcScore;
22 }
23 }
标签:
原文地址:http://www.cnblogs.com/Sheeeeep/p/4648792.html