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)