コード例 #1
0
  @Override
  public void process(ResponseBuilder rb) throws IOException {
    SolrQueryRequest req = rb.req;
    if (rb.doHighlights) {
      SolrParams params = req.getParams();

      String[] defaultHighlightFields; // TODO: get from builder by default?

      if (rb.getQparser() != null) {
        defaultHighlightFields = rb.getQparser().getDefaultHighlightFields();
      } else {
        defaultHighlightFields = params.getParams(CommonParams.DF);
      }

      Query highlightQuery = rb.getHighlightQuery();
      if (highlightQuery == null) {
        if (rb.getQparser() != null) {
          try {
            highlightQuery = rb.getQparser().getHighlightQuery();
            rb.setHighlightQuery(highlightQuery);
          } catch (Exception e) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
          }
        } else {
          highlightQuery = rb.getQuery();
          rb.setHighlightQuery(highlightQuery);
        }
      }

      if (highlightQuery != null) {
        boolean rewrite =
            !(Boolean.valueOf(req.getParams().get(HighlightParams.USE_PHRASE_HIGHLIGHTER, "true"))
                && Boolean.valueOf(
                    req.getParams().get(HighlightParams.HIGHLIGHT_MULTI_TERM, "true")));
        highlightQuery =
            rewrite ? highlightQuery.rewrite(req.getSearcher().getIndexReader()) : highlightQuery;
      }

      // No highlighting if there is no query -- consider q.alt="*:*
      if (highlightQuery != null) {
        NamedList sumData =
            highlighter.doHighlighting(
                rb.getResults().docList, highlightQuery, req, defaultHighlightFields);

        if (sumData != null) {
          // TODO ???? add this directly to the response?
          rb.rsp.add("highlighting", sumData);
        }
      }
    }
  }
コード例 #2
0
 public void inform(SolrCore core) {
   List<PluginInfo> children = info.getChildren("highlighting");
   if (children.isEmpty()) {
     PluginInfo pluginInfo =
         core.getSolrConfig()
             .getPluginInfo(
                 SolrHighlighter.class.getName()); // TODO deprecated configuration remove later
     if (pluginInfo != null) {
       highlighter =
           core.createInitInstance(
               pluginInfo, SolrHighlighter.class, null, DefaultSolrHighlighter.class.getName());
       highlighter.initalize(core.getSolrConfig());
     } else {
       DefaultSolrHighlighter defHighlighter = new DefaultSolrHighlighter(core);
       defHighlighter.init(PluginInfo.EMPTY_INFO);
       highlighter = defHighlighter;
     }
   } else {
     highlighter =
         core.createInitInstance(
             children.get(0), SolrHighlighter.class, null, DefaultSolrHighlighter.class.getName());
   }
 }
コード例 #3
0
 @Override
 public void prepare(ResponseBuilder rb) throws IOException {
   rb.doHighlights = highlighter.isHighlightingEnabled(rb.req.getParams());
 }