-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctfScorer.java
62 lines (51 loc) · 2.01 KB
/
ctfScorer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* COPYRIGHT (C) 2015 Gavin Ruddy. All Rights Reserved. */
/**
* Document scorer using click data from queries in ctfBse, stored in ctfDataHandler.
* @author Gavin Ruddy
* contact [email protected]
* @version 1.0.1 2015/8/01
*/
package com.ctf;
import java.io.IOException;
import org.apache.lucene.search.Query;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queries.CustomScoreProvider;
import org.apache.lucene.queries.CustomScoreQuery;
import org.apache.lucene.document.Document;
public class ctfScorer extends CustomScoreQuery {
public ctfScorer(Query subQuery) {
super(subQuery);
//this.setStrict(true);
}
protected CustomScoreProvider getCustomScoreProvider(LeafReaderContext context) throws IOException {
return new ctfScoreProvider(context);
}
class ctfScoreProvider extends CustomScoreProvider {
ctfDataHandler dh = new ctfDataHandler();
public ctfScoreProvider(LeafReaderContext context) {
super(context);
}
public float customScore(int doc, float subQueryScore, float valSrcScore) throws IOException {
return customScore(doc, subQueryScore, new float[]{valSrcScore});
}
public float customScore(int doc, float subQueryScore, float[] valSrcScores) throws IOException {
Document d = context.reader().document(doc);
String docID = (d.get(dh.getDOCID())).toString();
float docScore = subQueryScore;
for (float valSrcScore : valSrcScores) {
docScore *= valSrcScore;
}
float score = docScore;
float tieBreak = dh.getREORDER() ? 1.00001f : 1f;
if ( dh.getPrimaryObj().indexOf(docID) > -1 ) {
score = dh.getClickBoost(docID) * docScore * tieBreak;
}
else if ( dh.getSecondaryObj().indexOf(docID) > -1 ) {
score = dh.getClickBoost(docID) * dh.getInitDocScores( dh.getParent(docID) );
}
dh.addDocScore(docID,score);
return score;
}
}
}