Search in sources :

Example 1 with PluginRescorer

use of com.yelp.nrtsearch.server.grpc.PluginRescorer in project nrtsearch by Yelp.

the class SearchRequestProcessor method getRescorers.

/**
 * Parses rescorers defined in this search request.
 */
private static List<RescoreTask> getRescorers(IndexState indexState, IndexSearcher searcher, SearchRequest searchRequest) throws IOException {
    List<RescoreTask> rescorers = new ArrayList<>();
    for (int i = 0; i < searchRequest.getRescorersList().size(); ++i) {
        com.yelp.nrtsearch.server.grpc.Rescorer rescorer = searchRequest.getRescorers(i);
        String rescorerName = rescorer.getName();
        RescoreOperation thisRescoreOperation;
        if (rescorer.hasQueryRescorer()) {
            QueryRescorer queryRescorer = rescorer.getQueryRescorer();
            Query query = QUERY_NODE_MAPPER.getQuery(queryRescorer.getRescoreQuery(), indexState);
            query = searcher.rewrite(query);
            thisRescoreOperation = QueryRescore.newBuilder().setQuery(query).setQueryWeight(queryRescorer.getQueryWeight()).setRescoreQueryWeight(queryRescorer.getRescoreQueryWeight()).build();
        } else if (rescorer.hasPluginRescorer()) {
            PluginRescorer plugin = rescorer.getPluginRescorer();
            thisRescoreOperation = RescorerCreator.getInstance().createRescorer(plugin);
        } else {
            throw new IllegalArgumentException("Rescorer should define either QueryRescorer or PluginRescorer");
        }
        rescorers.add(RescoreTask.newBuilder().setRescoreOperation(thisRescoreOperation).setWindowSize(rescorer.getWindowSize()).setName(rescorerName != null && !rescorerName.equals("") ? rescorerName : String.format("rescorer_%d", i)).build());
    }
    return rescorers;
}
Also used : RescoreTask(com.yelp.nrtsearch.server.luceneserver.rescore.RescoreTask) Query(org.apache.lucene.search.Query) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) ArrayList(java.util.ArrayList) PluginRescorer(com.yelp.nrtsearch.server.grpc.PluginRescorer) RescoreOperation(com.yelp.nrtsearch.server.luceneserver.rescore.RescoreOperation) QueryRescorer(com.yelp.nrtsearch.server.grpc.QueryRescorer)

Aggregations

PluginRescorer (com.yelp.nrtsearch.server.grpc.PluginRescorer)1 QueryRescorer (com.yelp.nrtsearch.server.grpc.QueryRescorer)1 RescoreOperation (com.yelp.nrtsearch.server.luceneserver.rescore.RescoreOperation)1 RescoreTask (com.yelp.nrtsearch.server.luceneserver.rescore.RescoreTask)1 ArrayList (java.util.ArrayList)1 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)1 Query (org.apache.lucene.search.Query)1