Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
DATSOLR-364 - Fix duplicate core names in Solr Url when using Multico…
Browse files Browse the repository at this point in the history
…reSolrServerFactory.

We now make sure to use the base url along with the collection callback. This fixes situations where the core name had been falsely appended multiple times.
  • Loading branch information
christophstrobl committed Mar 28, 2017
1 parent 4c49f1f commit 7dd08b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/org/springframework/data/solr/core/SolrTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.springframework.data.solr.core.schema.SolrPersistentEntitySchemaCreator.Feature;
import org.springframework.data.solr.server.SolrClientFactory;
import org.springframework.data.solr.server.support.HttpSolrClientFactory;
import org.springframework.data.solr.server.support.MulticoreSolrClientFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -206,8 +207,16 @@ public <T> T execute(String collection, CollectionCallback<T> action) {

try {

SolrClient solrClient = StringUtils.hasText(collection) ? this.solrClientFactory.getSolrClient(collection)
: this.getSolrClient();
SolrClient solrClient = null;
if(StringUtils.hasText(collection)) {
if(this.solrClientFactory instanceof MulticoreSolrClientFactory) {
solrClient = this.solrClientFactory.getSolrClient();
} else {
solrClient = this.solrClientFactory.getSolrClient(collection);
}
} else {
solrClient = this.getSolrClient();
}
return action.doInSolr(solrClient, collection);
} catch (Exception e) {
DataAccessException resolved = getExceptionTranslator().translateExceptionIfPossible(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.beans.Field;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.params.FacetParams.FacetRangeInclude;
Expand Down Expand Up @@ -106,6 +107,7 @@
import org.springframework.data.solr.core.query.result.StatsResult;
import org.springframework.data.solr.core.query.result.TermsFieldEntry;
import org.springframework.data.solr.core.query.result.TermsPage;
import org.springframework.data.solr.server.support.MulticoreSolrClientFactory;
import org.xml.sax.SAXException;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -1259,6 +1261,23 @@ public void testFindByNameWithSpellcheckSeggestion() {
Assert.assertThat(found.getSuggestions(), Matchers.contains("green"));
}

@Test // DATSOLR-364
public void shouldUseBaseUrlInCollectionCallbackWhenExecutingCommands() {

final HttpSolrClient client = new HttpSolrClient("http://127.0.0.1/solr/");

SolrTemplate solrTemplate = new SolrTemplate(new MulticoreSolrClientFactory(client), "collection-1");

solrTemplate.execute("collection-1", new CollectionCallback<Object>() {
@Override
public Object doInSolr(SolrClient solrClient, String collection) throws SolrServerException, IOException {

Assert.assertThat(((HttpSolrClient)solrClient).getBaseURL(), is("http://127.0.0.1/solr"));
return null;
}
});
}

private void executeAndCheckStatsRequest(StatsOptions statsOptions) {

ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null);
Expand Down

0 comments on commit 7dd08b8

Please sign in to comment.