SOLR-2173 Suggester should always rebuild Lookup data if Lookup.load fails.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1025781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrzej Bialecki 2010-10-20 22:16:14 +00:00
parent 19244901b0
commit 9a1ffd44db
3 changed files with 19 additions and 13 deletions

View File

@ -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
----------------------

View File

@ -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) {

View File

@ -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() {