Java 类org.apache.lucene.search.function.CustomScoreProvider 实例源码

项目:t4f-data    文件:FunctionQueryTest.java   
public void testCustomScoreQuery() throws Throwable {
  Query q = new QueryParser(Version.LUCENE_41,
                            "content",
                            new StandardAnalyzer(
                              Version.LUCENE_41))
               .parse("the green hat");
  FieldScoreQuery qf = new FieldScoreQuery("score",
                                           FieldScoreQuery.Type.BYTE);
  CustomScoreQuery customQ = new CustomScoreQuery(q, qf) {
    public CustomScoreProvider getCustomScoreProvider(IndexReader r) {
      return new CustomScoreProvider(r) {
        public float customScore(int doc,
                                 float subQueryScore,
                                 float valSrcScore) {
          return (float) (Math.sqrt(subQueryScore) * valSrcScore);
        }
      };
    }
  };

  TopDocs hits = s.search(customQ, 10);
  assertEquals(2, hits.scoreDocs.length);

  assertEquals(1, hits.scoreDocs[0].doc);           //
  assertEquals(0, hits.scoreDocs[1].doc);
}
项目:opensearchserver    文件:ScoreFunctionQuery.java   
@Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
    return new ScoreFunctionProvider(reader);
}
项目:t4f-data    文件:FunctionQueryTest.java   
public CustomScoreProvider getCustomScoreProvider(IndexReader r) throws IOException {
  return new RecencyBooster(r);
}