andywebb1975 commented on a change in pull request #1113: SOLR-14131: adds
maxQueryLength option
URL: https://github.com/apache/lucene-solr/pull/1113#discussion_r360989610
##########
File path:
solr/core/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java
##########
@@ -88,6 +88,45 @@ public void testOnlyMorePopularWithExtendedResults() throws
Exception {
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/arr[@name='suggestion']/lst/int[@name='freq']=2",
"//lst[@name='spellcheck']/bool[@name='correctlySpelled']='true'"
);
- }
+ }
+
+ @Test
+ public void testMaxQueryLength() throws Exception {
+ testMaxQueryLength(true);
+ testMaxQueryLength(false);
+ }
+
+ private void testMaxQueryLength(Boolean limitQueryLength) throws Exception {
+
+ DirectSolrSpellChecker checker = new DirectSolrSpellChecker();
+ NamedList spellchecker = new NamedList();
+ spellchecker.add("classname", DirectSolrSpellChecker.class.getName());
+ spellchecker.add(SolrSpellChecker.FIELD, "teststop");
+ spellchecker.add(DirectSolrSpellChecker.MINQUERYLENGTH, 2);
+
+ // demonstrate that "anothar" is not corrected when maxQueryLength is set
to a small number
+ if (limitQueryLength)
spellchecker.add(DirectSolrSpellChecker.MAXQUERYLENGTH, 4);
+
+ SolrCore core = h.getCore();
+ checker.init(spellchecker, core);
+
+ h.getCore().withSearcher(searcher -> {
+ Collection<Token> tokens = queryConverter.convert("anothar");
+ SpellingOptions spellOpts = new SpellingOptions(tokens,
searcher.getIndexReader());
+ SpellingResult result = checker.getSuggestions(spellOpts);
+ assertTrue("result should not be null", result != null);
+ Map<String, Integer> suggestions = result.get(tokens.iterator().next());
+ assertTrue("suggestions should not be null", suggestions != null);
+
+ if (limitQueryLength) {
+ assertTrue("suggestions should be empty", suggestions.isEmpty());
+ } else {
+ Map.Entry<String, Integer> entry =
suggestions.entrySet().iterator().next();
Review comment:
done!
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]