[ 
https://issues.apache.org/jira/browse/SOLR-3479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18126650#comment-18126650
 ] 

David Smiley edited comment on SOLR-3479 at 10/13/26 9:05 AM:
--------------------------------------------------------------

Proposal for the first implementation of a highlighting doc transformer, 
{{{}[hl]{}}}.
h3. Syntax

One transformer instance highlights one field, and its snippets are output as a 
flat list under the transformer's name:
 * {{fl=id,body_hl:[hl f=body]}} adds {{body_hl}} with the snippets of 
{{{}body{}}}. The full {{body}} isn't fetched or returned unless {{fl}} also 
lists it.
 * {{{}fl=id,body:[hl]{}}}: if {{f}} isn't given, the field is the one named by 
the alias, so {{body}} holds its snippets.
 * {{{}fl=id,body:[hl],title:[hl snippets=3]{}}}: list several instances to 
highlight several fields, with separate settings.
 * {{[hl]}} with neither an alias nor {{field}} is an error.

{code:json}
{"id":"1", "body":["The quick brown <em>fox</em> jumps ..."], 
"title":["<em>Fox</em> stories"]}
{code}
h3. When nothing matches
 * If the output name is the field name (e.g. {{{}body:[hl]{}}}), the field's 
original stored value is returned as-is, like {{{}hl.alternateField{}}}. So 
{{body:[hl]}} means "body, highlighted where possible". The original is fetched 
only on a miss.
 * Otherwise (e.g. {{{}body_hl:[hl f=body]{}}}) the output is an empty list.
 * With {{{}defaultSummary=true{}}}, the leading passage(s) are returned 
instead.
 * On a miss the value has the field's normal shape (a string, or a list if 
multi-valued) rather than a list of snippets.

h3. Parameters

Short local params override, and the request's {{hl.{*}{*}}} \{*}params 
(including per-field {{f.body.hl.}}{*}) are the fallback: {{{}f{}}}, {{{}q{}}}, 
{{{}qparser{}}}, {{{}snippets{}}}, {{{}fragsize{}}}, {{{}pre{}}}, {{{}post{}}}, 
{{{}encoder{}}}, {{{}defaultSummary{}}}, {{{}requireFieldMatch{}}}, 
{{{}maxAnalyzedChars{}}}, {{{}offsetSource{}}}, {{{}bsType{}}}. The query 
defaults to the main query.
h3. Implementation notes
 * Built on the UnifiedHighlighter, sharing the existing {{hl.*}} handling by 
refactoring {{UnifiedSolrHighlighter.SolrExtendedUnifiedHighlighter}} for reuse 
(no behavior change for the highlight component).
 * Transformers see one doc at a time, so the per-request work (query term 
extraction, offset strategy) is done once in {{{}setContext{}}}. Each doc is 
then highlighted with {{{}FieldHighlighter.highlightFieldForDoc{}}}, using 
stored text and postings/term-vector offsets as usual.
 * Works in {{/select}} (single core and distributed: transformers run on the 
shards, like {{{}[explain]{}}}) and in real-time get (no-op without a query). 
{{/export}} needs its own change to support doc transformers.

h3. Later

A multi-field form returning a map, e.g. {{[hl fl=body,title]}} -> {{"[hl]":

{"body":[...],"title":[...]}

}}, mirroring today's {{highlighting}} section. It fits alongside this syntax 
and could be added if there's demand.

Feedback welcome, especially on the syntax and the no-match pass-through.

🤖 This comment was AI-generated.


was (Author: dsmiley):
Proposal for the first implementation of a highlighting doc transformer, 
{{[hl]}}.

h3. Syntax
One transformer instance highlights one field, and its snippets are output as a 
flat list under the transformer's name:
* {{fl=id,body_hl:[hl field=body]}} adds {{body_hl}} with the snippets of 
{{body}}. The full {{body}} isn't fetched or returned unless {{fl}} also lists 
it.
* {{fl=id,body:[hl]}}: if {{field}} isn't given, the field is the one named by 
the alias, so {{body}} holds its snippets.
* {{fl=id,body:[hl],title:[hl snippets=3]}}: list several instances to 
highlight several fields, with separate settings.
* {{[hl]}} with neither an alias nor {{field}} is an error.

{code:json}
{"id":"1", "body":["The quick brown <em>fox</em> jumps ..."], 
"title":["<em>Fox</em> stories"]}
{code}

h3. When nothing matches
* If the output name is the field name (e.g. {{body:[hl]}}), the field's 
original stored value is returned as-is, like {{hl.alternateField}}. So 
{{body:[hl]}} means "body, highlighted where possible". The original is fetched 
only on a miss.
* Otherwise (e.g. {{body_hl:[hl field=body]}}) the output is an empty list.
* With {{defaultSummary=true}}, the leading passage(s) are returned instead.
* On a miss the value has the field's normal shape (a string, or a list if 
multi-valued) rather than a list of snippets.

h3. Parameters
Short local params override, and the request's {{hl.*}} params (including 
per-field {{f.body.hl.*}}) are the fallback: {{field}}, {{q}}, {{qparser}}, 
{{snippets}}, {{fragsize}}, {{pre}}, {{post}}, {{encoder}}, {{defaultSummary}}, 
{{requireFieldMatch}}, {{maxAnalyzedChars}}, {{offsetSource}}, {{bsType}}. The 
query defaults to the main query.

h3. Implementation notes
* Built on the UnifiedHighlighter, sharing the existing {{hl.*}} handling by 
refactoring {{UnifiedSolrHighlighter.SolrExtendedUnifiedHighlighter}} for reuse 
(no behavior change for the highlight component).
* Transformers see one doc at a time, so the per-request work (query term 
extraction, offset strategy) is done once in {{setContext}}. Each doc is then 
highlighted with {{FieldHighlighter.highlightFieldForDoc}}, using stored text 
and postings/term-vector offsets as usual.
* Works in {{/select}} (single core and distributed: transformers run on the 
shards, like {{[explain]}}) and in real-time get (no-op without a query). 
{{/export}} needs its own change to support doc transformers.

h3. Later
A multi-field form returning a map, e.g. {{[hl fl=body,title]}} -> 
{{"[hl]":{"body":[...],"title":[...]}}}, mirroring today's {{highlighting}} 
section. It fits alongside this syntax and could be added if there's demand.

Feedback welcome, especially on the syntax and the no-match pass-through.

🤖 This comment was AI-generated.

> should provide highlighter support as a DocTransformer
> ------------------------------------------------------
>
>                 Key: SOLR-3479
>                 URL: https://issues.apache.org/jira/browse/SOLR-3479
>             Project: Solr
>          Issue Type: New Feature
>            Reporter: Chris M. Hostetter
>            Assignee: David Smiley
>            Priority: Major
>
> following in the footsteps of SOLR-2444, we should add a "HighlightAugmenter" 
> that can be used as a DocTransformer similar to how the ExplainAugmenter 
> works to inlining highligher output directly in the documents (instead of in 
> a parallel list in the response)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to