Skip to content

Commit

Permalink
fix bill_text template.
Browse files Browse the repository at this point in the history
This had some out of date references which was causing the full text search
to miss bills like in #388.

closes #388
  • Loading branch information
fgregg committed Jan 13, 2024
1 parent a61accd commit 80f1db8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
30 changes: 30 additions & 0 deletions chicago/management/commands/preview_search_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.core.management.base import BaseCommand
from chicago.models import ChicagoBill
from chicago.search_indexes import BillIndex
import pprint


class Command(BaseCommand):
"""A simple management command which clears the site-wide cache."""

help = "Preview the text template that will be used in the search."

def add_arguments(self, parser):
parser.add_argument(
"identifier",
help=(
"The identifier of the bill to preview"
),
)



def handle(self, *args, **kwargs):




b = ChicagoBill.objects.get(identifier=kwargs['identifier'])

self.stdout.write(pprint.pformat(BillIndex().prepare(b), indent=4))

12 changes: 3 additions & 9 deletions chicago/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ class BillIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(
document=True,
use_template=True,
template_name="search/indexes/councilmatic_core/bill_text.txt",
template_name="search/bill_text.txt",
)
slug = indexes.CharField(model_attr="slug", indexed=False)
id = indexes.CharField(model_attr="id", indexed=False)
bill_type = indexes.CharField(faceted=True)
identifier = indexes.CharField(model_attr="identifier")
description = indexes.CharField(model_attr="title", boost=1.25)
title = indexes.CharField(model_attr="title", boost=1.25)
source_url = indexes.CharField(model_attr="sources__url", indexed=False)
source_note = indexes.CharField(model_attr="sources__note")
abstract = indexes.CharField(
model_attr="abstracts__abstract", boost=1.25, default=""
)

friendly_name = indexes.CharField()
sort_name = indexes.CharField(faceted=True)
Expand All @@ -38,7 +35,7 @@ class BillIndex(indexes.SearchIndex, indexes.Indexable):
last_action_date = indexes.DateTimeField()
inferred_status = indexes.CharField(faceted=True)
legislative_session = indexes.CharField(faceted=True)
topics = indexes.MultiValueField(faceted=True)
topics = indexes.MultiValueField(model_attr="topics", faceted=True)

def get_model(self):
return ChicagoBill
Expand All @@ -60,9 +57,6 @@ def prepare(self, obj):

return data

def prepare_topics(self, obj):
return obj.topics

def prepare_last_action_date(self, obj):
if not obj.last_action_date:
action_dates = [a.date for a in obj.actions.all()]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{% load extras %}
{{ object.identifier | alternative_identifiers }}
{{ object.friendly_name }}
{{ object.classification }}
{{ object.description }}
{{ object.abstract }}
{% for identifier in object.other_identifiers.all %}
{{ identifier.identifier }}
{% endfor %}
{% for classification in object.classification %}
{{ classification }}
{% endfor %}
{{ object.title }}
{% for s in object.sponsorships.all %}
{% if s.primary %}
{{ s.person.name }}
Expand All @@ -16,4 +19,4 @@
{% for t in object.topics %}
{{t}}
{% endfor %}
{{ object.ocr_full_text|clean_html }}
{{ object.ocr_full_text }}
9 changes: 0 additions & 9 deletions chicago/templatetags/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ def clean_html(text):
return re.sub(r"&(?:\w+|#\d+);", "", value)


@register.filter
@stringfilter
def alternative_identifiers(id_original):
id_1 = re.sub(" ", " 0", id_original)
id_2 = re.sub(" ", "", id_original)
id_3 = re.sub(" ", "", id_1)
return " ".join(i for i in set([id_original, id_1, id_2, id_3]))


@register.filter
def get_item(dictionary, key):
return dictionary.get(key)
Expand Down

0 comments on commit 80f1db8

Please sign in to comment.