Java 类org.apache.lucene.search.DoubleValuesSource 实例源码

项目:elasticsearch-learning-to-rank    文件:DerivedExpressionQuery.java   
@Override
public Scorer scorer(LeafReaderContext context, Supplier<LtrRanker.FeatureVector> vectorSupplier) throws IOException {
    Bindings bindings = new Bindings(){
        @Override
        public DoubleValuesSource getDoubleValuesSource(String name) {
            return new FVDoubleValuesSource(vectorSupplier, features.featureOrdinal(name));
        }
    };

    DocIdSetIterator iterator = DocIdSetIterator.all(context.reader().maxDoc());
    DoubleValuesSource src = expression.getDoubleValuesSource(bindings);
    DoubleValues values = src.getValues(context, null);

    return new DValScorer(this, iterator, values);
}
项目:elasticsearch-learning-to-rank    文件:DerivedExpressionQuery.java   
@Override
public Explanation explain(LeafReaderContext context, LtrRanker.FeatureVector vector, int doc) throws IOException {
    Bindings bindings = new Bindings(){
        @Override
        public DoubleValuesSource getDoubleValuesSource(String name) {
            return new FVDoubleValuesSource(() -> vector, features.featureOrdinal(name));
        }
    };

    DoubleValuesSource src = expression.getDoubleValuesSource(bindings);
    DoubleValues values = src.getValues(context, null);
    values.advanceExact(doc);
    return Explanation.match((float) values.doubleValue(), "Evaluation of derived expression: " + expression.sourceText);
}
项目:information-retrieval-adventure    文件:IndexTimeScoringFactors.java   
/**
 * Since Lucene 6.6.0 the index time boosting has been deprecated. How we suppose to solve it now?
 */
public static void main(String[] args) throws IOException {

  Directory dir = new RAMDirectory();
  Analyzer analyzer = new StandardAnalyzer();
  IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
  iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
  IndexWriter writer = new IndexWriter(dir, iwc);

  Document doc1 = new Document();
  doc1.add(new TextField("title", "The biggest title in the world", Store.YES));
  doc1.add(new TextField("description", "short descr", Store.YES));
  doc1.add(new FloatDocValuesField("doc_boost", 1.30f));
  writer.addDocument(doc1);

  Document doc2 = new Document();
  doc2.add(new TextField("title", "Not so important title", Store.YES));
  doc1.add(new TextField("description", "very valuable descr", Store.YES));
  doc1.add(new FloatDocValuesField("doc_boost", 3.30f));
  writer.addDocument(doc2);

  writer.close();

  IndexReader reader = DirectoryReader.open(dir);
  IndexSearcher searcher = new IndexSearcher(reader);

  Query query = new MatchAllDocsQuery();
  Query q = new FunctionScoreQuery(query, DoubleValuesSource.fromFloatField("doc_boost"));

  final ScoreDoc[] scoreDocs = searcher.search(q, 10).scoreDocs;
  for (ScoreDoc doc : scoreDocs) {
    System.out.println(doc.doc + " " + doc.score);
  }
}