Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package de.wellnerbou.solr;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.SolrOperations;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.repository.query.SolrEntityInformation;
import org.springframework.data.solr.repository.support.SimpleSolrRepository;
public class YourRepository extends SimpleSolrRepository<YourSolrDocument, String> {
private final SolrEntityInformation<YourSolrDocument, String> metadata;
public YourRepository(final SolrOperations solrOperations, final SolrEntityInformation<YourSolrDocument, String> metadata) {
super(solrOperations, metadata);
this.metadata = metadata; // as SimpleSolrRepository#metadata is private, we have to store it in this class again
}
public Page<YourSolrDocument> findById(final String id, final Pageable page) {
final SimpleQuery query = new SimpleQuery("id:" + id);
// now call the overloaded query method handing in your collection name
return getSolrOperations().queryForPage(metadata.getCollectionName(), query, YourSolrDocument.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.