private void extractSpellCheckInfo(NamedList<Object> spellInfo) { _spellResponse = new SpellCheckResponse(spellInfo); }
QueryResponse response = this.externalServicesAccess.getServer().query(enhancedParams); SolrDocumentList results = response.getResults(); if (response.getSpellCheckResponse() != null && !response.getSpellCheckResponse().isCorrectlySpelled() && StringUtils.isNotEmpty(response.getSpellCheckResponse().getCollatedResult())) { enhancedParams = SolrQueryUtils.applySpellcheckSuggestion(enhancedParams, response.getSpellCheckResponse() .getCollatedResult()); SolrDocumentList spellcheckResults = this.externalServicesAccess.getServer().query(enhancedParams).getResults();
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());
response.getSpellCheckResponse().getCollatedResult().replaceFirst("\\*$","") : null;
final Map<String, Suggestion> solrSuggestions = response.getSuggestionMap();
@Override public SuggestionResults fetchSuggections(final SolrIndex<FulltextIndexSchema> index, final String query) { SolrQuery params = new SolrQuery(); params.set(PARAM_QT, "/suggest"); params.set(PARAM_QUERY, query); params.set(PARAM_SPELLCHECK, "true"); QueryResponse response = null; try { response = index.query(params); } catch (final SearchParserException spe) { log.debug("Error in query {}", query, spe); throw new SearchException("Error in query " + query, spe); } final SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse(); if (spellCheckResponse == null) { return new SuggestionResults(); } final Suggestion suggestion = spellCheckResponse.getSuggestion(query); if (suggestion == null) { return new SuggestionResults(); } List<SuggestionResult> alternatives = new ArrayList<SuggestionResult>(); for (String token : suggestion.getAlternatives()) { alternatives.add(new SuggestionResult(token)); } return new SuggestionResults(suggestion.getNumFound(), suggestion.getOriginalFrequency(), alternatives); }
QueryResponse response = this.externalServicesAccess.getSolrConnection(this).query(query); SolrDocumentList results = response.getResults(); if (response.getSpellCheckResponse() != null && !response.getSpellCheckResponse().isCorrectlySpelled() && StringUtils.isNotEmpty(response.getSpellCheckResponse().getCollatedResult())) { SolrQueryUtils.applySpellcheckSuggestion(query, response.getSpellCheckResponse().getCollatedResult()); this.logger.debug("Searching [{}] with spellchecked query [{}]", this.getIdentifier(), query); SolrDocumentList spellcheckResults =
/** * @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; }
/** * @see org.opencms.jsp.search.result.I_CmsSearchResultWrapper#getDidYouMeanCollated() */ public String getDidYouMeanCollated() { String suggestion = null; I_CmsSearchControllerDidYouMean didYouMeanController = getController().getDidYouMean(); if ((null != didYouMeanController) && didYouMeanController.getConfig().getCollate()) { if ((m_solrResultList != null) && (m_solrResultList.getSpellCheckResponse() != null)) { suggestion = m_solrResultList.getSpellCheckResponse().getCollatedResult(); } } return suggestion; }
if (response.getSpellCheckResponse() != null && !response.getSpellCheckResponse().isCorrectlySpelled()) { String suggestedQuery = response.getSpellCheckResponse().getCollatedResult(); if (StringUtils.isEmpty(suggestedQuery)) { return results;
if (spellCheckResponse != null && spellCheckResponse.getSuggestions() != null && spellCheckResponse.getSuggestions().size() > 0) { putSpellChecks(spellCheckResponse, queue, filter, configuration, solrServer); noDocs = true;
String recommendedQuery = solrQueryResponse.getSpellCheckResponse().getCollatedResult(); if (StringUtils.isNotBlank(recommendedQuery)) { result.setSpellCheckQuery(recommendedQuery);
private void extractSpellCheckInfo(NamedList<Object> spellInfo) { _spellResponse = new SpellCheckResponse(spellInfo); }
if (spellCheckResponse != null && spellCheckResponse.getSuggestions() != null && spellCheckResponse.getSuggestions().size() > 0) { putSpellChecks(spellCheckResponse, queue, filter, configuration, solrServer); noDocs = true;
private void extractSpellCheckInfo(NamedList<Object> spellInfo) { _spellResponse = new SpellCheckResponse(spellInfo); }
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());