AbstractReSearcherComponent extends SearchComponent implements ReSearcherParams, SolrCoreAware, PluginInfoInitialized { public boolean preProcessOriginalQuery(ReSearcherRequestContext ctx, ResponseBuilder rb) { if (commonMisspellingsFileLocation == null) { return false; } String originalQuery = rb.getQueryString(); String correctedQuery = CommonMisspellings.correctedQuery(originalQuery, commonMisspellingsMap); if (correctedQuery != null) { LOG.info("Original query : '" + originalQuery + "' is corrected to '" + correctedQuery + "', checking its results..."); ctx.setCorrectedQuery(correctedQuery); try { long hits = ctx.getHandler().handleSuggestionHitsRequest(ctx, correctedQuery, componentNames); LOG.info("New query : '" + correctedQuery + "' produced " + hits + " hits"); if (hits > maxOriginalResults) { ctx.setCorrectedQueryHits(hits); List<String> suggestionsList = new ArrayList<String>(); suggestionsList.add(correctedQuery); Map<String, Long> suggestionsHitCounts = new HashMap<String, Long>(); suggestionsHitCounts.put(correctedQuery, hits); ReSearcherUtils.addValueToResult(rb, getSuggestionsTagName(), suggestionsList); ReSearcherUtils.addValueToResult(rb, getSuggestionsTagName() + "_hit_counts", suggestionsHitCounts); SolrQueryResponse rsp = ctx.getHandler().handleSuggestionResponseRequest(ctx, correctedQuery, getComponentName(), rb); rb.rsp.add("spellchecked_response", rsp.getValues().get("response")); rb.rsp.add("spellchecked_facet_counts", rsp.getValues().get("facet_counts")); rb.rsp.add("spellchecked_terms", rsp.getValues().get("terms")); rb.rsp.add("spellchecked_termVectors", rsp.getValues().get("termVectors")); rb.rsp.add("spellchecked_highlighting", rsp.getValues().get("highlighting")); rb.rsp.add("spellchecked_stats", rsp.getValues().get("stats")); rb.rsp.add("spellchecked_grouped", rsp.getValues().get("grouped")); return true; } } catch (Exception e) { String msg = "Error while correcting original query '" + originalQuery + "' to query '" + correctedQuery + "' and searching for results!"; LOG.error(msg, e); throw new RuntimeException(msg, e); } } return false; }  @Override @SuppressWarnings("rawtypes") void init(NamedList args); @Override void init(PluginInfo info); @Override void inform(SolrCore core); @Override void prepare(ResponseBuilder rb); @Override void process(ResponseBuilder rb); @Override void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq); @Override void finishStage(ResponseBuilder rb); void doProcess(ResponseBuilder rb); boolean preProcessOriginalQuery(ReSearcherRequestContext ctx, ResponseBuilder rb); SolrCore getCore(); List<SearchComponent> getQueryOnlyComponents(); ShardHandlerFactory getShardHandlerFactory(); Set<String> getComponentNames(); int getMaxOriginalResults();  }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testPreProcessOriginalQuery() { DummyAbstractReSearcherComponent comp = new DummyAbstractReSearcherComponent(); NamedList args = new NamedList(); args.add("commonMisspellingsFile", "../solr/collection1/conf/common_misspellings_en.txt"); comp.init(args); SolrQueryRequestBase req = new LocalSolrQueryRequest(null, (SolrParams) null); ResponseBuilder rb = new ResponseBuilder(req, null, null); ReSearcherRequestContext ctx = new ReSearcherRequestContext(rb); rb.setQueryString("some \"acadamy query\" for test"); try { comp.preProcessOriginalQuery(ctx, rb); } catch (Throwable thr) { } assertNotNull(ctx.getCorrectedQuery()); assertEquals(ctx.getCorrectedQuery(), "some \"academy query\" for test"); rb.setQueryString("acadamy some \" acadamy query \" for test"); try { comp.preProcessOriginalQuery(ctx, rb); } catch (Throwable thr) { } assertNotNull(ctx.getCorrectedQuery()); assertEquals(ctx.getCorrectedQuery(), "academy some \" academy query \" for test"); rb.setQueryString("\"acadamy\" some \" acadamy query \" for \"test\""); try { comp.preProcessOriginalQuery(ctx, rb); } catch (Throwable thr) { } assertNotNull(ctx.getCorrectedQuery()); assertEquals(ctx.getCorrectedQuery(), "\"academy\" some \" academy query \" for \"test\""); rb.setQueryString("\" acadamy\""); try { comp.preProcessOriginalQuery(ctx, rb); } catch (Throwable thr) { } assertNotNull(ctx.getCorrectedQuery()); assertEquals(ctx.getCorrectedQuery(), "\" academy\""); rb.setQueryString("\"acadamy \" "); try { comp.preProcessOriginalQuery(ctx, rb); } catch (Throwable thr) { } assertNotNull(ctx.getCorrectedQuery()); assertEquals(ctx.getCorrectedQuery(), "\"academy \""); rb.setQueryString("some \"academy query\" for test"); ctx.setCorrectedQuery(null); try { comp.preProcessOriginalQuery(ctx, rb); } catch (Throwable thr) { } assertNull(ctx.getCorrectedQuery()); }