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 7e077c3 commit 56a87bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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.CollectionUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -206,7 +207,17 @@ public <T> T execute(String collection, CollectionCallback<T> action) {
Assert.notNull(action, "Action must not be null!");

try {
SolrClient solrClient = this.solrClientFactory.getSolrClient(collection);

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 @@ -40,6 +40,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 @@ -109,6 +110,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 @@ -1265,6 +1267,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 56a87bd

Please sign in to comment.