Guest User

Untitled

a guest
Jan 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. package CustomModul;
  2. import java.io.IOException;
  3. import org.apache.lucene.index.LeafReaderContext;
  4. import org.apache.lucene.index.IndexReader;
  5. import org.apache.lucene.index.Terms;
  6. import org.apache.lucene.queries.CustomScoreProvider;
  7. import org.apache.lucene.queries.CustomScoreQuery;
  8. import org.apache.lucene.search.Query;
  9.  
  10. public class CountingQuery extends CustomScoreQuery {
  11.  
  12. public CountingQuery(Query subQuery) {
  13. super(subQuery);
  14. }
  15.  
  16.  
  17. public class CountingQueryScoreProvider extends CustomScoreProvider {
  18.  
  19. String _field;
  20.  
  21. public CountingQueryScoreProvider(String field, LeafReaderContext context) {
  22. super(context);
  23. _field = field;
  24. }
  25.  
  26. public float customScore(int doc, float subQueryScore, float valSrcScores[]) throws IOException {
  27. IndexReader r = context.reader();
  28.  
  29. //getTermVector returns Null
  30. Terms vec = r.getTermVector(doc, _field);
  31.  
  32. //*TO-DO* Algorithm
  33.  
  34. return (float)(1.0f);
  35. }
  36. }
  37.  
  38. protected CustomScoreProvider getCustomScoreProvider(
  39. LeafReaderContext context) throws IOException {
  40. return new CountingQueryScoreProvider("contents", context);
  41. }
  42.  
  43. }
Add Comment
Please, Sign In to add comment