Skip to content

Commit

Permalink
index judge names as text for use with advanced search
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Aug 6, 2024
1 parent 84f40c9 commit 60ad48c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion peachjam_search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class SearchableDocument(Document):
case_summary = fields.TextField()
flynote = fields.TextField()
order = fields.TextField()
judges = fields.KeywordField(attr="judge.name")
judges = fields.KeywordField()
judges_text = fields.TextField()
attorneys = fields.KeywordField(attr="attorney.name")

registry = fields.KeywordField(attr="registry.name")
Expand Down Expand Up @@ -224,6 +225,9 @@ def prepare_judges(self, instance):
if instance.doc_type == "judgment":
return [j.name for j in instance.judges.all()]

def prepare_judges_text(self, instance):
return self.prepare_judges(instance)

def prepare_attorneys(self, instance):
if instance.doc_type == "judgment":
return [a.name for a in instance.attorneys.all()]
Expand Down
29 changes: 29 additions & 0 deletions peachjam_search/migrations/0005_es_mapping_add_judges_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

from django.db import migrations


def forwards(apps, schema_editor):
from django.conf import settings
from django_elasticsearch_dsl.registries import registry

if not settings.DEBUG and os.environ.get("ELASTICSEARCH_HOST"):
for ix in registry.get_indices():
if not ix._mapping:
continue
print(f"Adding judges_text mapping for {ix._name}")
ix.connection.indices.put_mapping(
index=ix._name,
body={
"properties": {"judges_text": ix._mapping["judges_text"].to_dict()}
},
)


class Migration(migrations.Migration):

dependencies = [
("peachjam_search", "0004_auto_20240719_1050"),
]

operations = [migrations.RunPython(forwards, migrations.RunPython.noop)]

0 comments on commit 60ad48c

Please sign in to comment.