diff --git a/CHANGES.txt b/CHANGES.txt index 155fd8c9ba1..665741b2b04 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -438,7 +438,9 @@ Bug Fixes problems in Resin, and could potentially cause problems for customized usages of SolrServlet. -36. SOLR-585: Now sets the QParser on the ResponseBuilder (gsingers) +36. SOLR-585: Now sets the QParser on the ResponseBuilder (gsingers) + +37. SOLR-604: If the spellchecking path is relative, make it relative to the Solr Data Directory. (Shalin Shekhar Mangar via gsingers) Other Changes 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xml index 6d6063eb698..ad2981f9c8a 100755 --- a/example/solr/conf/solrconfig.xml +++ b/example/solr/conf/solrconfig.xml @@ -504,7 +504,7 @@ default spell - ./spellchecker + ./spellchecker1 @@ -512,17 +512,17 @@ spell org.apache.lucene.search.spell.JaroWinklerDistance - ./spellchecker + ./spellchecker2 - + ./spellcheckerFile + diff --git a/example/solr/conf/spellings.txt b/example/solr/conf/spellings.txt new file mode 100644 index 00000000000..d7ede6f5611 --- /dev/null +++ b/example/solr/conf/spellings.txt @@ -0,0 +1,2 @@ +pizza +history \ No newline at end of file diff --git a/src/java/org/apache/solr/core/SolrResourceLoader.java b/src/java/org/apache/solr/core/SolrResourceLoader.java index 684bc58280b..91fc97d18a3 100644 --- a/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -64,6 +64,7 @@ public class SolrResourceLoader implements ResourceLoader private final ClassLoader classLoader; private final String instanceDir; + private String dataDir; private final List waitingForCore = new ArrayList(); private final List waitingForResources = new ArrayList(); @@ -122,6 +123,10 @@ public class SolrResourceLoader implements ResourceLoader public String getConfigDir() { return instanceDir + "conf/"; } + + public String getDataDir() { + return dataDir; + } /** Opens a schema resource by its name. * Override this method to customize loading schema resources. @@ -283,6 +288,7 @@ public class SolrResourceLoader implements ResourceLoader */ public void inform(SolrCore core) { + this.dataDir = core.getDataDir(); for( SolrCoreAware aware : waitingForCore ) { aware.inform( core ); } diff --git a/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java b/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java index 3469cc7cbf7..fd38495073d 100644 --- a/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java +++ b/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java @@ -1,23 +1,24 @@ package org.apache.solr.spelling; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + import org.apache.lucene.analysis.Token; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.search.spell.Dictionary; +import org.apache.lucene.search.spell.LevensteinDistance; import org.apache.lucene.search.spell.SpellChecker; import org.apache.lucene.search.spell.StringDistance; -import org.apache.lucene.search.spell.LevensteinDistance; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.RAMDirectory; import org.apache.solr.common.util.NamedList; import org.apache.solr.core.SolrResourceLoader; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - /** * Abstract base class for all Lucene based spell checking implementations. @@ -51,6 +52,12 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker { public String init(NamedList config, SolrResourceLoader loader) { super.init(config, loader); indexDir = (String) config.get(INDEX_DIR); + //If indexDir is relative then create index inside core.getDataDir() + if (indexDir != null) { + if (!new File(indexDir).isAbsolute()) { + indexDir = loader.getDataDir() + File.separator + indexDir; + } + } sourceLocation = (String) config.get(LOCATION); field = (String) config.get(FIELD); String strDistanceName = (String)config.get(STRING_DISTANCE); diff --git a/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java b/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java index 0ef145f40ee..5305be16a10 100644 --- a/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java +++ b/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java @@ -115,7 +115,7 @@ public class FileBasedSpellChecker extends AbstractLuceneSpellChecker { analyzer = fieldType.getQueryAnalyzer(); } else { log.warning("No fieldType: " + fieldTypeName - + " found for dictionary: " + name); + + " found for dictionary: " + name + ". Using WhitespaceAnalzyer."); analyzer = new WhitespaceAnalyzer(); // check if character encoding is defined diff --git a/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java b/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java index dda8e87d246..c73dc055df0 100644 --- a/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java +++ b/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java @@ -17,6 +17,11 @@ package org.apache.solr.handler.component; +import java.io.File; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -27,12 +32,8 @@ import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryResponse; import org.apache.solr.request.SolrRequestHandler; -import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.spelling.IndexBasedSpellChecker; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import org.apache.solr.util.AbstractSolrTestCase; /** * @since solr 1.3 @@ -140,8 +141,6 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase { idx = blue.indexOf("suggestion", idx + 1); assertTrue(idx + " does not equal: " + -1, idx == -1); - - } public void test() throws Exception { @@ -281,6 +280,37 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase { } + + @SuppressWarnings("unchecked") + public void testRelativeIndexDirLocation() throws Exception { + SolrCore core = h.getCore(); + Map args = new HashMap(); + + args.put(CommonParams.Q, "test"); + args.put(CommonParams.QT, "spellCheckCompRH"); + args.put(SpellCheckComponent.SPELLCHECK_BUILD, "true"); + args.put(SpellCheckComponent.COMPONENT_NAME, "true"); + SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams( + args)); + + File indexDir = new File(core.getDataDir() + File.separator + + "spellchecker1"); + assertTrue( + "spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml", + indexDir.exists()); + + indexDir = new File(core.getDataDir() + File.separator + + "spellchecker2"); + assertTrue( + "spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml", + indexDir.exists()); + + indexDir = new File(core.getDataDir() + File.separator + + "spellchecker3"); + assertTrue( + "spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml", + indexDir.exists()); + } // TODO: add more tests for various spelling options diff --git a/src/test/test-files/solr/conf/solrconfig.xml b/src/test/test-files/solr/conf/solrconfig.xml index 988b7451761..248450c9d8b 100644 --- a/src/test/test-files/solr/conf/solrconfig.xml +++ b/src/test/test-files/solr/conf/solrconfig.xml @@ -331,8 +331,7 @@ default lowerfilt - ./spellchecker - + spellchecker1 @@ -340,7 +339,7 @@ lowerfilt org.apache.lucene.search.spell.JaroWinklerDistance - ./spellchecker + spellchecker2 @@ -348,7 +347,7 @@ external spellings.txt UTF-8 - ./spellchecker + spellchecker3