I don't know why the code block in my first post lost newlines. Let me try
again:
MoreLikeThisQuery mltQuery = new MoreLikeThisQuery(queryText, new String[]
{"source"}, defaultFuzzyAnalyzer, "source"); // defaultFuzzyAnalyzer is a 4-gram
analyzer based on NGramTokenFilter.
mltQuery.setMinTermFrequency(1);
mltQuery.setMinDocFreq(1);
mltQuery.setPercentTermsToMatch(threshold);
mltQuery.setMaxQueryTerms(Integer.MAX_VALUE);
TopDocs topDocs = indexSearcher.search(mltQuery, max);
But after posting this, I realized that I could use IndexSearcher#explain() as:
Explanation expl = indexSearcher.explain(mltQuery, docId);
System.out.printf("docId=%d; expl=%s\n", docId, expl.toString());
If there are better ways to debug, please let me know.
TK
On 5/20/21 9:51 PM, TK Solr wrote:
I am having difficulty using MoreLikeThisQuery with an n-gram analyzer as its
analyzer.
A test query isn't hitting any document in a unit test case.
Is there any debugging method to use to understand why there is not hit?
Because the test code uses a RAMDirectory, I cannot use Luke to see if the
index was made correctly.
This is a snippet of the query code:
MoreLikeThisQuery mltQuery = new MoreLikeThisQuery(queryText, new String[]
{"source"}, //TODO: Make this array constant defaultFuzzyAnalyzer, "source");
// defaultFuzzyAnalyzer is a 4-gram analyzer based on NGramTokenFilter.
mltQuery.setMinTermFrequency(1); mltQuery.setMinDocFreq(1);
mltQuery.setPercentTermsToMatch(threshold);mltQuery.setMaxQueryTerms(Integer.MAX_VALUE);
TopDocs topDocs = indexSearcher.search(mltQuery, max);
Thanks.
TK