diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 68873b74238..d568df0ae72 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -529,6 +529,8 @@ Bug Fixes * SOLR-1794: Dataimport of CLOB fields fails when getCharacterStream() is defined in a superclass. (Gunnar Gauslaa Bergem via rmuir) + +* SOLR-2173 Suggester should always rebuild Lookup data if Lookup.load fails. (ab) Other Changes ---------------------- diff --git a/solr/src/java/org/apache/solr/spelling/suggest/Suggester.java b/solr/src/java/org/apache/solr/spelling/suggest/Suggester.java index dce4aa9cf84..95fc71148bc 100644 --- a/solr/src/java/org/apache/solr/spelling/suggest/Suggester.java +++ b/solr/src/java/org/apache/solr/spelling/suggest/Suggester.java @@ -129,20 +129,10 @@ public class Suggester extends SolrSpellChecker { if (lookup.load(storeDir)) { return; // loaded ok } + LOG.debug("load failed, need to build Lookup again"); } - // dictionary based on the current index may need refreshing - if (dictionary instanceof HighFrequencyDictionary) { - reader = reader.reopen(); - dictionary = new HighFrequencyDictionary(reader, field, threshold); - try { - lookup.build(dictionary); - if (storeDir != null) { - lookup.store(storeDir); - } - } catch (Exception e) { - throw new IOException(e); - } - } + // loading was unsuccessful - build it again + build(core, searcher); } public void add(String query, int numHits) { diff --git a/solr/src/test/org/apache/solr/spelling/suggest/SuggesterTest.java b/solr/src/test/org/apache/solr/spelling/suggest/SuggesterTest.java index 133392eaf03..de0001fab23 100644 --- a/solr/src/test/org/apache/solr/spelling/suggest/SuggesterTest.java +++ b/solr/src/test/org/apache/solr/spelling/suggest/SuggesterTest.java @@ -62,6 +62,20 @@ public class SuggesterTest extends SolrTestCaseJ4 { "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[2][.='accommodate']" ); } + + @Test + public void testReload() throws Exception { + addDocs(); + assertU(commit()); + assertQ(req("qt","/suggest", "q","ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"), + "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']"); + assertU(adoc("id", "4", + "text", "actually" + )); + assertU(commit()); + assertQ(req("qt","/suggest", "q","ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"), + "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']"); + } private TermFreqIterator getTFIT() {