Introduction
Reading your comments. I see that there is a bit of confusion as to what SolrJ and
Spring Data are for Apache Solr .
SolrJ - Solr ( ).
SolrJ - API, Java Solr. SolrJ Solr Solr .
Spring Apache Solr Spring Data Apache Solr Search Server Spring ( Solr SolrJ).
Solr Spring Data ver. 1.2.0.RELEASE SolrJ 4.7.2, Solr 6.2.0 (, SolrCloud).
, Solr SolrJ (, , ).
, Solr v.6.2.1 SolrJ 6.2.1, , , Solr Spring 2.1.3.RELEASE( SolrJ 5.5.0).
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
</dependencies>
, , , Solr Data .
, Solr Spring Data, Repository, RepositoryImpl, , SolrJ.
@Component
public class ProductsRepositoryImpl implements ProductsRepositoryCustom {
@Autowired
private SolrServer solrServer;
public ProductsRepositoryImpl() {};
public ProductsRepositoryImpl(SolrServer solrServer) {
this.solrServer = solrServer;
}
public List<Map<String, Object>> findFields(String id, List<String> fields)
{
SolrQuery solrQuery = new SolrQuery("id:" + id);
solrQuery.setFields(fields.toArray(new String[0]));
try {
QueryResponse response = this.solrServer.query(solrQuery);
return response.getResults()
.stream()
.map(d ->
{
return d.entrySet()
.stream()
.filter(e -> fields.contains(e.getKey()))
.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
}).collect(Collectors.toList());
} catch (SolrServerException e) {
}
return Collections.emptyList();
}
}