ITPub博客

首页 > > > solr调用lucene底层实现倒排索引源码解析-2

solr调用lucene底层实现倒排索引源码解析-2

作者:longmanma 时间:2019-12-18 18:07:05 0 删除 编辑

4.4 入口是SolrDispatchFilter,整个流程如流程图所示

从上面的流程图可以看出,solr采用filter的模式(如struts2,springmvc使用servlet模式),然后以容器的方式来封装各种Handler,Handler负责处理各种请求,最终调用的是lucene的底层实现。

注意:solr没有使用lucene本身的QueryParser,而是自己重写了这个组件。

4.4.1 SolrDispatchFilter入口

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throwsIOException, ServletException { if (!(request instanceof HttpServletRequest)) return; try{ if (cores == null ||cores.isShutDown()) { try{ init.await(); } catch (InterruptedException e) { //well, no wait then} final String msg = "Error processing the request. CoreContainer is either not initialized or shutting down."; if (cores == null ||cores.isShutDown()) { log.error(msg); throw newUnavailableException(msg); } } AtomicReference wrappedRequest = new AtomicReference (); if (!authenticateRequest(request, response, wrappedRequest)) { // the response and status code have already been // sent return; } if (wrappedRequest.get() != null) { request =wrappedRequest.get(); } request =closeShield(request, retry); response =closeShield(response, retry); if (cores.getAuthenticationPlugin() != null) { log.debug("User principal: {}", ((HttpServletRequest) request).getUserPrincipal()); } // No need to even create the HttpSolrCall object if this path is excluded. if (excludePatterns != null) { String requestPath =((HttpServletRequest) request).getServletPath(); String extraPath =((HttpServletRequest) request).getPathInfo(); if (extraPath != null) { // In embedded mode, servlet path is empty - include all post-context path here for // testing requestPath +=extraPath; } for(Pattern p : excludePatterns) { Matcher matcher =p.matcher(requestPath); if(matcher.lookingAt()) { chain.doFilter(request, response); return; } } } HttpSolrCall call =getHttpSolrCall((HttpServletRequest) request, (HttpServletResponse) response, retry); ExecutorUtil.setServerThreadFlag(Boolean.TRUE); try{ Action result = call.call(); //1 switch(result) { casePASSTHROUGH: chain.doFilter(request, response); break; caseRETRY: doFilter(request, response, chain, true); break; caseFORWARD: request.getRequestDispatcher(call.getPath()).forward(request, response); break; } } finally{ call.destroy(); ExecutorUtil.setServerThreadFlag(null); } } finally {

consumeInputFully((HttpServletRequest) request);

}

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2730/viewspace-3124608/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-12-18

  • 博文量
    492
  • 访问量
    11996