Skip to content

Apache Lucene open-source search software

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

Shalin Shekhar Mangar5a7f0c6cd96b
diff --git a/CHANGES.txt b/CHANGES.txt
index 0f1ded61269..75d2716fe2d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -45,17 +45,17 @@ New Features
3. SOLR-658: Allow Solr to load index from arbitrary directory in dataDir
(Noble Paul, Akshay Ukey via shalin)
-
+
4. SOLR-793: Add 'commitWithin' argument to the update add command. This behaves
- similar to the global autoCommit maxTime argument except that it is set for
+ similar to the global autoCommit maxTime argument except that it is set for
each request. (ryan)
5. SOLR-670: Add support for rollbacks in UpdateHandler. This allows user to rollback all changes
since the last commit. (Noble Paul, koji via shalin)
-
- 6. SOLR-813: Adding DoubleMetaphone Filter and Factory. Similar to the PhoneticFilter,
+
+ 6. SOLR-813: Adding DoubleMetaphone Filter and Factory. Similar to the PhoneticFilter,
but this uses DoubleMetaphone specific calls (including alternate encoding)
- (Todd Feak via ryan)
+ (Todd Feak via ryan)
7. SOLR-680: Add StatsComponent. This gets simple statists on matched numeric fields,
including: min, max, mean, median, stddev. (koji, ryan)
@@ -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,13 +100,7 @@ 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
----------------------
1. SOLR-776: Added in ability to sign artifacts via Ant for releases (gsingers)
diff --git a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
index 5ec378935d2..898a6fdb86a 100644
--- a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
+++ b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
@@ -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,17 +343,29 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
}
} else {
// newSearcher event
- 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);
+ 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);
+ } catch (Exception e) {
+ log.error(
+ "Exception in building spell check index for spellchecker: " + checker.getDictionaryName(), e);
+ }
+ }
+
public void postCommit() {
}
}