Package org.apache.solr.highlight

Examples of org.apache.solr.highlight.SolrHighlighter


  /**
   * Prepares Carrot2 documents for clustering.
   */
  private List<Document> getDocuments(DocList docList,
                                      Query query, final SolrQueryRequest sreq) throws IOException {
    SolrHighlighter highligher = null;
    SolrParams solrParams = sreq.getParams();
    SolrCore core = sreq.getCore();

    // Names of fields to deliver content for clustering
    String urlField = solrParams.get(CarrotParams.URL_FIELD_NAME, "url");
    String titleField = solrParams.get(CarrotParams.TITLE_FIELD_NAME, "title");
    String snippetField = solrParams.get(CarrotParams.SNIPPET_FIELD_NAME,
            titleField);
    if (StringUtils.isBlank(snippetField)) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, CarrotParams.SNIPPET_FIELD_NAME
              + " must not be blank.");
    }
    Set<String> fieldsToLoad = Sets.newHashSet(urlField, titleField,
            snippetField, idFieldName);

    // Get the documents
    DocIterator docsIter = docList.iterator();
    boolean produceSummary = solrParams.getBool(CarrotParams.PRODUCE_SUMMARY,
            false);

    SolrQueryRequest req = null;
    String[] snippetFieldAry = null;
    if (produceSummary == true) {
      highligher = core.getHighlighter();
      Map args = new HashMap();
      snippetFieldAry = new String[]{snippetField};
      args.put(HighlightParams.FIELDS, snippetFieldAry);
      args.put(HighlightParams.HIGHLIGHT, "true");
      req = new LocalSolrQueryRequest(core, query.toString(), "", 0, 1, args) {
        @Override
        public SolrIndexSearcher getSearcher() {
          return sreq.getSearcher();
        }
      };
    }

    SolrIndexSearcher searcher = sreq.getSearcher();
    List<Document> result = new ArrayList<Document>(docList.size());
    FieldSelector fieldSelector = new SetBasedFieldSelector(fieldsToLoad,
            Collections.emptySet());
    float[] scores = {1.0f};
    int[] docsHolder = new int[1];
    Query theQuery = query;

    while (docsIter.hasNext()) {
      Integer id = docsIter.next();
      org.apache.lucene.document.Document doc = searcher.doc(id,
              fieldSelector);
      String snippet = getValue(doc, snippetField);
      if (produceSummary == true) {
        docsHolder[0] = id.intValue();
        DocList docAsList = new DocSlice(0, 1, docsHolder, scores, 1, 1.0f);
        highligher.doHighlighting(docAsList, theQuery, req, snippetFieldAry);
      }
      Document carrotDocument = new Document(getValue(doc, titleField),
              snippet, doc.get(urlField));
      carrotDocument.addField("solrId", doc.get(idFieldName));
      result.add(carrotDocument);
View Full Code Here


    // from the core.
    resourceLoader.inform(infoRegistry);
  }

  private SolrHighlighter initHighLighter() {
    SolrHighlighter highlighter = null;
    PluginInfo pluginInfo = solrConfig.getPluginInfo(SolrHighlighter.class.getName());
    if(pluginInfo != null){
      highlighter = createInitInstance(pluginInfo,SolrHighlighter.class,null, DefaultSolrHighlighter.class.getName());
      highlighter.initalize(solrConfig);
    } else{
      highlighter = new DefaultSolrHighlighter();
      highlighter.initalize(solrConfig);
    }
    return highlighter;
  }
View Full Code Here

        for (String field : returnFields) {
          fieldFilter.add(Bytes.toBytes(field));
        }

        // add highlight fields
        SolrHighlighter highligher = rb.req.getCore().getHighlighter();
        if (highligher.isHighlightingEnabled(rb.req.getParams())) {
          for (String field : highligher.getHighlightFields(rb.getQuery(), rb.req, null))
            if (!returnFields.contains(field))
              fieldFilter.add(Bytes.toBytes(field));
        }
        // fetch unique key if one exists.
        SchemaField keyField = rb.req.getSearcher().getSchema().getUniqueKeyField();
View Full Code Here

                {
                    fieldFilter.add(ByteBufferUtil.bytes(field));
                }

                // add highlight fields
                SolrHighlighter highligher = rb.req.getCore().getHighlighter();
                if (highligher.isHighlightingEnabled(rb.req.getParams()))
                {
                    for (String field : highligher.getHighlightFields(rb.getQuery(), rb.req, null))
                        if (!returnFields.contains(field))
                            fieldFilter.add(ByteBufferUtil.bytes(field));
                }
                // fetch unique key if one exists.
                SchemaField keyField = rb.req.getSearcher().getSchema().getUniqueKeyField();
View Full Code Here

TOP

Related Classes of org.apache.solr.highlight.SolrHighlighter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.