You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2012/07/03 19:36:40 UTC
svn commit: r1356842 - in /lucene/dev/trunk/solr: ./
core/src/java/org/apache/solr/update/
core/src/test-files/solr/collection1/conf/ core/src/test/org/apache/solr/
Author: markrmiller
Date: Tue Jul 3 17:36:38 2012
New Revision: 1356842
URL: http://svn.apache.org/viewvc?rev=1356842&view=rev
Log:
SOLR-3587: After reloading a SolrCore, the original Analyzer is still used rather than a new one
Added:
lucene/dev/trunk/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1356842&r1=1356841&r2=1356842&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Jul 3 17:36:38 2012
@@ -46,6 +46,9 @@ Bug Fixes
* SOLR-3467: ExtendedDismax escaping is missing several reserved characters
(Michael Dodsworth via janhoy)
+
+* SOLR-3587: After reloading a SolrCore, the original Analyzer is still used rather than a new
+ one. (Alexey Serba, yonik, rmuir, Mark Miller)
Other Changes
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java?rev=1356842&r1=1356841&r2=1356842&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java Tue Jul 3 17:36:38 2012
@@ -198,7 +198,7 @@ public class DirectUpdateHandler2 extend
Document luceneDocument = cmd.getLuceneDocument();
// SolrCore.verbose("updateDocument",updateTerm,luceneDocument,writer);
- writer.updateDocument(updateTerm, luceneDocument);
+ writer.updateDocument(updateTerm, luceneDocument, schema.getAnalyzer());
// SolrCore.verbose("updateDocument",updateTerm,"DONE");
@@ -219,7 +219,7 @@ public class DirectUpdateHandler2 extend
} else {
// allow duplicates
- writer.addDocument(cmd.getLuceneDocument());
+ writer.addDocument(cmd.getLuceneDocument(), schema.getAnalyzer());
if (ulog != null) ulog.add(cmd);
}
@@ -371,7 +371,7 @@ public class DirectUpdateHandler2 extend
synchronized (this) {
IndexWriter writer = solrCoreState.getIndexWriter(core);
- writer.updateDocument(idTerm, luceneDocument);
+ writer.updateDocument(idTerm, luceneDocument, core.getSchema().getAnalyzer());
for (Query q : dbqList) {
writer.deleteDocuments(q);
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java?rev=1356842&r1=1356841&r2=1356842&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java Tue Jul 3 17:36:38 2012
@@ -155,7 +155,11 @@ public class SolrIndexConfig {
}
public IndexWriterConfig toIndexWriterConfig(IndexSchema schema) {
- IndexWriterConfig iwc = new IndexWriterConfig(luceneVersion, schema.getAnalyzer());
+ // so that we can update the analyzer on core reload, we pass null
+ // for the default analyzer, and explicitly pass an analyzer on
+ // appropriate calls to IndexWriter
+
+ IndexWriterConfig iwc = new IndexWriterConfig(luceneVersion, null);
if (maxBufferedDocs != -1)
iwc.setMaxBufferedDocs(maxBufferedDocs);
Modified: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml?rev=1356842&r1=1356841&r2=1356842&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml Tue Jul 3 17:36:38 2012
@@ -147,11 +147,15 @@
</fieldtype>
<fieldtype name="teststop" class="solr.TextField">
- <analyzer>
+ <analyzer type="index">
<tokenizer class="solr.LowerCaseTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.StopFilterFactory" words="stopwords.txt"/>
</analyzer>
+ <analyzer type="query">
+ <tokenizer class="solr.LowerCaseTokenizerFactory"/>
+ <filter class="solr.StandardFilterFactory"/>
+ </analyzer>
</fieldtype>
<!-- fieldtypes in this section isolate tokenizers and tokenfilters for testing -->
Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java?rev=1356842&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java Tue Jul 3 17:36:38 2012
@@ -0,0 +1,174 @@
+package org.apache.solr;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.HttpSolrServer;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.After;
+
+public class AnalysisAfterCoreReloadTest extends AbstractSolrTestCase {
+ private File homeDir;
+ int port = 0;
+ static final String context = "/solr";
+ JettySolrRunner jetty;
+ static final String collection = "collection1";
+
+ @After
+ public void cleanUp() throws Exception {
+ jetty.stop();
+ if (homeDir != null && homeDir.isDirectory() && homeDir.exists())
+ recurseDelete(homeDir);
+ }
+
+ @Override
+ public String getSolrHome() {
+ return homeDir.getAbsolutePath();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ homeDir = new File(TEMP_DIR + File.separator + "solr-test-home-" + System.nanoTime());
+ homeDir.mkdirs();
+ FileUtils.copyDirectory(new File(getFile("solr/" + collection).getParent()), homeDir, false);
+
+ super.setUp();
+
+ jetty = new JettySolrRunner(getSolrHome(), context, 0 );
+ jetty.start(false);
+ port = jetty.getLocalPort();
+ }
+
+ public void testStopwordsAfterCoreReload() throws Exception {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.setField( "id", "42" );
+ doc.setField( "teststop", "terma stopworda stopwordb stopwordc" );
+
+ // default stopwords - stopworda and stopwordb
+
+ UpdateRequest up = new UpdateRequest();
+ up.setAction(ACTION.COMMIT, true, true);
+ up.add( doc );
+ up.process( getSolrCore() );
+
+ SolrQuery q = new SolrQuery();
+ QueryRequest r = new QueryRequest( q );
+ q.setQuery( "teststop:terma" );
+ assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:stopworda" );
+ assertEquals( 0, r.process( getSolrCore() ).getResults().size() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:stopwordb" );
+ assertEquals( 0, r.process( getSolrCore() ).getResults().size() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:stopwordc" );
+ assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
+
+ // overwrite stopwords file with stopword list ["stopwordc"] and reload the core
+ overwriteStopwords("stopwordc\n");
+ SolrServer coreadmin = getSolrAdmin();
+ CoreAdminRequest.reloadCore(collection, coreadmin);
+
+ up.process( getSolrCore() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:terma" );
+ assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:stopworda" );
+ // stopworda is no longer a stopword
+ assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:stopwordb" );
+ // stopwordb is no longer a stopword
+ assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
+
+ q = new SolrQuery();
+ r = new QueryRequest( q );
+ q.setQuery( "teststop:stopwordc" );
+ // stopwordc should be a stopword
+ assertEquals( 0, r.process( getSolrCore() ).getResults().size() );
+ }
+
+ private void overwriteStopwords(String stopwords) throws IOException {
+ SolrCore core = h.getCoreContainer().getCore(collection);
+ try {
+ String configDir = core.getResourceLoader().getConfigDir();
+ File file = new File(configDir, "stopwords.txt");
+ FileUtils.writeStringToFile(file, stopwords);
+ } finally {
+ core.close();
+ }
+ }
+
+ protected SolrServer getSolrAdmin() {
+ return createServer("");
+ }
+ protected SolrServer getSolrCore() {
+ return createServer(collection);
+ }
+ private SolrServer createServer( String name ) {
+ try {
+ // setup the server...
+ String url = "http://localhost:"+port+context+"/"+name;
+ HttpSolrServer s = new HttpSolrServer( url );
+ s.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
+ s.setDefaultMaxConnectionsPerHost(100);
+ s.setMaxTotalConnections(100);
+ return s;
+ }
+ catch( Exception ex ) {
+ throw new RuntimeException( ex );
+ }
+ }
+
+ @Override
+ public String getSchemaFile() {
+ return "schema.xml";
+ }
+
+ @Override
+ public String getSolrConfigFile() {
+ return "solrconfig.xml";
+ }
+
+}
\ No newline at end of file