use of org.nextprot.api.solr.SearchResult.Facet in project nextprot-api by calipho-sib.
the class SolrServiceImpl method buildSearchResult.
private SearchResult buildSearchResult(SolrQuery query, String indexName, String url, QueryResponse response) {
SearchResult results = new SearchResult(indexName, url);
SolrDocumentList docs = response.getResults();
Logger.debug("Response doc size:" + docs.size());
List<Map<String, Object>> res = new ArrayList<>();
Map<String, Object> item = null;
for (SolrDocument doc : docs) {
item = new HashMap<>();
for (Entry<String, Object> e : doc.entrySet()) item.put(e.getKey(), e.getValue());
res.add(item);
}
results.addAllResults(res);
if (query.getStart() != null)
results.setStart(query.getStart());
results.setRows(query.getRows());
results.setElapsedTime(response.getElapsedTime());
results.setFound(docs.getNumFound());
if (docs.getMaxScore() != null)
results.setScore(docs.getMaxScore());
// Facets
List<FacetField> facetFields = response.getFacetFields();
Logger.debug("Response facet fields:" + facetFields.size());
if (facetFields != null) {
Facet facet = null;
for (FacetField ff : facetFields) {
facet = new Facet(ff.getName());
Logger.debug("Response facet field:" + ff.getName() + " count:" + ff.getValueCount());
for (Count c : ff.getValues()) facet.addFacetField(c.getName(), c.getCount());
results.addSearchResultFacet(facet);
}
}
// Spellcheck
SpellCheckResponse spellcheckResponse = response.getSpellCheckResponse();
if (spellcheckResponse != null) {
Spellcheck spellcheckResult = new Spellcheck();
List<Suggestion> suggestions = spellcheckResponse.getSuggestions();
List<Collation> collations = spellcheckResponse.getCollatedResults();
if (collations != null) {
for (Collation c : collations) spellcheckResult.addCollation(c.getCollationQueryString(), c.getNumberOfHits());
}
if (suggestions != null)
for (Suggestion s : suggestions) spellcheckResult.addSuggestions(s.getToken(), s.getAlternatives());
results.setSpellCheck(spellcheckResult);
}
return results;
}
Aggregations