Skip to content

Commit

Permalink
fix search index for array fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 23, 2024
1 parent 563fd4a commit 8161fcf
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 26 deletions.
3 changes: 2 additions & 1 deletion catalog/music/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ class Album(Item):
duration = jsondata.IntegerField(
_("length"), null=True, blank=True, help_text=_("milliseconds")
)
artist = jsondata.JSONField(
artist = jsondata.ArrayField(
verbose_name=_("artist"),
base_field=models.CharField(blank=True, default="", max_length=100),
null=False,
blank=False,
default=list,
Expand Down
4 changes: 2 additions & 2 deletions catalog/podcast/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from ninja import Field
from typing_extensions import deprecated

from catalog.common import (
BaseSchema,
Expand Down Expand Up @@ -52,8 +51,9 @@ class Podcast(Item):

language = LanguageListField()

host = jsondata.JSONField(
host = jsondata.ArrayField(
verbose_name=_("host"),
base_field=models.CharField(blank=True, default="", max_length=200),
null=False,
blank=False,
default=list,
Expand Down
2 changes: 2 additions & 0 deletions catalog/search/typesense.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def obj_to_dict(cls, obj):
for field in obj.__class__.indexable_fields_dict:
if field.startswith("localized_"):
item[field] = [t["text"] for t in getattr(obj, field, [])]
elif field in ["actor", "crew"]:
item[field] = [t["name"] for t in getattr(obj, field, [])]

item["id"] = obj.uuid
item["category"] = obj.category.value
Expand Down
4 changes: 0 additions & 4 deletions catalog/templates/_item_card_metadata_edition.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
{% endif %}
{% include '_people.html' with people=item.author role='author' max=2 %}
{% include '_people.html' with people=item.translator role='translator' max=2 %}
{% include '_people.html' with people=item.director role='director' max=2 %}
{% include '_people.html' with people=item.hosts role='' max=2 %}
{% include '_people.html' with people=item.artist role='' max=2 %}
{% include '_people.html' with people=item.developer role='' max=2 %}
{% if item.pub_house %}<span>{{ item.pub_house }}</span>{% endif %}
{% if item.pub_year %}
<span>
Expand Down
2 changes: 1 addition & 1 deletion catalog/templates/_item_card_metadata_podcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% if item.rating %}
<span class="solo-hidden">{{ item.rating | floatformat:1 }} <small>({{ item.rating_count }} {% trans "ratings" %})</small></span>
{% endif %}
{% include '_people.html' with people=item.hosts role='host' max=5 %}
{% include '_people.html' with people=item.host role='host' max=5 %}
</div>
{% endblock brief %}
{% block full %}
Expand Down
2 changes: 1 addition & 1 deletion catalog/templates/_item_comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
data-position="{{ comment.metadata.position|default:0 }}"
data-cover="{{ comment.item.cover_url|default:item.cover.url }}"
class="episode"
data-hosts="{{ item.hosts|join:' / ' }}"
data-hosts="{{ item.host|join:' / ' }}"
data-title="{{ comment.item.display_title }}"
data-album="{{ item.display_title }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' comment.item.uuid %}" {% endif %}
Expand Down
2 changes: 1 addition & 1 deletion catalog/templates/embed_podcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
cover: "{{ focus_item.cover_url | default:item.cover.url | escapejs }}",
src: "{{ focus_item.media_url | escapejs }}",
album: "{{ item.display_title|escapejs }}",
artist: "{{ item.hosts|join:' / '|escapejs }}"
artist: "{{ item.host|join:' / '|escapejs }}"
}
});
if (position) window.player._initSeek = position;
Expand Down
4 changes: 2 additions & 2 deletions catalog/templates/podcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% endblock %}
{% block details %}
<div>{% include '_people.html' with people=item.genre role='genre' max=5 %}</div>
<div>{% include '_people.html' with people=item.hosts role='podcast host' max=5 %}</div>
<div>{% include '_people.html' with people=item.host role='podcast host' max=5 %}</div>
<div>
{% if item.official_site %}
{% trans 'website' %}: {{ item.official_site|urlizetrunc:24 }}
Expand Down Expand Up @@ -51,7 +51,7 @@ <h5>{% trans 'recent episodes' %}</h5>
cover: "{{ focus_item.cover_url | default:item.cover.url | escapejs }}",
src: "{{ focus_item.media_url | escapejs }}",
album: "{{ item.display_title|escapejs }}",
artist: "{{ item.hosts|join:' / '|escapejs }}"
artist: "{{ item.host|join:' / '|escapejs }}"
})
if (position) window.player._initSeek = position;
{% if request.user.is_authenticated %}
Expand Down
2 changes: 1 addition & 1 deletion catalog/templates/podcast_episode_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h6>
data-uuid="{{ ep.uuid }}"
data-title="{{ ep.display_title }}"
data-album="{{ item.display_title }}"
data-hosts="{{ item.hosts|join:' / ' }}"
data-hosts="{{ item.host|join:' / ' }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' ep.uuid %}" {% endif %}
style="top:4px;
margin-right: 8px"></a>
Expand Down
4 changes: 2 additions & 2 deletions catalog/tv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ class TVSeason(Item):
blank=True,
default=list,
)
language = jsondata.JSONField(
language = jsondata.ArrayField(
verbose_name=_("language"),
# base_field=models.CharField(blank=True, default="", max_length=100, choices=LANGUAGE_CHOICES ),
base_field=models.CharField(blank=True, default="", max_length=100),
null=True,
blank=True,
default=list,
Expand Down
2 changes: 1 addition & 1 deletion common/templates/_sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h6 class="nickname">{{ identity.display_name }}</h6>
data-cover="{{ item.cover_url|default:item.program.cover.url }}"
data-title="{{ item.display_title }}"
data-album="{{ item.program.display_title }}"
data-hosts="{{ item.program.hosts|join:' / ' }}"
data-hosts="{{ item.program.host|join:' / ' }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' item.uuid %}" {% endif %}
data-position="0"
href="{{ item.url }}"
Expand Down
42 changes: 33 additions & 9 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ services:
- ${NEODB_DATA:-../data}/redis:/data

typesense:
image: typesense/typesense:0.25.2
image: typesense/typesense:${TYPESENSE_VERSION:-0.25.2}
restart: "on-failure"
# healthcheck:
# test: ['CMD', 'curl', '-vf', 'http://127.0.0.1:8108/health']
Expand All @@ -132,12 +132,12 @@ services:
GLOG_minloglevel: 2
volumes:
- ${NEODB_DATA:-../data}/typesense:/data
command: '--data-dir /data --api-key=eggplant'
command: "--data-dir /data --api-key=eggplant"

neodb-db:
image: postgres:14-alpine
image: postgres:${POSTGRES_VERSION:-14-alpine}
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'neodb']
test: ["CMD", "pg_isready", "-U", "neodb"]
volumes:
- ${NEODB_DATA:-../data}/neodb-db:/var/lib/postgresql/data
environment:
Expand All @@ -146,9 +146,9 @@ services:
- POSTGRES_PASSWORD=aubergine

takahe-db:
image: postgres:14-alpine
image: postgres:${POSTGRES_VERSION:-14-alpine}
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'takahe']
test: ["CMD", "pg_isready", "-U", "takahe"]
volumes:
- ${NEODB_DATA:-../data}/takahe-db:/var/lib/postgresql/data
environment:
Expand All @@ -174,7 +174,15 @@ services:
<<: *neodb-service
command: ${NEODB_VENV:-/neodb-venv}/bin/gunicorn boofilsic.wsgi -w ${NEODB_WEB_WORKER_NUM:-8} --preload --max-requests 2000 --timeout 60 -b 0.0.0.0:8000
healthcheck:
test: ['CMD', 'wget', '-qO/tmp/test', '--header', 'X-Forwarded-Proto: https', 'http://127.0.0.1:8000/nodeinfo/2.0/']
test:
[
"CMD",
"wget",
"-qO/tmp/test",
"--header",
"X-Forwarded-Proto: https",
"http://127.0.0.1:8000/nodeinfo/2.0/",
]
depends_on:
migration:
condition: service_completed_successfully
Expand All @@ -183,7 +191,15 @@ services:
<<: *neodb-service
command: ${NEODB_VENV:-/neodb-venv}/bin/gunicorn boofilsic.wsgi -w ${NEODB_API_WORKER_NUM:-4} --preload --max-requests 2000 --timeout 30 -b 0.0.0.0:8000
healthcheck:
test: ['CMD', 'wget', '-qO/tmp/test', '--header', 'X-Forwarded-Proto: https', 'http://127.0.0.1:8000/nodeinfo/2.0/']
test:
[
"CMD",
"wget",
"-qO/tmp/test",
"--header",
"X-Forwarded-Proto: https",
"http://127.0.0.1:8000/nodeinfo/2.0/",
]
depends_on:
migration:
condition: service_completed_successfully
Expand All @@ -206,7 +222,15 @@ services:
<<: *neodb-service
command: ${TAKAHE_VENV:-/takahe-venv}/bin/gunicorn --chdir /takahe takahe.wsgi -w ${TAKAHE_WEB_WORKER_NUM:-8} --max-requests 2000 --timeout 60 --preload -b 0.0.0.0:8000
healthcheck:
test: ['CMD', 'wget', '-qO/tmp/test', '--header', 'X-Forwarded-Proto: https', 'http://127.0.0.1:8000/api/v1/instance']
test:
[
"CMD",
"wget",
"-qO/tmp/test",
"--header",
"X-Forwarded-Proto: https",
"http://127.0.0.1:8000/api/v1/instance",
]
depends_on:
migration:
condition: service_completed_successfully
Expand Down
2 changes: 1 addition & 1 deletion social/templates/feed_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
data-cover="{{ item.cover_url|default:item.parent_item.cover.url }}"
data-title="{{ item.display_title }}"
data-album="{{ item.parent_item.display_title }}"
data-hosts="{{ item.parent_item.hosts|join:' / ' }}"
data-hosts="{{ item.parent_item.host|join:' / ' }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' item.uuid %}" {% endif %}
data-position="{{ piece.metadata.position | default:0 }}"><i class="fa-solid fa-circle-play"></i></a>
{% else %}
Expand Down

0 comments on commit 8161fcf

Please sign in to comment.