Skip to content

Commit a5fa85e

Browse files
committed
fix: omit irrelevant search-result evidence/highlights
1 parent c09e4f4 commit a5fa85e

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

share/search/index_strategy/trovesearch_denorm.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _cardsearch_handle(
564564
_results.append(CardsearchResult(
565565
card_iri=_card_iri,
566566
card_pk=_es8_hit['_id'],
567-
text_match_evidence=list(self._gather_textmatch_evidence(_card_iri, _es8_hit)),
567+
text_match_evidence=list(self._gather_textmatch_evidence(_card_iri, _es8_hit, cardsearch_params)),
568568
))
569569
_relatedproperty_list: list[PropertypathUsage] = []
570570
if cardsearch_params.related_property_paths:
@@ -585,16 +585,20 @@ def _cardsearch_handle(
585585
search_params=cardsearch_params,
586586
)
587587

588-
def _gather_textmatch_evidence(self, card_iri, es8_hit) -> Iterator[TextMatchEvidence]:
588+
def _gather_textmatch_evidence(self, card_iri, es8_hit, cardsearch_params) -> Iterator[TextMatchEvidence]:
589589
for _field, _snippets in es8_hit.get('highlight', {}).items():
590590
(_, _, _encoded_path) = _field.rpartition('.')
591591
_property_path = _parse_path_field_name(_encoded_path)
592-
for _snippet in _snippets:
593-
yield TextMatchEvidence(
594-
property_path=_property_path,
595-
matching_highlight=rdf.literal(_snippet),
596-
card_iri=card_iri,
597-
)
592+
if ( # skip highlights on non-requested text fields
593+
_property_path in cardsearch_params.cardsearch_text_paths
594+
or len(_property_path) in cardsearch_params.cardsearch_text_glob_depths
595+
):
596+
for _snippet in _snippets:
597+
yield TextMatchEvidence(
598+
property_path=_property_path,
599+
matching_highlight=rdf.literal(_snippet),
600+
card_iri=card_iri,
601+
)
598602

599603

600604
###

trove/trovesearch/search_params.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,21 @@ def cardsearch_type_iris(self):
584584
if _filter.is_type_filter():
585585
yield from _filter.value_set
586586

587+
@functools.cached_property
588+
def cardsearch_text_paths(self) -> PropertypathSet:
589+
return frozenset().union(*(
590+
_textsegment.propertypath_set
591+
for _textsegment in self.cardsearch_textsegment_set
592+
))
593+
594+
@functools.cached_property
595+
def cardsearch_text_glob_depths(self) -> frozenset[int]:
596+
return frozenset(
597+
len(_path)
598+
for _path in self.cardsearch_text_paths
599+
if is_globpath(_path)
600+
)
601+
587602
def to_querydict(self) -> QueryDict:
588603
_querydict = super().to_querydict()
589604
for _qp_name, _qp_value in Textsegment.queryparams_from_textsegments('cardSearchText', self.cardsearch_textsegment_set):

0 commit comments

Comments
 (0)