dsmiley commented on code in PR #1260: URL: https://github.com/apache/solr/pull/1260#discussion_r1110573135
########## solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java: ########## @@ -127,6 +128,53 @@ public void process(ResponseBuilder rb) throws IOException { } } + private static NamedList<String> putMLTIntoParamList( Review Comment: We strive to match the Google Java Style guide, and that means using "Mlt" and not "MLT" inside names. But maybe MLT is so pervasive capitalized this way in the code already (before striving for this) that you are trying to be consistent? Any way; do as you wish. ########## solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java: ########## @@ -389,5 +389,29 @@ public void test() throws Exception { Long actual = ((SolrDocumentList) entry.getValue()).getNumFound(); assertEquals("MLT mismatch for id=" + key, expected, actual); } + // test bost mlt.qf Review Comment: ```suggestion // test boost mlt.qf ``` ########## solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java: ########## @@ -127,6 +128,53 @@ public void process(ResponseBuilder rb) throws IOException { } } + private static NamedList<String> putMLTIntoParamList( + IndexSchema schema, + List<MoreLikeThisHandler.InterestingTerm> terms, + String uniqueField, + String uniqueVal) { + final NamedList<String> mltQ = new NamedList<>(); + StringBuilder q = new StringBuilder("{!bool"); + q.append(" must_not=$"); + int cnt = 0; + String param = "mltq" + (cnt++); + q.append(param); + mltQ.add(param, "{!field f=" + uniqueField + "}" + uniqueVal); + final StringBuilder reuseStr = new StringBuilder(); + final CharsRefBuilder reuseChar = new CharsRefBuilder(); + for (MoreLikeThisHandler.InterestingTerm term : terms) { + param = "mltq" + (cnt++); + q.append(" should=$"); + q.append(param); + mltQ.add(param, toParserParam(schema, term.term, term.boost, reuseStr, reuseChar)); + } + q.append("}"); + mltQ.add(CommonParams.Q, q.toString()); + return mltQ; + } + + private static String toParserParam( + IndexSchema schema, + Term term1, + float boost, + StringBuilder reuseStr, + CharsRefBuilder reuseChar) { + reuseStr.setLength(0); + if (boost != 1f) { + reuseStr.append("{!boost b="); + reuseStr.append(boost); + reuseStr.append("}"); + } + final String field = term1.field(); + final CharsRef val = Review Comment: See `org.apache.solr.client.solrj.util.ClientUtils#encodeLocalParamVal` ########## solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java: ########## @@ -422,6 +417,24 @@ public DocListAndSet getMoreLikeThis( return results; } + public List<InterestingTerm> getInterestingTerms(int docid) throws IOException { + final ArrayList<InterestingTerm> interestingTerms = new ArrayList<>(); + getBoostedMLTQuery(docid, interestingTerms); + return interestingTerms; + } + /** + * Sets {@link #boostedMLTQuery} and return, also put interesting terms into terms list if + * provided non-null. Sorry. It lacks of perfection and overall sense. Review Comment: LOL.... so it can help make it less ugly to name the parameter outputTerms or something like that. I've also seen a strategy where the return value is a Pair or something like that. There is such a class in SolrJ. -- 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. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org