List of usage examples for org.apache.solr.client.solrj.response SpellCheckResponse getSuggestionMap
public Map<String, Suggestion> getSuggestionMap()
From source file:com.gisgraphy.domain.valueobject.FulltextResultsDto.java
License:Open Source License
/** * @param response/*from w w w . j a v a2 s .c o m*/ * The {@link QueryResponse} to build the DTO */ public FulltextResultsDto(QueryResponse response) { super(); this.results = SolrUnmarshaller.unmarshall(response); this.QTime = response.getQTime(); this.numFound = response.getResults().getNumFound(); this.maxScore = response.getResults().getMaxScore(); this.resultsSize = results == null ? 0 : results.size(); SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse(); if (spellCheckResponse != null) { Map<String, Suggestion> suggestionMapInternal = spellCheckResponse.getSuggestionMap(); if (suggestionMapInternal != null) { suggestionMap = spellCheckResponse.getSuggestionMap(); } if (spellCheckResponse.getCollatedResult() != null) { collatedResult = spellCheckResponse.getCollatedResult().trim(); } List<Suggestion> suggestions = spellCheckResponse.getSuggestions(); if (suggestions.size() != 0) { StringBuffer sb = new StringBuffer(); for (Suggestion suggestion : suggestions) { sb.append(suggestion.getSuggestions().get(0)).append(" "); } spellCheckProposal = sb.toString().trim(); } } }
From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java
License:Open Source License
/** * Converts the suggestions from the Solrj format to JSON format. * * @param response The SpellCheckResponse object containing the spellcheck results. * @return The spellcheck suggestions as JSON object or null if something goes wrong. *//* w w w . j av a 2s.c o m*/ private JSONObject getConvertedResponseAsJson(SpellCheckResponse response) { if (null == response) { return null; } final JSONObject suggestions = new JSONObject(); final Map<String, Suggestion> solrSuggestions = response.getSuggestionMap(); // Add suggestions to the response for (final String key : solrSuggestions.keySet()) { // Indicator to ignore words that are erroneously marked as misspelled. boolean ignoreWord = false; // Suggestions that are in the form "Xxxx" -> "xxxx" should be ignored. if (Character.isUpperCase(key.codePointAt(0))) { final String lowercaseKey = key.toLowerCase(); // If the suggestion map doesn't contain the lowercased word, ignore this entry. if (!solrSuggestions.containsKey(lowercaseKey)) { ignoreWord = true; } } if (!ignoreWord) { try { // Get suggestions as List final List<String> l = solrSuggestions.get(key).getAlternatives(); suggestions.put(key, l); } catch (JSONException e) { LOG.debug("Exception while converting Solr spellcheckresponse to JSON. ", e); } } } return suggestions; }