alessandrobenedetti commented on a change in pull request #1571: URL: https://github.com/apache/lucene-solr/pull/1571#discussion_r518736297
########## File path: solr/contrib/ltr/src/java/org/apache/solr/ltr/search/LTRQParserPlugin.java ########## @@ -146,93 +149,114 @@ public LTRQParser(String qstr, SolrParams localParams, SolrParams params, @Override public Query parse() throws SyntaxError { // ReRanking Model - final String modelName = localParams.get(LTRQParserPlugin.MODEL); - if ((modelName == null) || modelName.isEmpty()) { + final String[] modelNames = localParams.getParams(LTRQParserPlugin.MODEL); + if ((modelNames == null) || modelNames.length==0 || modelNames[0].isEmpty()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Must provide model in the request"); } - - final LTRScoringModel ltrScoringModel = mr.getModel(modelName); - if (ltrScoringModel == null) { - throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, - "cannot find " + LTRQParserPlugin.MODEL + " " + modelName); - } - - final String modelFeatureStoreName = ltrScoringModel.getFeatureStoreName(); - final boolean extractFeatures = SolrQueryRequestContextUtils.isExtractingFeatures(req); - final String fvStoreName = SolrQueryRequestContextUtils.getFvStoreName(req); - // Check if features are requested and if the model feature store and feature-transform feature store are the same - final boolean featuresRequestedFromSameStore = (modelFeatureStoreName.equals(fvStoreName) || fvStoreName == null) ? extractFeatures:false; - if (threadManager != null) { - threadManager.setExecutor(req.getCore().getCoreContainer().getUpdateShardHandler().getUpdateExecutor()); - } - final LTRScoringQuery scoringQuery = new LTRScoringQuery(ltrScoringModel, - extractEFIParams(localParams), - featuresRequestedFromSameStore, threadManager); - - // Enable the feature vector caching if we are extracting features, and the features - // we requested are the same ones we are reranking with - if (featuresRequestedFromSameStore) { - scoringQuery.setFeatureLogger( SolrQueryRequestContextUtils.getFeatureLogger(req) ); + + LTRScoringQuery[] rerankingQueries = new LTRScoringQuery[modelNames.length]; + for (int i = 0; i < modelNames.length; i++) { + final LTRScoringQuery rerankingQuery; + if (!ORIGINAL_RANKING.equals(modelNames[i])) { + final LTRScoringModel ltrScoringModel = mr.getModel(modelNames[i]); + if (ltrScoringModel == null) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, + "cannot find " + LTRQParserPlugin.MODEL + " " + modelNames[i]); + } + final String modelFeatureStoreName = ltrScoringModel.getFeatureStoreName(); + final boolean extractFeatures = SolrQueryRequestContextUtils.isExtractingFeatures(req); + final String fvStoreName = SolrQueryRequestContextUtils.getFvStoreName(req); // Check if features are requested and if the model feature store and feature-transform feature store are the same + final boolean featuresRequestedFromSameStore = (modelFeatureStoreName.equals(fvStoreName) || fvStoreName == null) ? extractFeatures : false; + if (threadManager != null) { + threadManager.setExecutor(req.getCore().getCoreContainer().getUpdateShardHandler().getUpdateExecutor()); + } + rerankingQuery = new LTRScoringQuery(ltrScoringModel, + extractEFIParams(localParams), + featuresRequestedFromSameStore, threadManager); + + // Enable the feature vector caching if we are extracting features, and the features + // we requested are the same ones we are reranking with + if (featuresRequestedFromSameStore) { + rerankingQuery.setFeatureLogger( SolrQueryRequestContextUtils.getFeatureLogger(req) ); + } + }else{ + rerankingQuery = new LTRScoringQuery(null); + } + + // External features + rerankingQuery.setRequest(req); + rerankingQueries[i] = rerankingQuery; } - SolrQueryRequestContextUtils.setScoringQuery(req, scoringQuery); + SolrQueryRequestContextUtils.setScoringQuery(req, rerankingQueries); int reRankDocs = localParams.getInt(RERANK_DOCS, DEFAULT_RERANK_DOCS); if (reRankDocs <= 0) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, - "Must rerank at least 1 document"); + "Must rerank at least 1 document"); + } + if (rerankingQueries.length == 1) { + return new LTRQuery(rerankingQueries[0], reRankDocs); + } else { + return new LTRQuery(rerankingQueries, reRankDocs); } - - // External features - scoringQuery.setRequest(req); - - return new LTRQuery(scoringQuery, reRankDocs); } } + + public static boolean isOriginalRanking(LTRScoringQuery rerankingQuery){ + return rerankingQuery.getScoringModel() == null; + } /** * A learning to rank Query, will incapsulate a learning to rank model, and delegate to it the rescoring * of the documents. **/ public class LTRQuery extends AbstractReRankQuery { - private final LTRScoringQuery scoringQuery; + private final LTRScoringQuery[] rerankingQueries; - public LTRQuery(LTRScoringQuery scoringQuery, int reRankDocs) { - super(defaultQuery, reRankDocs, new LTRRescorer(scoringQuery)); - this.scoringQuery = scoringQuery; + public LTRQuery(LTRScoringQuery[] rerankingQueries, int rerankDocs) { + super(defaultQuery, rerankDocs, new LTRInterleavingRescorer(rerankingQueries)); + this.rerankingQueries = rerankingQueries; + } + + public LTRQuery(LTRScoringQuery rerankingQuery, int rerankDocs) { + super(defaultQuery, rerankDocs, new LTRRescorer(rerankingQuery)); + this.rerankingQueries = new LTRScoringQuery[]{rerankingQuery}; Review comment: So I have done that in my latest commit, I brought back the original implementation for the transformers, it may be less readable but are we reducing the number of contains call? Given that we support just interleaving for 2 ranked list, if a document is not assigned to modelB is by default assigned to modelA and no need of checking the getPickedInterleavingDocIds? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org