Skip to content

Commit

Permalink
Add labels to search view
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmwangemi committed Jul 28, 2023
1 parent b54481d commit 55d5b36
Show file tree
Hide file tree
Showing 6 changed files with 3,792 additions and 19 deletions.
21 changes: 21 additions & 0 deletions peachjam/js/components/FindDocuments/SearchResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@
v-html="highlights(item)"
/>
</div>
<span v-if="item.labels.length">
<span v-if="documentLabels.length">
<span v-for="(l, idx) in item.labels" :key="idx">
<span v-for="(label, index) in documentLabels" :key="index">
<span v-if="l == 'repealed' && l == label.code " class="badge rounded-pill bg-danger">
{{ label.name }}
</span>
<span v-if="l == 'reported' && l == label.code " class="badge rounded-pill bg-success">
{{ label.name }}
</span>
</span>
</span>
</span>
</span>
</li>
</template>

Expand All @@ -74,6 +88,13 @@ export default {
default: false,
}
},
data (){
const documentLabels = JSON.parse(document.querySelector('#data-labels').textContent).documentLabels;
console.log(documentLabels);
return {
documentLabels
}
},
methods: {
highlights (item) {
if (item.highlight.content) {
Expand Down
3,758 changes: 3,756 additions & 2 deletions peachjam/static/js/app-prod.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions peachjam_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from peachjam.models import (
CitationLink,
CoreDocument,
Label,
Legislation,
Predicate,
Relationship,
Expand Down Expand Up @@ -130,3 +131,9 @@ class Meta:
"action",
"data",
)


class LabelSerializer(serializers.ModelSerializer):
class Meta:
model = Label
exclude = []
20 changes: 4 additions & 16 deletions peachjam_search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ class SearchableDocument(Document):
created_at = fields.DateField()
updated_at = fields.DateField()
taxonomies = fields.KeywordField()
labels = fields.KeywordField(attr="label.name")
labels_en = fields.KeywordField()
labels_sw = fields.KeywordField()
labels_fr = fields.KeywordField()
labels_pt = fields.KeywordField()
labels = fields.KeywordField()

# Judgment
court = fields.KeywordField(attr="court.name")
Expand Down Expand Up @@ -110,7 +106,6 @@ class SearchableDocument(Document):
("registry", "name"),
("order_outcome", "name"),
("nature", "name"),
("labels", "name"),
]

def should_index_object(self, obj):
Expand Down Expand Up @@ -218,16 +213,6 @@ def prepare_authors(self, instance):
if hasattr(instance, "authors"):
return [a.name for a in instance.authors.all()]

def prepare_labels(self, instance):
if instance.labels.exists():
return [
{
"name": label.name,
"code": label.code,
}
for label in instance.labels.all()
]

def prepare_content(self, instance):
"""Text content of document body for non-PDFs."""
if instance.content_html:
Expand Down Expand Up @@ -280,6 +265,9 @@ def prepare_taxonomies(self, instance):
]
return list({t.slug for t in topics})

def prepare_labels(self, instance):
return [label.code for label in instance.labels.all()]

def prepare_title_expanded(self, instance):
# combination of the title, citation and alternative names
parts = [instance.title]
Expand Down
1 change: 1 addition & 0 deletions peachjam_search/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Meta:
"highlight",
"is_most_recent",
"alternative_names",
"labels",
]

def get_highlight(self, obj):
Expand Down
4 changes: 3 additions & 1 deletion peachjam_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from elasticsearch_dsl.query import MatchPhrase, Q, SimpleQueryString
from rest_framework.permissions import AllowAny

from peachjam.models import Author, pj_settings
from peachjam.models import Author, Label, pj_settings
from peachjam_api.serializers import LabelSerializer
from peachjam_search.documents import SearchableDocument, get_search_indexes
from peachjam_search.serializers import SearchableDocumentSerializer

Expand Down Expand Up @@ -199,6 +200,7 @@ def get_context_data(self, **kwargs):
context["labels"] = {
"author": Author.model_label,
"searchPlaceholder": search_placeholder_text,
"documentLabels": LabelSerializer(Label.objects.all(), many=True).data,
}
context["show_jurisdiction"] = settings.PEACHJAM["SEARCH_JURISDICTION_FILTER"]
return context
Expand Down

0 comments on commit 55d5b36

Please sign in to comment.