Skip to content

Commit 1424a2a

Browse files
committed
fix: sanitize hit level
1 parent 76ab577 commit 1424a2a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

algoliasearch_django/models.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ def get_model_attr(name):
3636
return partial(_getattr, name=name)
3737

3838

39-
def aggregator(aggregated, resp):
40-
for hit in resp.hits:
41-
if "_highlightResult" in hit:
42-
hit.pop("_highlightResult")
43-
aggregated.append(hit)
39+
def sanitize(hit):
40+
if "_highlightResult" in hit:
41+
hit.pop("_highlightResult")
42+
return hit
4443

4544

4645
class AlgoliaIndexError(Exception):
@@ -499,13 +498,19 @@ def reindex_all(self, batch_size=1000):
499498
logger.debug("APPLY SETTINGS ON %s_tmp", self.index_name)
500499

501500
rules = []
502-
self.__client.browse_rules(self.index_name, lambda _resp: aggregator(rules, _resp))
501+
self.__client.browse_rules(
502+
self.index_name,
503+
lambda _resp: rules.extend([sanitize(_hit.to_dict()) for _hit in _resp.hits]),
504+
)
503505
if len(rules):
504506
logger.debug("Got rules for index %s: %s", self.index_name, rules)
505507
should_keep_rules = True
506508

507509
synonyms = []
508-
self.__client.browse_synonyms(self.index_name, lambda _resp: aggregator(synonyms, _resp))
510+
self.__client.browse_synonyms(
511+
self.index_name,
512+
lambda _resp: synonyms.extend([sanitize(_hit.to_dict()) for _hit in _resp.hits]),
513+
)
509514
if len(synonyms):
510515
logger.debug("Got synonyms for index %s: %s", self.index_name, rules)
511516
should_keep_synonyms = True

0 commit comments

Comments
 (0)