SOLR-795 -- SpellCheckComponent supports building indices on optimize if configured in solrconfig.xml

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@708653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2008-10-28 19:59:44 +00:00
parent 9c3ab6d75f
commit 5a7f0c6cd9
2 changed files with 37 additions and 27 deletions

View File

@ -70,6 +70,8 @@ New Features
10. SOLR-651: Added TermVectorComponent for serving up term vector information, plus IDF. 10. SOLR-651: Added TermVectorComponent for serving up term vector information, plus IDF.
See http://wiki.apache.org/solr/TermVectorComponent (gsingers, Vaijanath N. Rao, Noble Paul) See http://wiki.apache.org/solr/TermVectorComponent (gsingers, Vaijanath N. Rao, Noble Paul)
12. SOLR-795: SpellCheckComponent supports building indices on optimize if configured in solrconfig.xml
(Jason Rennie, shalin)
Optimizations Optimizations
---------------------- ----------------------
@ -89,8 +91,6 @@ Bug Fixes
4. SOLR-805: DisMax queries are not being cached in QueryResultCache (Todd Feak via koji) 4. SOLR-805: DisMax queries are not being cached in QueryResultCache (Todd Feak via koji)
5. SOLR-803, SOLR-827: Fix CoreAdminRequest#createCore (Sean Colombo via ryan)
Other Changes Other Changes
---------------------- ----------------------
@ -100,12 +100,6 @@ Other Changes
3. DumpRequestHandler (/debug/dump): changed 'fieldName' to 'sourceInfo'. (ehatcher) 3. DumpRequestHandler (/debug/dump): changed 'fieldName' to 'sourceInfo'. (ehatcher)
4. SOLR-657: Replace many deprecated calls with non-deprecated equivalents
(Lars Kotthoff via ryan)
5. SOLR-816: Deprecate access to SolrConfig from IndexSchema. Rather then access
SolrConfig from the schema, plugins should get the config from the core. IndexSchema
still has access to the ResourceLoader. (ryan)
Build Build
---------------------- ----------------------

View File

@ -51,7 +51,6 @@ import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.spelling.*; import org.apache.solr.spelling.*;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.plugin.NamedListPluginLoader; import org.apache.solr.util.plugin.NamedListPluginLoader;
import org.apache.solr.util.plugin.SolrCoreAware; import org.apache.solr.util.plugin.SolrCoreAware;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -273,10 +272,12 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
} }
} }
// Register event listeners for this SpellChecker // Register event listeners for this SpellChecker
core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, true)); core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false));
if (Boolean.parseBoolean((String)spellchecker.get("buildOnCommit"))) { boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit"));
boolean buildOnOptimize = Boolean.parseBoolean((String) spellchecker.get("buildOnOptimize"));
if (buildOnCommit || buildOnOptimize) {
LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName()); LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName());
core.registerNewSearcherListener(new SpellCheckerListener(core, checker, false)); core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize));
} }
} else { } else {
throw new RuntimeException("Can't load spell checker: " + className); throw new RuntimeException("Can't load spell checker: " + className);
@ -316,12 +317,14 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
private static class SpellCheckerListener implements SolrEventListener { private static class SpellCheckerListener implements SolrEventListener {
private final SolrCore core; private final SolrCore core;
private final SolrSpellChecker checker; private final SolrSpellChecker checker;
private final boolean firstSearcher; private final boolean buildOnCommit;
private final boolean buildOnOptimize;
public SpellCheckerListener(SolrCore core, SolrSpellChecker checker, boolean firstSearcher) { public SpellCheckerListener(SolrCore core, SolrSpellChecker checker, boolean buildOnCommit, boolean buildOnOptimize) {
this.core = core; this.core = core;
this.checker = checker; this.checker = checker;
this.firstSearcher = firstSearcher; this.buildOnCommit = buildOnCommit;
this.buildOnOptimize = buildOnOptimize;
} }
public void init(NamedList args) { public void init(NamedList args) {
@ -329,7 +332,8 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
public void newSearcher(SolrIndexSearcher newSearcher, public void newSearcher(SolrIndexSearcher newSearcher,
SolrIndexSearcher currentSearcher) { SolrIndexSearcher currentSearcher) {
if (firstSearcher) { if (currentSearcher == null) {
// firstSearcher event
try { try {
LOG.info("Loading spell index for spellchecker: " LOG.info("Loading spell index for spellchecker: "
+ checker.getDictionaryName()); + checker.getDictionaryName());
@ -339,17 +343,29 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
} }
} else { } else {
// newSearcher event // newSearcher event
try { if (buildOnCommit) {
LOG.info("Building spell index for spell checker: " + checker.getDictionaryName()); buildSpellIndex(newSearcher);
checker.build(core, newSearcher); } else if (buildOnOptimize) {
} catch (Exception e) { if (newSearcher.getReader().isOptimized()) {
log.error( buildSpellIndex(newSearcher);
"Exception in building spell check index for spellchecker: " + checker.getDictionaryName(), e); } else {
LOG.info("Index is not optimized therefore skipping building spell check index for: " + checker.getDictionaryName());
}
} }
} }
} }
private void buildSpellIndex(SolrIndexSearcher newSearcher) {
try {
LOG.info("Building spell index for spell checker: " + checker.getDictionaryName());
checker.build(core, newSearcher);
} catch (Exception e) {
log.error(
"Exception in building spell check index for spellchecker: " + checker.getDictionaryName(), e);
}
}
public void postCommit() { public void postCommit() {
} }
} }