Class AlfrescoSolrHighlighter

java.lang.Object
org.apache.solr.highlight.SolrHighlighter
org.apache.solr.highlight.DefaultSolrHighlighter
org.apache.solr.handler.component.AlfrescoSolrHighlighter
All Implemented Interfaces:
org.apache.solr.util.plugin.PluginInfoInitialized

public class AlfrescoSolrHighlighter extends org.apache.solr.highlight.DefaultSolrHighlighter implements org.apache.solr.util.plugin.PluginInfoInitialized
The Alfresco customisation of the original (or somewhere called default) Solr highlighter. In this latest revision, the core Highlighting logic has been delegated to the Solr highlighter. The main difference introduced in this customisation is related with the fields mappings (i.e. mappings between the Alfresco and Solr fields names). The purpose of the delegation to the built-in Solr logic is to allow (later) an easier refactoring/removal. Specifically, when the mapping logic will be extracted in an external (calling) layer this component will be removed in favour of the built-in Solr (Default) Highlighter. The doHighlighting(DocList, Query, SolrQueryRequest, String[]) core method, which has been overriden, provides the required mapping between the requested highlighting fields in the hl.fl parameters (which follow the Alfresco semantic) and the Solr fields we have in the schema. At the end of the highlighting process the same mappings are used for doing the reverse process (replace the Solr fields with the original requested fields). Additionally, since the Solr ID has no meaning outside Solr, the Highlighter adds the DBID to each highlighting snippets:
  <lst name="_DEFAULT_!8000016f66a1a298!8000016f66a1a29e">
      <str name="DBID">1577974866590</str>
      <arr name="name">
          <str>some very <em>long</em> name</str>
      </arr>
      <arr name="title">
          <str>This the <em>long</em> french version of of the</str>
          <str>This the <em>long</em> english version of the</str>
      </arr>
  </lst>
 
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.solr.highlight.DefaultSolrHighlighter

    org.apache.solr.highlight.DefaultSolrHighlighter.FvhContainer
  • Field Summary

    Fields inherited from class org.apache.solr.highlight.DefaultSolrHighlighter

    boundaryScanners, encoders, formatters, fragListBuilders, fragmenters, fragmentsBuilders, solrCore

    Fields inherited from class org.apache.solr.highlight.SolrHighlighter

    DEFAULT_MAX_CHARS, DEFAULT_PHRASE_LIMIT
  • Constructor Summary

    Constructors
    Constructor
    Description
    AlfrescoSolrHighlighter(org.apache.solr.core.SolrCore core)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.solr.common.util.NamedList<Object>
    doHighlighting(org.apache.solr.search.DocList docs, org.apache.lucene.search.Query query, org.apache.solr.request.SolrQueryRequest request, String[] defaultFields)
     
    protected org.apache.lucene.search.highlight.Highlighter
    getHighlighter(org.apache.lucene.search.Query query, String requestFieldname, org.apache.solr.request.SolrQueryRequest request)
     
    protected org.apache.lucene.search.highlight.QueryScorer
    getSpanQueryScorer(org.apache.lucene.search.Query query, String requestFieldname, org.apache.lucene.analysis.TokenStream tokenStream, org.apache.solr.request.SolrQueryRequest request)
    We need to override this method because here Solr manages the HighlightParams.FIELD_MATCH parameter.

    Methods inherited from class org.apache.solr.highlight.DefaultSolrHighlighter

    alternateField, createAnalyzerTStream, doHighlightingByFastVectorHighlighter, doHighlightingByHighlighter, doHighlightingOfField, getBoundaryScanner, getDocPrefetchFieldNames, getEncoder, getFieldValues, getFormatter, getFragListBuilder, getFragmenter, getFragmentsBuilder, getMaxSnippets, getPhraseHighlighter, getQueryScorer, getResponseForFragments, getSolrFragmentsBuilder, init, isMergeContiguousFragments, useFastVectorHighlighter

    Methods inherited from class org.apache.solr.highlight.SolrHighlighter

    emptyArray, getHighlightFields, isHighlightingEnabled

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.solr.util.plugin.PluginInfoInitialized

    init
  • Constructor Details

    • AlfrescoSolrHighlighter

      public AlfrescoSolrHighlighter(org.apache.solr.core.SolrCore core)
  • Method Details

    • getHighlighter

      protected org.apache.lucene.search.highlight.Highlighter getHighlighter(org.apache.lucene.search.Query query, String requestFieldname, org.apache.solr.request.SolrQueryRequest request)
      Overrides:
      getHighlighter in class org.apache.solr.highlight.DefaultSolrHighlighter
    • getSpanQueryScorer

      protected org.apache.lucene.search.highlight.QueryScorer getSpanQueryScorer(org.apache.lucene.search.Query query, String requestFieldname, org.apache.lucene.analysis.TokenStream tokenStream, org.apache.solr.request.SolrQueryRequest request)
      We need to override this method because here Solr manages the HighlightParams.FIELD_MATCH parameter. In the last iteration, we improved the Solr schema by using one single stored field (used in this context for the highlighting) which is copied across multiple search fields (e.g. text@s__t,text@s_lt,mltext@m__lt). The input requestFieldName parameter is the stored field mentioned above; in case HighlightParams.FIELD_MATCH is set to true only query terms aligning with the field being highlighted will in turn be highlighted. The reverse field mapping you'll find in this method is because the stored field is not indexed, and therefore there won't be any "alignment" as described above, never. So starting from the stored field we need to query AlfrescoSolrDataModel for retrieving the corresponding cross-locale field (text|mltext@m|s__t@) and inject it into the QueryScorer that is in charge to score only those terms that contributed in generating the 'hit' on the document. TODO: this is one thing that can be improved together with the multilanguage improvement/implementation tasks
      Overrides:
      getSpanQueryScorer in class org.apache.solr.highlight.DefaultSolrHighlighter
      See Also:
    • doHighlighting

      public org.apache.solr.common.util.NamedList<Object> doHighlighting(org.apache.solr.search.DocList docs, org.apache.lucene.search.Query query, org.apache.solr.request.SolrQueryRequest request, String[] defaultFields) throws IOException
      Overrides:
      doHighlighting in class org.apache.solr.highlight.DefaultSolrHighlighter
      Throws:
      IOException