mirror of https://github.com/apache/lucene.git
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:
parent
9c3ab6d75f
commit
5a7f0c6cd9
10
CHANGES.txt
10
CHANGES.txt
|
@ -70,6 +70,8 @@ New Features
|
|||
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)
|
||||
|
||||
12. SOLR-795: SpellCheckComponent supports building indices on optimize if configured in solrconfig.xml
|
||||
(Jason Rennie, shalin)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
@ -89,8 +91,6 @@ Bug Fixes
|
|||
|
||||
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
|
||||
----------------------
|
||||
|
@ -100,12 +100,6 @@ Other Changes
|
|||
|
||||
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
|
||||
----------------------
|
||||
|
|
|
@ -51,7 +51,6 @@ import org.apache.solr.schema.FieldType;
|
|||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.search.SolrIndexSearcher;
|
||||
import org.apache.solr.spelling.*;
|
||||
import org.apache.solr.util.RefCounted;
|
||||
import org.apache.solr.util.plugin.NamedListPluginLoader;
|
||||
import org.apache.solr.util.plugin.SolrCoreAware;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
@ -273,10 +272,12 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
|
|||
}
|
||||
}
|
||||
// Register event listeners for this SpellChecker
|
||||
core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, true));
|
||||
if (Boolean.parseBoolean((String)spellchecker.get("buildOnCommit"))) {
|
||||
core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false));
|
||||
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());
|
||||
core.registerNewSearcherListener(new SpellCheckerListener(core, checker, false));
|
||||
core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize));
|
||||
}
|
||||
} else {
|
||||
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 final SolrCore core;
|
||||
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.checker = checker;
|
||||
this.firstSearcher = firstSearcher;
|
||||
this.buildOnCommit = buildOnCommit;
|
||||
this.buildOnOptimize = buildOnOptimize;
|
||||
}
|
||||
|
||||
public void init(NamedList args) {
|
||||
|
@ -329,7 +332,8 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
|
|||
|
||||
public void newSearcher(SolrIndexSearcher newSearcher,
|
||||
SolrIndexSearcher currentSearcher) {
|
||||
if (firstSearcher) {
|
||||
if (currentSearcher == null) {
|
||||
// firstSearcher event
|
||||
try {
|
||||
LOG.info("Loading spell index for spellchecker: "
|
||||
+ checker.getDictionaryName());
|
||||
|
@ -339,6 +343,20 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
|
|||
}
|
||||
} else {
|
||||
// newSearcher event
|
||||
if (buildOnCommit) {
|
||||
buildSpellIndex(newSearcher);
|
||||
} else if (buildOnOptimize) {
|
||||
if (newSearcher.getReader().isOptimized()) {
|
||||
buildSpellIndex(newSearcher);
|
||||
} 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);
|
||||
|
@ -348,8 +366,6 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void postCommit() {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue