dsmiley opened a new pull request, #5126:
URL: https://github.com/apache/solr/pull/5126

   https://issues.apache.org/jira/browse/SOLR-3479
   
   # Description
   
   Adds a `[hl]` document transformer that puts highlighted snippets inside 
each document, as an alternative to the highlight component's separate 
`highlighting` section. One instance highlights one field, so several can be 
listed in `fl`:
   
   * `fl=id,body_hl:[hl f=body]` adds `body_hl` with snippets of `body`. The 
full `body` isn't returned unless `fl` also lists it.
   * `fl=id,body:[hl]`: without `f`, the field is the transformer's name (its 
alias).
   * If the name is the field and nothing matches, the field's original value 
is returned, so `body:[hl]` means "body, highlighted where possible". Otherwise 
a miss gives an empty list, or no value at all.
   * A single-valued field with one snippet (the default) gets a plain value; 
otherwise a list.
   * Local params are `hl.*` params without the prefix (e.g. `snippets=3 
tag.pre='<b>'`), and they override the request's `hl.*` params, including 
per-field ones. The names are discovered from `HighlightParams` by reflection, 
so new params work automatically.
   
   A multi-field form that returns a map (like today's `highlighting` section) 
could be added later; see the JIRA discussion.
   
   # Solution
   
   * Built on the Unified Highlighter. A transformer sees one doc at a time, so 
query term extraction and per-field setup (`FieldHighlighter`) happen once per 
request in `setContext`, and each doc is then highlighted with 
`FieldHighlighter.highlightFieldForDoc`. Stored text and postings/term-vector 
offsets are used as usual.
   * `UnifiedSolrHighlighter.SolrExtendedUnifiedHighlighter` is now public, 
with a constructor that doesn't need a `SolrQueryRequest`, so the transformer 
shares its `hl.*` handling. No behavior change for the highlight component.
   * Works in `/select` (single-core and distributed, since transformers run on 
the shards) and in real-time get, where there's no query, so the original value 
passes through.
   * Ref guide: a new section on the document transformers page, and an intro 
on the highlighting page describing both approaches and when to prefer each.
   
   Found along the way, not fixed here: with `hl.method=unified`, multi-valued 
fields can return a leading empty snippet (e.g. `[, forest <em>fox</em>]`), 
because Lucene's value separator and Solr's snippet separator are both 
`\u0000`. The transformer filters empty snippets; the component deserves its 
own issue.
   
   Developed with Claude Code (AI coding assistant), reviewed and directed by 
me.
   
   # Tests
   
   New `TestHighlightAugmenterFactory` (`SolrTestCase` + 
`EmbeddedSolrServerTestRule`) covers an explicit field, the field taken from 
the alias, pass-through (single- and multi-valued), single value vs list, local 
params and request fallback/override, several instances in one `fl`, real-time 
get, and errors. The existing highlighter tests pass, as does `gradlew check -x 
test`. There's no distributed test, since the embedded test rule can't run a 
sharded request.
   
   # Checklist
   
   - [x] I have reviewed the guidelines for [How to 
Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my 
code conforms to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request 
title.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to