Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6708] fix: omit irrelevant search-result evidence/highlights #844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions share/search/index_strategy/trovesearch_denorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def _cardsearch_handle(
_results.append(CardsearchResult(
card_iri=_card_iri,
card_pk=_es8_hit['_id'],
text_match_evidence=list(self._gather_textmatch_evidence(_card_iri, _es8_hit)),
text_match_evidence=list(self._gather_textmatch_evidence(_card_iri, _es8_hit, cardsearch_params)),
))
_relatedproperty_list: list[PropertypathUsage] = []
if cardsearch_params.related_property_paths:
Expand All @@ -585,16 +585,20 @@ def _cardsearch_handle(
search_params=cardsearch_params,
)

def _gather_textmatch_evidence(self, card_iri, es8_hit) -> Iterator[TextMatchEvidence]:
def _gather_textmatch_evidence(self, card_iri, es8_hit, cardsearch_params) -> Iterator[TextMatchEvidence]:
for _field, _snippets in es8_hit.get('highlight', {}).items():
(_, _, _encoded_path) = _field.rpartition('.')
_property_path = _parse_path_field_name(_encoded_path)
for _snippet in _snippets:
yield TextMatchEvidence(
property_path=_property_path,
matching_highlight=rdf.literal(_snippet),
card_iri=card_iri,
)
if ( # skip highlights on non-requested text fields
_property_path in cardsearch_params.cardsearch_text_paths
or len(_property_path) in cardsearch_params.cardsearch_text_glob_depths
):
for _snippet in _snippets:
yield TextMatchEvidence(
property_path=_property_path,
matching_highlight=rdf.literal(_snippet),
card_iri=card_iri,
)


###
Expand Down
15 changes: 15 additions & 0 deletions trove/trovesearch/search_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,21 @@ def cardsearch_type_iris(self):
if _filter.is_type_filter():
yield from _filter.value_set

@functools.cached_property
def cardsearch_text_paths(self) -> PropertypathSet:
return frozenset().union(*(
_textsegment.propertypath_set
for _textsegment in self.cardsearch_textsegment_set
))

@functools.cached_property
def cardsearch_text_glob_depths(self) -> frozenset[int]:
return frozenset(
len(_path)
for _path in self.cardsearch_text_paths
if is_globpath(_path)
)

def to_querydict(self) -> QueryDict:
_querydict = super().to_querydict()
for _qp_name, _qp_value in Textsegment.queryparams_from_textsegments('cardSearchText', self.cardsearch_textsegment_set):
Expand Down