Skip to content

Commit

Permalink
also index num and type of provision
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Apr 24, 2024
1 parent ec7c7bd commit 8fa876d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions peachjam_search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class SearchableDocument(Document):
properties={
"title": fields.TextField(),
"id": fields.KeywordField(),
"num": fields.KeywordField(),
"type": fields.KeywordField(),
"parent_titles": fields.TextField(),
"parent_ids": fields.KeywordField(),
"body": fields.TextField(fields={"exact": Text()}),
Expand Down Expand Up @@ -301,6 +303,8 @@ def prepare_provision(item, parents):
provision = {
"title": item["title"],
"id": provision_id,
"num": (item["num"] or "").rstrip("."),
"type": item["type"],
"parent_titles": [
p["title"] for p in parents if p["title"] and p["id"]
],
Expand Down
4 changes: 3 additions & 1 deletion peachjam_search/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def get_pages(self, obj):
def get_provisions(self, obj):
"""Serialize nested provision hits and highlights."""
provisions = []
if hasattr(obj.meta, "inner_hits"):
if hasattr(obj.meta, "inner_hits") and hasattr(
obj.meta.inner_hits, "provisions"
):
for provision in obj.meta.inner_hits.provisions.hits.hits:
info = provision._source.to_dict()
info["highlight"] = (
Expand Down

0 comments on commit 8fa876d

Please sign in to comment.