lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tflo...@apache.org
Subject svn commit: r1657655 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/spelling/suggest/fst/ core/src/test-files/solr/collection1/conf/ core/src/test/org/apache/solr/spelling/suggest/
Date Thu, 05 Feb 2015 18:24:01 GMT
Author: tflobbe
Date: Thu Feb  5 18:24:01 2015
New Revision: 1657655

URL: http://svn.apache.org/r1657655
Log:
SOLR-6648: Add support for highlight and allTermsRequired configuration in AnalyzingInfix
and BlendedInfix Solr suggesters

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
    lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1657655&r1=1657654&r2=1657655&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Feb  5 18:24:01 2015
@@ -97,6 +97,10 @@ New Features
   collection that has a replica on all nodes where there is a replica in the to index
   (Jack Lo, Timothy Potter)
 
+* SOLR-6648: Add support in AnalyzingInfixLookupFactory and BlendedInfixLookupFactory 
+  for setting 'highlight' and 'allTermsRequired' in the suggester configuration.
+  (Boon Low, Varun Thacker via Tomás Fernández Löbbe)
+
 Bug Fixes
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java?rev=1657655&r1=1657654&r2=1657655&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
Thu Feb  5 18:24:01 2015
@@ -58,6 +58,15 @@ public class AnalyzingInfixLookupFactory
   protected static final String MIN_PREFIX_CHARS = "minPrefixChars";
   
   /** 
+   * Boolean clause matching option for multiple terms 
+   * Default is true - all terms required. 
+   */
+  protected static final String ALL_TERMS_REQUIRED = "allTermsRequired";
+  
+  /** Highlight suggest terms  - default is true. */
+  protected static final String HIGHLIGHT = "highlight";
+    
+  /** 
    * Default path where the index for the suggester is stored/loaded from
    * */
   private static final String DEFAULT_INDEX_PATH = "analyzingInfixSuggesterIndexDir";
@@ -94,10 +103,19 @@ public class AnalyzingInfixLookupFactory
     int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
     ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
     : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;
+    
+    boolean allTermsRequired = params.get(ALL_TERMS_REQUIRED) != null
+    ? Boolean.getBoolean(params.get(ALL_TERMS_REQUIRED).toString())
+    : AnalyzingInfixSuggester.DEFAULT_ALL_TERMS_REQUIRED;
+    
+    boolean highlight = params.get(HIGHLIGHT) != null
+    ? Boolean.getBoolean(params.get(HIGHLIGHT).toString())
+    : AnalyzingInfixSuggester.DEFAULT_HIGHLIGHT; 
 
     try {
       return new AnalyzingInfixSuggester(FSDirectory.open(new File(indexPath).toPath()),
indexAnalyzer,
-                                         queryAnalyzer, minPrefixChars, true) {
+                                         queryAnalyzer, minPrefixChars, true, 
+                                         allTermsRequired, highlight) {
         @Override
         public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts,
int num, boolean allTermsRequired, boolean doHighlight) throws IOException {
           List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired,
doHighlight);

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java?rev=1657655&r1=1657654&r2=1657655&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
Thu Feb  5 18:24:01 2015
@@ -93,6 +93,14 @@ public class BlendedInfixLookupFactory e
     int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
     ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
     : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;
+    
+    boolean allTermsRequired = params.get(ALL_TERMS_REQUIRED) != null
+    ? Boolean.getBoolean(params.get(ALL_TERMS_REQUIRED).toString())
+    : AnalyzingInfixSuggester.DEFAULT_ALL_TERMS_REQUIRED;
+    
+    boolean highlight = params.get(HIGHLIGHT) != null
+    ? Boolean.getBoolean(params.get(HIGHLIGHT).toString())
+    : AnalyzingInfixSuggester.DEFAULT_HIGHLIGHT;
 
     BlenderType blenderType = getBlenderType(params.get(BLENDER_TYPE));
     
@@ -103,7 +111,8 @@ public class BlendedInfixLookupFactory e
     try {
       return new BlendedInfixSuggester(FSDirectory.open(new File(indexPath).toPath()),
                                        indexAnalyzer, queryAnalyzer, minPrefixChars,
-                                       blenderType, numFactor, true) {
+                                       blenderType, numFactor, true,
+                                       allTermsRequired, highlight) {
         @Override
         public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts,
int num, boolean allTermsRequired, boolean doHighlight) throws IOException {
           List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired,
doHighlight);

Modified: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml?rev=1657655&r1=1657654&r2=1657655&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml
(original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml
Thu Feb  5 18:24:01 2015
@@ -82,7 +82,43 @@
     <!-- specify a fieldType using keywordtokenizer + lowercase + cleanup -->
     <str name="queryAnalyzerFieldType">phrase_suggest</str>
   </searchComponent>
-
+  
+  <!-- AnalyzingInfixLookup suggest component (SolrSuggester - default) -->
+  <searchComponent class="solr.SuggestComponent" name="analyzing_infix_suggest">
+    <!-- Default: highlight - true, allTermsRequired - true -->
+    <lst name="suggester">
+      <str name="name">analyzing_infix_suggest_default</str>
+      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
+      <str name="dictionaryImpl">FileDictionaryFactory</str>
+      <str name="buildOnCommit">false</str>
+      <str name="indexPath">analyzing_infix_suggest_default</str>
+      <str name="sourceLocation">analyzingInfixSuggest.txt</str>
+      <str name="suggestAnalyzerFieldType">text</str>
+    </lst>
+    
+    <lst name="suggester">
+      <str name="name">analyzing_infix_suggest_without_highlight</str>
+      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
+      <str name="dictionaryImpl">FileDictionaryFactory</str>
+      <str name="buildOnCommit">false</str>
+      <str name="indexPath">analyzing_infix_suggest_without_highlight</str>
+      <str name="sourceLocation">analyzingInfixSuggest.txt</str>
+      <str name="suggestAnalyzerFieldType">text</str>
+      <bool name="highlight">false</bool>
+    </lst>
+    
+    <lst name="suggester">
+      <str name="name">analyzing_infix_suggest_not_all_terms_required</str>
+      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
+      <str name="dictionaryImpl">FileDictionaryFactory</str>
+      <str name="buildOnCommit">false</str>
+      <str name="indexPath">analyzing_infix_suggest_not_all_terms_required</str>
+      <str name="sourceLocation">analyzingInfixSuggest.txt</str>
+      <str name="suggestAnalyzerFieldType">text</str>
+      <bool name="allTermsRequired">false</bool>
+    </lst>
+  </searchComponent>
+  
   
   <!-- FuzzyLookup suggest component with HighFrequencyDictionary -->
   <searchComponent class="solr.SuggestComponent" name="fuzzy_suggest_analyzing_with_high_freq_dict">
@@ -306,6 +342,14 @@
     </arr>
   </requestHandler>
   
+  <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/analyzing_infix_suggest">
+    <lst name="defaults">
+      <str name="suggest">true</str>
+    </lst>
+    <arr name="components">
+      <str>analyzing_infix_suggest</str>
+    </arr>
+  </requestHandler>
   
   <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/blended_infix_suggest">
     <lst name="defaults">

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java?rev=1657655&r1=1657654&r2=1657655&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java
Thu Feb  5 18:24:01 2015
@@ -23,11 +23,13 @@ import org.junit.BeforeClass;
 
 public class TestAnalyzeInfixSuggestions extends SolrTestCaseJ4  {
   static final String URI_DEFAULT = "/infix_suggest_analyzing";
+  static final String URI_SUGGEST_DEFAULT = "/analyzing_infix_suggest";
 
   @BeforeClass
   public static void beforeClass() throws Exception {
     initCore("solrconfig-phrasesuggest.xml","schema-phrasesuggest.xml");
     assertQ(req("qt", URI_DEFAULT, "q", "", SpellingParams.SPELLCHECK_BUILD, "true"));
+    assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "", SuggesterParams.SUGGEST_BUILD_ALL, "true"));
   
   }
   
   public void testSingle() throws Exception {
@@ -41,6 +43,17 @@ public class TestAnalyzeInfixSuggestions
       "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='high']/int[@name='numFound'][.='1']",
       "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='high']/arr[@name='suggestion']/str[1][.='Japanese
Autocomplete and Japanese <b>High</b>lighter broken']"
       );
+   
+    /* equivalent SolrSuggester, SuggestComponent tests */ 
+    assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japan", SuggesterParams.SUGGEST_COUNT, "1",
SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/int[@name='numFound'][.='1']",
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='<b>Japan</b>ese
Autocomplete and <b>Japan</b>ese Highlighter broken']"
+    );
+    
+    assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "high", SuggesterParams.SUGGEST_COUNT, "1",
SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='high']/int[@name='numFound'][.='1']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='high']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Japanese
Autocomplete and Japanese <b>High</b>lighter broken']"
+      );
   }
   
   public void testMultiple() throws Exception {
@@ -62,6 +75,44 @@ public class TestAnalyzeInfixSuggestions
       "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[2][.='Add
<b>Japan</b>ese Kanji number normalization to Kuromoji']",
       "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[3][.='Add
decompose compound <b>Japan</b>ese Katakana token capability to Kuromoji']"
       );
+    
+    /* SolrSuggester, SuggestComponent tests: allTermsRequire (true), highlight (true) */

+    assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japan", SuggesterParams.SUGGEST_COUNT, "2",
SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/int[@name='numFound'][.='2']",
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='<b>Japan</b>ese
Autocomplete and <b>Japan</b>ese Highlighter broken']",
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Add
<b>Japan</b>ese Kanji number normalization to Kuromoji']"
+      );
+    
+    assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japanese ka", SuggesterParams.SUGGEST_COUNT,
"2", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japanese
ka']/int[@name='numFound'][.='2']",
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japanese
ka']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Add <b>Japanese</b>
<b>Ka</b>nji number normalization to Kuromoji']",
+      "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japanese
ka']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Add decompose compound <b>Japanese</b>
<b>Ka</b>takana token capability to Kuromoji']"
+      );
+    
+  }
+  
+  public void testWithoutHighlight() throws Exception {
+     assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japan", SuggesterParams.SUGGEST_COUNT,
"2", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_without_highlight"),
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_without_highlight']/lst[@name='japan']/int[@name='numFound'][.='2']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_without_highlight']/lst[@name='japan']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Japanese
Autocomplete and Japanese Highlighter broken']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_without_highlight']/lst[@name='japan']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Add
Japanese Kanji number normalization to Kuromoji']"
+     );
+  }
+  
+  public void testNotAllTermsRequired() throws Exception {
+     assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japanese javanese", SuggesterParams.SUGGEST_COUNT,
"5", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_not_all_terms_required"),
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='japanese
javanese']/int[@name='numFound'][.='3']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='japanese
javanese']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='<b>Japanese</b>
Autocomplete and <b>Japanese</b> Highlighter broken']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='japanese
javanese']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Add <b>Japanese</b>
Kanji number normalization to Kuromoji']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='japanese
javanese']/arr[@name='suggestions']/lst[3]/str[@name='term'][.='Add decompose compound <b>Japanese</b>
Katakana token capability to Kuromoji']"
+     );
+     
+     assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "just number", SuggesterParams.SUGGEST_COUNT,
"5", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_not_all_terms_required"),
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='just
number']/int[@name='numFound'][.='2']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='just
number']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Add Japanese Kanji <b>number</b>
normalization to Kuromoji']",
+       "//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_not_all_terms_required']/lst[@name='just
number']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='This is <b>just</b>
another entry!']"
+     );
+     
   }
   
 }
\ No newline at end of file



Mime
View raw message