Repository navigation
SOLR-3479: New [hl] document transformer for inline highlighting - #5126
Conversation
Highlights one field per transformer instance using the Unified Highlighter, e.g. fl=id,body:[hl] or fl=id,body_hl:[hl f=body]. The field defaults to the transformer's name; when that name is the field and nothing matches, the original value passes through. - Local params are hl.* params without the prefix, overriding the request's - Query analysis and per-field setup happen once per request, then each doc is highlighted individually - SolrExtendedUnifiedHighlighter is now public and reusable - Documented on the document transformers and highlighting pages Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
One P2 finding: AI-generated, static review. Happy to open a ticket/PR to follow up on this, or provide you with a branch to include in this PR. |
I don't think that's the case. The 'q' should be parsed by the parseHighlightQuery here which calls getHighlightQuery on the qparser and thus wouldn't have bq clauses.
I'm not sure what "the body's RTG support claim" refers to. Body of the PR? I don't see an RTG reference there. |
|
🤖 AI text below 🤖 (reviewed by Nick Shanin) @dsmiley, I now have a small production fix and regression tests on top of your PR. On Linux, the new assertion fails on your current code because a boost-only term appears in the snippet, and passes with the fix. My earlier explanation was too compressed, and I missed an important qualification: this example requires You are right that Using your existing document 2, the title is "Fox cameo" and the body is "A story about cats. Cats sleep a lot.". The important request parameters are: The document matches fox through its title. The cats clause is a ranking boost. Before the fix, its inline The patch uses the search request's existing parser and its highlighting query for the implicit path. It preserves explicit At final commit By "body" I meant the PR description's Solution bullet saying it works "in real-time get". I was comparing that wording with your JIRA note that RTG is unsupported. That was a description clarification. The proposed code change is limited to query selection; RTG support and the alias issue in #5188 stay separate. Would this evidence and the two-file fix be sufficient to address the query-selection concern in this PR? |
|
Thanks Nick! I took your changes. |
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 separatehighlightingsection. One instance highlights one field, so several can be listed infl:fl=id,body_hl:[hl f=body]addsbody_hlwith snippets ofbody. The fullbodyisn't returned unlessflalso lists it.fl=id,body:[hl]: withoutf, the field is the transformer's name (its alias).body:[hl]means "body, highlighted where possible". Otherwise a miss gives an empty list, or no value at all.hl.*params without the prefix (e.g.snippets=3 tag.pre='<b>'), and they override the request'shl.*params, including per-field ones. The names are discovered fromHighlightParamsby reflection, so new params work automatically.A multi-field form that returns a map (like today's
highlightingsection) could be added later; see the JIRA discussion.Solution
FieldHighlighter) happen once per request insetContext, and each doc is then highlighted withFieldHighlighter.highlightFieldForDoc. Stored text and postings/term-vector offsets are used as usual.UnifiedSolrHighlighter.SolrExtendedUnifiedHighlighteris now public, with a constructor that doesn't need aSolrQueryRequest, so the transformer shares itshl.*handling. No behavior change for the highlight component./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.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 onefl, real-time get, and errors. The existing highlighter tests pass, as doesgradlew check -x test. There's no distributed test, since the embedded test rule can't run a sharded request.Checklist
🤖 Generated with Claude Code