I am using spring data solr 3.0.6, and standalone solr server 7.0.0 and I have multiple solr cores in my solr server, and I want to choose one of them dynamically , Here is the configuration I Have
@Configuration
@EnableSolrRepositories(basePackages = "com.solr.repository")
public class SolrConfiguration
{
@Bean
public SolrOperations solrTemplate(SolrClient solr) {
return new SolrTemplate(solr);
}
@Bean(name = "solrClient")
public SolrClient createSolrClient()
{
HttpSolrClient.Builder builder = new HttpSolrClient.Builder().withBaseSolrUrl(solrInstanceUrl);
return builder.build();
}
}
SolrRepository
public interface SolrRepository extends SolrCrudRepository<SolrDocument, Integer>
{
@Query("name:*?0* OR content:*?0*")
@Highlight()
public HighlightPage<SolrDocument> findByQueryAnnotation(String searchTerm, Pageable pageable);
}
SolrDocument (domain class for Solr repository)
@SolrDocument
public class SolrDocument
{
}
ServicePojo (service class)
public class ServicePojo
{
@Autowired
SolrRepository solrRepository;
public void findData(int id)
{
solrRepository.findById(id);
}
}
Now I want to use methods of repository interface like findById()
etc, but as I mentioned above, I have different cores, and I want to point a specific core to perform searching, before calling method solrRepository.findById() I need to mention which core it should point. So where we can tell to solr server , which Core to be used ?
If I use annotation @SolrDocument(collectionName="core1")
, then it works fine and it points to "core1", but I want this to be dynamic. Please help