Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CustomModul;
- import java.io.IOException;
- import org.apache.lucene.index.LeafReaderContext;
- import org.apache.lucene.index.IndexReader;
- import org.apache.lucene.index.Terms;
- import org.apache.lucene.queries.CustomScoreProvider;
- import org.apache.lucene.queries.CustomScoreQuery;
- import org.apache.lucene.search.Query;
- public class CountingQuery extends CustomScoreQuery {
- public CountingQuery(Query subQuery) {
- super(subQuery);
- }
- public class CountingQueryScoreProvider extends CustomScoreProvider {
- String _field;
- public CountingQueryScoreProvider(String field, LeafReaderContext context) {
- super(context);
- _field = field;
- }
- public float customScore(int doc, float subQueryScore, float valSrcScores[]) throws IOException {
- IndexReader r = context.reader();
- //getTermVector returns Null
- Terms vec = r.getTermVector(doc, _field);
- //*TO-DO* Algorithm
- return (float)(1.0f);
- }
- }
- protected CustomScoreProvider getCustomScoreProvider(
- LeafReaderContext context) throws IOException {
- return new CountingQueryScoreProvider("contents", context);
- }
- }
Add Comment
Please, Sign In to add comment