Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Core Support in spring-data-solr 3.1.0 M1 [DATASOLR-450] #531

Open
spring-projects-issues opened this issue Feb 28, 2018 · 1 comment

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Feb 28, 2018

Paul Wellner Bou opened DATASOLR-450 and commented

I am setting up a new project which talks to Solr and would like to use the most recent versions of spring/spring-data-solr.

I noticed that the multicoreSupport which was there in 3.0 still was removed (https://jira.spring.io/browse/DATASOLR-364).

I need to make the solr core configurable via Properties: Is there any way to do this? With spring-data-solr 2.1.6 I used to do it like this:

@Bean
@Autowired
public SolrTemplate solrTemplate(final SolrClientFactory solrClientFactory) {
	return new SolrTemplate(solrClientFactory, solrCore);
}

This second parameter for SolrTemplate is not there any more.

Is there still a way to configure the core name with properties?

Thanks


Affects: 3.1 M1 (Lovelace)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 1, 2018

Paul Wellner Bou commented

Found a way... Unfortunately again without beeing able to use the annotated repository interface:

@Bean
@Autowired
public MySolrRepository solrRepository(SolrTemplate solrTemplate, @Value("${solr.core:mycore}") String solrCore) {
    return new MySolrRepository(solrTemplate, new CollectionAwareEntityInformationFacade<>(Document.class, solrCore));
}
public class CollectionAwareEntityInformationFacade<T, ID> implements SolrEntityInformation<T, ID> {

	private SolrEntityInformation<T, ID> solrEntityInformation;
	private String collectionName;

	public CollectionAwareEntityInformationFacade(Class<T> type, String collectionName) {
		this(createWrappendSolrEntityInformation(type), collectionName);
	}

	public CollectionAwareEntityInformationFacade(SolrEntityInformation<T, ID> solrEntityInformation, String collectionName) {
		this.solrEntityInformation = solrEntityInformation;
		this.collectionName = collectionName;
	}

	/**
	 * Copied from {@link org.springframework.data.solr.repository.support.SimpleSolrRepository}.
	 */
	private static SolrEntityInformation createWrappendSolrEntityInformation(Class type) {
		return new SolrEntityInformationCreatorImpl(new SimpleSolrMappingContext()).getEntityInformation(type);
	}

	@Override
	public String getCollectionName() {
		return collectionName;
	}
	
	// ... other implemented methods here, wrapping solrEntityInformation
}

I assume there any way to hook into the RepositoryFactory beans while creating the context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants