Last active
August 21, 2018 07:15
-
-
Save paulwellnerbou/2ee6ed580ff58429993607120ca4b45b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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