static Map<String, List<Alternative>> extreactSuggestions(QueryResponse response) { if (response == null || response.getSpellCheckResponse() == null || response.getSpellCheckResponse().getSuggestions() == null) { return Collections.emptyMap(); } Map<String, List<Alternative>> alternativesMap = new LinkedHashMap<>(); SpellCheckResponse scr = response.getSpellCheckResponse(); if (scr != null && scr.getSuggestions() != null) { for (SpellCheckResponse.Suggestion suggestion : scr.getSuggestions()) { List<Alternative> alternatives = new ArrayList<>(); if (!CollectionUtils.isEmpty(suggestion.getAlternatives())) { for (int i = 0; i < suggestion.getAlternatives().size(); i++) { alternatives.add(new Alternative(suggestion.getToken(), suggestion.getOriginalFrequency(), suggestion.getAlternatives().get(i), suggestion.getAlternativeFrequencies().get(i))); } } alternativesMap.put(suggestion.getToken(), alternatives); } } return alternativesMap; }
@SuppressWarnings("unchecked") private void collectShardSuggestions(NamedList nl, SpellCheckMergeData mergeData) { SpellCheckResponse spellCheckResp = new SpellCheckResponse(nl); for (SpellCheckResponse.Suggestion suggestion : spellCheckResp.getSuggestions()) { mergeData.origVsSuggestion.put(suggestion.getToken(), suggestion); HashSet<String> suggested = mergeData.origVsSuggested.get(suggestion.getToken());
/** * @see org.opencms.jsp.search.result.I_CmsSearchResultWrapper#getDidYouMeanSuggestion() */ public Suggestion getDidYouMeanSuggestion() { I_CmsSearchControllerDidYouMean didYouMeanController = getController().getDidYouMean(); Suggestion usedSuggestion = null; if ((null != didYouMeanController) && ((m_solrResultList != null) && (m_solrResultList.getSpellCheckResponse() != null))) { // find most suitable suggestion List<Suggestion> suggestionList = m_solrResultList.getSpellCheckResponse().getSuggestions(); int queryLength = m_controller.getDidYouMean().getState().getQuery().length(); int minDistance = queryLength + 1; for (Suggestion suggestion : suggestionList) { int currentDistance = Math.abs(queryLength - suggestion.getToken().length()); if (currentDistance < minDistance) { usedSuggestion = suggestion; minDistance = currentDistance; } } } return usedSuggestion; }
if (spellCheckResponse != null && spellCheckResponse.getSuggestions() != null && spellCheckResponse.getSuggestions().size() > 0) { putSpellChecks(spellCheckResponse, queue, filter, configuration, solrServer); noDocs = true;
if (spellCheckResponse != null && spellCheckResponse.getSuggestions() != null && spellCheckResponse.getSuggestions().size() > 0) { putSpellChecks(spellCheckResponse, queue, filter, configuration, solrServer); noDocs = true;
private void putSpellChecks(SpellCheckResponse spellCheckResponse, final Deque<SolrResultRow> queue, Filter filter, OakSolrConfiguration configuration, SolrClient solrServer) throws IOException, SolrServerException { List<SpellCheckResponse.Suggestion> suggestions = spellCheckResponse.getSuggestions(); Collection<String> alternatives = new ArrayList<String>(suggestions.size()); for (SpellCheckResponse.Suggestion suggestion : suggestions) { alternatives.addAll(suggestion.getAlternatives()); } // ACL filter spellcheck results for (String alternative : alternatives) { SolrQuery solrQuery = new SolrQuery(); solrQuery.setParam("q", alternative); solrQuery.setParam("df", configuration.getCatchAllField()); solrQuery.setParam("q.op", "AND"); solrQuery.setParam("rows", "100"); QueryResponse suggestQueryResponse = solrServer.query(solrQuery); SolrDocumentList results = suggestQueryResponse.getResults(); if (results != null && results.getNumFound() > 0) { for (SolrDocument doc : results) { if (filter.isAccessible(String.valueOf(doc.getFieldValue(configuration.getPathField())))) { queue.add(new SolrResultRow(alternative)); break; } } } } }
private void putSpellChecks(SpellCheckResponse spellCheckResponse, final Deque<SolrResultRow> queue, Filter filter, OakSolrConfiguration configuration, SolrClient solrServer) throws IOException, SolrServerException { List<SpellCheckResponse.Suggestion> suggestions = spellCheckResponse.getSuggestions(); Collection<String> alternatives = new ArrayList<String>(suggestions.size()); for (SpellCheckResponse.Suggestion suggestion : suggestions) { alternatives.addAll(suggestion.getAlternatives()); } // ACL filter spellcheck results for (String alternative : alternatives) { SolrQuery solrQuery = new SolrQuery(); solrQuery.setParam("q", alternative); solrQuery.setParam("df", configuration.getCatchAllField()); solrQuery.setParam("q.op", "AND"); solrQuery.setParam("rows", "100"); QueryResponse suggestQueryResponse = solrServer.query(solrQuery); SolrDocumentList results = suggestQueryResponse.getResults(); if (results != null && results.getNumFound() > 0) { for (SolrDocument doc : results) { if (filter.isAccessible(String.valueOf(doc.getFieldValue(configuration.getPathField())))) { queue.add(new SolrResultRow(alternative)); break; } } } } }
SpellCheckResponse spellCheckResponse = queryResponse.getSpellCheckResponse(); if (spellCheckResponse != null) { List<SpellCheckResponse.Suggestion> suggestions = spellCheckResponse.getSuggestions(); for (SpellCheckResponse.Suggestion suggestion : suggestions) { spellingSuggestionsByToken.put(suggestion.getToken(), suggestion.getAlternatives());