org.elasticsearch.search.rescore.QueryRescorer.combine()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(58)

本文整理了Java中org.elasticsearch.search.rescore.QueryRescorer.combine方法的一些代码示例,展示了QueryRescorer.combine的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryRescorer.combine方法的具体详情如下:
包路径:org.elasticsearch.search.rescore.QueryRescorer
类名称:QueryRescorer
方法名:combine

QueryRescorer.combine介绍

[英]Modifies incoming TopDocs (in) by replacing the top hits with resorted's hits, and then resorting all hits.
[中]修改传入的TopDocs(in),方法是用Restored的点击替换热门点击,然后重新选择所有点击。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext rescoreContext) throws IOException {
  assert rescoreContext != null;
  if (topDocs == null || topDocs.totalHits == 0 || topDocs.scoreDocs.length == 0) {
    return topDocs;
  }
  final QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
  org.apache.lucene.search.Rescorer rescorer = new org.apache.lucene.search.QueryRescorer(rescore.query()) {
    @Override
    protected float combine(float firstPassScore, boolean secondPassMatches, float secondPassScore) {
      if (secondPassMatches) {
        return rescore.scoreMode.combine(firstPassScore * rescore.queryWeight(), secondPassScore * rescore.rescoreQueryWeight());
      }
      // TODO: shouldn't this be up to the ScoreMode?  I.e., we should just invoke ScoreMode.combine, passing 0.0f for the
      // secondary score?
      return firstPassScore * rescore.queryWeight();
    }
  };
  // First take top slice of incoming docs, to be rescored:
  TopDocs topNFirstPass = topN(topDocs, rescoreContext.getWindowSize());
  // Save doc IDs for which rescoring was applied to be used in score explanation
  Set<Integer> topNDocIDs = Collections.unmodifiableSet(
    Arrays.stream(topNFirstPass.scoreDocs).map(scoreDoc -> scoreDoc.doc).collect(toSet()));
  rescoreContext.setRescoredDocs(topNDocIDs);
  // Rescore them:
  TopDocs rescored = rescorer.rescore(searcher, topNFirstPass, rescoreContext.getWindowSize());
  // Splice back to non-topN hits and resort all of them:
  return combine(topDocs, rescored, (QueryRescoreContext) rescoreContext);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext rescoreContext) throws IOException {
  assert rescoreContext != null;
  if (topDocs == null || topDocs.totalHits == 0 || topDocs.scoreDocs.length == 0) {
    return topDocs;
  }
  final QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
  org.apache.lucene.search.Rescorer rescorer = new org.apache.lucene.search.QueryRescorer(rescore.query()) {
    @Override
    protected float combine(float firstPassScore, boolean secondPassMatches, float secondPassScore) {
      if (secondPassMatches) {
        return rescore.scoreMode.combine(firstPassScore * rescore.queryWeight(), secondPassScore * rescore.rescoreQueryWeight());
      }
      // TODO: shouldn't this be up to the ScoreMode?  I.e., we should just invoke ScoreMode.combine, passing 0.0f for the
      // secondary score?
      return firstPassScore * rescore.queryWeight();
    }
  };
  // First take top slice of incoming docs, to be rescored:
  TopDocs topNFirstPass = topN(topDocs, rescoreContext.getWindowSize());
  // Save doc IDs for which rescoring was applied to be used in score explanation
  Set<Integer> topNDocIDs = Collections.unmodifiableSet(
    Arrays.stream(topNFirstPass.scoreDocs).map(scoreDoc -> scoreDoc.doc).collect(toSet()));
  rescoreContext.setRescoredDocs(topNDocIDs);
  // Rescore them:
  TopDocs rescored = rescorer.rescore(searcher, topNFirstPass, rescoreContext.getWindowSize());
  // Splice back to non-topN hits and resort all of them:
  return combine(topDocs, rescored, (QueryRescoreContext) rescoreContext);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@Override
public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext rescoreContext) throws IOException {
  assert rescoreContext != null;
  if (topDocs == null || topDocs.totalHits == 0 || topDocs.scoreDocs.length == 0) {
    return topDocs;
  }
  final QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
  org.apache.lucene.search.Rescorer rescorer = new org.apache.lucene.search.QueryRescorer(rescore.query()) {
    @Override
    protected float combine(float firstPassScore, boolean secondPassMatches, float secondPassScore) {
      if (secondPassMatches) {
        return rescore.scoreMode.combine(firstPassScore * rescore.queryWeight(), secondPassScore * rescore.rescoreQueryWeight());
      }
      // TODO: shouldn't this be up to the ScoreMode?  I.e., we should just invoke ScoreMode.combine, passing 0.0f for the
      // secondary score?
      return firstPassScore * rescore.queryWeight();
    }
  };
  // First take top slice of incoming docs, to be rescored:
  TopDocs topNFirstPass = topN(topDocs, rescoreContext.getWindowSize());
  // Save doc IDs for which rescoring was applied to be used in score explanation
  Set<Integer> topNDocIDs = Collections.unmodifiableSet(
    Arrays.stream(topNFirstPass.scoreDocs).map(scoreDoc -> scoreDoc.doc).collect(toSet()));
  rescoreContext.setRescoredDocs(topNDocIDs);
  // Rescore them:
  TopDocs rescored = rescorer.rescore(searcher, topNFirstPass, rescoreContext.getWindowSize());
  // Splice back to non-topN hits and resort all of them:
  return combine(topDocs, rescored, (QueryRescoreContext) rescoreContext);
}

代码示例来源:origin: harbby/presto-connectors

@Override
public TopDocs rescore(TopDocs topDocs, SearchContext context, RescoreSearchContext rescoreContext) throws IOException {
  assert rescoreContext != null;
  if (topDocs == null || topDocs.totalHits == 0 || topDocs.scoreDocs.length == 0) {
    return topDocs;
  }
  final QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
  org.apache.lucene.search.Rescorer rescorer = new org.apache.lucene.search.QueryRescorer(rescore.query()) {
    @Override
    protected float combine(float firstPassScore, boolean secondPassMatches, float secondPassScore) {
      if (secondPassMatches) {
        return rescore.scoreMode.combine(firstPassScore * rescore.queryWeight(), secondPassScore * rescore.rescoreQueryWeight());
      }
      // TODO: shouldn't this be up to the ScoreMode?  I.e., we should just invoke ScoreMode.combine, passing 0.0f for the
      // secondary score?
      return firstPassScore * rescore.queryWeight();
    }
  };
  // First take top slice of incoming docs, to be rescored:
  TopDocs topNFirstPass = topN(topDocs, rescoreContext.window());
  // Rescore them:
  TopDocs rescored = rescorer.rescore(context.searcher(), topNFirstPass, rescoreContext.window());
  // Splice back to non-topN hits and resort all of them:
  return combine(topDocs, rescored, (QueryRescoreContext) rescoreContext);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@Override
public TopDocs rescore(TopDocs topDocs, SearchContext context, RescoreSearchContext rescoreContext) throws IOException {
  assert rescoreContext != null;
  if (topDocs == null || topDocs.totalHits == 0 || topDocs.scoreDocs.length == 0) {
    return topDocs;
  }
  final QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
  org.apache.lucene.search.Rescorer rescorer = new org.apache.lucene.search.QueryRescorer(rescore.query()) {
    @Override
    protected float combine(float firstPassScore, boolean secondPassMatches, float secondPassScore) {
      if (secondPassMatches) {
        return rescore.scoreMode.combine(firstPassScore * rescore.queryWeight(), secondPassScore * rescore.rescoreQueryWeight());
      }
      // TODO: shouldn't this be up to the ScoreMode?  I.e., we should just invoke ScoreMode.combine, passing 0.0f for the
      // secondary score?
      return firstPassScore * rescore.queryWeight();
    }
  };
  // First take top slice of incoming docs, to be rescored:
  TopDocs topNFirstPass = topN(topDocs, rescoreContext.window());
  // Rescore them:
  TopDocs rescored = rescorer.rescore(context.searcher(), topNFirstPass, rescoreContext.window());
  // Splice back to non-topN hits and resort all of them:
  return combine(topDocs, rescored, (QueryRescoreContext) rescoreContext);
}

相关文章

微信公众号

最新文章

更多