From e74d16286f4fc3bc34139cbf1e3a39301cf13d6b Mon Sep 17 00:00:00 2001 From: Kevin Schaper Date: Fri, 10 Jul 2026 22:02:46 -0700 Subject: [PATCH] Use the Unified highlighter for association search (hl.method=unified) Set hl.method=unified on the association free-text search so highlighting reads offsets from the postings (storeOffsetsWithPositions) instead of term vectors. Pairs with monarch-initiative/monarch-ingest#708, which drops term vectors from the `text` field type to shrink the index and speed indexing. Solr 8 defaults to the `original` highlighter, which uses term vectors and does NOT read postings offsets, so without this change highlighting would fall back to slow per-result re-analysis once term vectors are gone. Adds an optional hl_method field to SolrQuery (serialized to hl.method); None by default, so all other queries are unchanged. Companion still needed: frontend should stop wrapping q in wildcards and rely on the analyzed _t fields already in the qf. Claude-Session: https://claude.ai/code/session_012eRPzupZErBJN7495bWEVD --- backend/src/monarch_py/datamodels/solr.py | 3 +++ .../src/monarch_py/implementations/solr/solr_query_utils.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/backend/src/monarch_py/datamodels/solr.py b/backend/src/monarch_py/datamodels/solr.py index 8433bb326..0bd42287c 100644 --- a/backend/src/monarch_py/datamodels/solr.py +++ b/backend/src/monarch_py/datamodels/solr.py @@ -98,6 +98,7 @@ class SolrQuery(BaseModel): boost: Optional[str] = None sort: Optional[str] = None hl: bool = False + hl_method: Optional[str] = None # e.g. "unified" — reads offsets from postings (storeOffsetsWithPositions) def add_field_filter_query(self, field: str, value: Union[list, str, None]): if not value or len(value) == 0: @@ -141,6 +142,8 @@ def _solrize(self, value): return "defType" elif value == "q_op": return "q.op" + elif value == "hl_method": + return "hl.method" elif value is True: return "true" elif value is False: diff --git a/backend/src/monarch_py/implementations/solr/solr_query_utils.py b/backend/src/monarch_py/implementations/solr/solr_query_utils.py index 99811f6cc..7be324eb8 100644 --- a/backend/src/monarch_py/implementations/solr/solr_query_utils.py +++ b/backend/src/monarch_py/implementations/solr/solr_query_utils.py @@ -132,6 +132,9 @@ def build_association_query( query.q = q query.def_type = "edismax" query.hl = True + # Unified highlighter reads offsets from the postings (storeOffsetsWithPositions), + # so highlighting no longer needs term vectors on the _t fields. + query.hl_method = "unified" query.query_fields = association_search_query_fields() if sort: query.sort = ", ".join(sort)