Search in sources :

Example 1 with Spellcheck

use of org.nextprot.api.solr.SearchResult.Spellcheck 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;
}
Also used : Spellcheck(org.nextprot.api.solr.SearchResult.Spellcheck) FacetField(org.apache.solr.client.solrj.response.FacetField) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Count(org.apache.solr.client.solrj.response.FacetField.Count) Collation(org.apache.solr.client.solrj.response.SpellCheckResponse.Collation) SpellCheckResponse(org.apache.solr.client.solrj.response.SpellCheckResponse) Suggestion(org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion) SolrDocument(org.apache.solr.common.SolrDocument) Facet(org.nextprot.api.solr.SearchResult.Facet)

Aggregations

FacetField (org.apache.solr.client.solrj.response.FacetField)1 Count (org.apache.solr.client.solrj.response.FacetField.Count)1 SpellCheckResponse (org.apache.solr.client.solrj.response.SpellCheckResponse)1 Collation (org.apache.solr.client.solrj.response.SpellCheckResponse.Collation)1 Suggestion (org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 Facet (org.nextprot.api.solr.SearchResult.Facet)1 Spellcheck (org.nextprot.api.solr.SearchResult.Spellcheck)1