Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Dedup fields into generalized search field. #2033

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions capstone/capapi/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class CaseDocument(Document):

restricted = fields.BooleanField()

search = FTSField()

def prepare_provenance(self, instance):
return {
"date_added": instance.date_added.strftime('%Y-%m-%d'),
Expand Down Expand Up @@ -224,6 +226,27 @@ def prepare_name(self, instance):
def prepare_name_abbreviation(self, instance):
return instance.redact_obj(instance.name_abbreviation)

def prepare_search(self, instance):
# It seems more efficient to pull the search fields manually,
# as casebody and jurisdiction data is extracted differently
# from the other fields.
text_body = self.prepare_casebody_data(instance)['text']

text_set = ' '.join(["{} {}".format(blob['author'],blob['text'])
for blob in text_body['opinions']])

filter_set = [
self.prepare_name(instance),
self.prepare_name_abbreviation(instance),
instance.docket_number,
instance.jurisdiction.name_long,
instance.court.name,
text_set,
text_body['corrections'],
]

return ' '.join(filter_set)

class Django:
model = CaseMetadata
fields = [
Expand Down
17 changes: 2 additions & 15 deletions capstone/capapi/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,24 +490,11 @@ def get_search_query_params(self, request, view=None):


class MultiFieldFTSFilter(BaseSearchFilterBackend):
# Query fields are prepared in CaseDocument.prepare_search()
search_param = 'search'
fields = (
'name',
'name_abbreviation',
'jurisdiction.name_long',
'court.name',
'casebody_data.text.head_matter',
'casebody_data.text.corrections',
'docket_number',
)

nested_query_fields = (
'casebody_data.text.opinions.author',
'casebody_data.text.opinions.text',
)
fields = ('search',)

query_backends = [
NestedSimpleStringQueryBackend,
SimpleQueryStringQueryBackend,
]

Expand Down