indicate search result by category
This commit is contained in:
parent
1e241bf494
commit
92ae75d864
3 changed files with 54 additions and 13 deletions
|
@ -5,6 +5,7 @@ from typesense.exceptions import ObjectNotFound
|
|||
from django.conf import settings
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
from catalog.models import Item
|
||||
from pprint import pprint
|
||||
|
||||
INDEX_NAME = "catalog"
|
||||
SEARCHABLE_ATTRIBUTES = [
|
||||
|
@ -249,6 +250,7 @@ class Indexer:
|
|||
"per_page": SEARCH_PAGE_SIZE,
|
||||
"query_by": ",".join(SEARCHABLE_ATTRIBUTES),
|
||||
"filter_by": filters,
|
||||
# "facet_by": "category",
|
||||
"sort_by": "_text_match:desc,rating_count:desc"
|
||||
# 'facetsDistribution': ['_class'],
|
||||
# 'sort_by': None,
|
||||
|
@ -257,7 +259,7 @@ class Indexer:
|
|||
|
||||
try:
|
||||
r = cls.instance().collections[INDEX_NAME].documents.search(options)
|
||||
print(r)
|
||||
# pprint(r)
|
||||
results.items = list(
|
||||
[
|
||||
x
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<main>
|
||||
<div class="grid__main">
|
||||
<article>
|
||||
<h5>{% trans '正在连线' %}{{ site.SITE_NAME.label }}</h5>
|
||||
<h5>正在从{{ site.SITE_NAME.label }}获取</h5>
|
||||
<div hx-get="{% url 'catalog:fetch_refresh' job_id %}"
|
||||
hx-trigger="load delay:2s"
|
||||
hx-swap="outerHTML">
|
||||
|
|
|
@ -20,31 +20,70 @@
|
|||
{% include '_header.html' %}
|
||||
<main>
|
||||
<div class="grid__main">
|
||||
<div class="main-section-wrapper">
|
||||
<div class="entity-list">
|
||||
<div>
|
||||
<div>
|
||||
{% if request.GET.q %}
|
||||
<h5>“{{ request.GET.q }}” {% trans '的搜索结果' %}</h5>
|
||||
<hgroup>
|
||||
<h5>“{{ request.GET.q }}” {% trans '的搜索结果' %}</h5>
|
||||
<div>
|
||||
{% if request.GET.c != 'book' %}
|
||||
<a href="?q={{ request.GET.q }}&c=book">书籍</a>
|
||||
{% else %}
|
||||
书籍
|
||||
{% endif %}
|
||||
|
|
||||
{% if request.GET.c != 'movietv' %}
|
||||
<a href="?q={{ request.GET.q }}&c=movietv">影视</a>
|
||||
{% else %}
|
||||
影视
|
||||
{% endif %}
|
||||
|
|
||||
{% if request.GET.c != 'podcast' %}
|
||||
<a href="?q={{ request.GET.q }}&c=podcast">播客</a>
|
||||
{% else %}
|
||||
播客
|
||||
{% endif %}
|
||||
|
|
||||
{% if request.GET.c != 'music' %}
|
||||
<a href="?q={{ request.GET.q }}&c=music">音乐</a>
|
||||
{% else %}
|
||||
音乐
|
||||
{% endif %}
|
||||
|
|
||||
{% if request.GET.c != 'game' %}
|
||||
<a href="?q={{ request.GET.q }}&c=game">游戏</a>
|
||||
{% else %}
|
||||
游戏
|
||||
{% endif %}
|
||||
|
|
||||
{% if request.GET.c and request.GET.c != 'all' %}
|
||||
<a href="?q={{ request.GET.q }}&c=all">全部</a>
|
||||
{% else %}
|
||||
全部
|
||||
{% endif %}
|
||||
</div>
|
||||
</hgroup>
|
||||
{% endif %}
|
||||
{% if request.GET.tag %}
|
||||
<h5>{% trans '含有标签' %} “{{ request.GET.tag }}” {% trans '的结果' %}</h5>
|
||||
{% endif %}
|
||||
<ul class="item-card-list">
|
||||
<div class="item-card-list">
|
||||
{% for item in items %}
|
||||
{% with "list_item_"|add:item.class_name|add:".html" as template %}
|
||||
{% include template with show_tags=1 %}
|
||||
{% endwith %}
|
||||
{% empty %}
|
||||
<li class="empty">{% trans '无站内条目匹配' %}</li>
|
||||
<p class="empty">{% trans '无站内条目匹配' %}</p>
|
||||
{% endfor %}
|
||||
{% if request.GET.q and user.is_authenticated %}
|
||||
<li hx-get="{% url 'catalog:external_search' %}?q={{ request.GET.q }}&c={{ request.GET.c }}&page={% if pagination.current_page %}{{ pagination.current_page }}{% else %}1{% endif %}"
|
||||
hx-trigger="load"
|
||||
hx-swap="outerHTML">
|
||||
{% trans '正在实时搜索站外条目' %}
|
||||
<p hx-get="{% url 'catalog:external_search' %}?q={{ request.GET.q }}&c={{ request.GET.c }}&page={% if pagination.current_page %}{{ pagination.current_page }}{% else %}1{% endif %}"
|
||||
hx-trigger="load"
|
||||
hx-swap="outerHTML">
|
||||
<span><i class="fa-solid fa-compact-disc fa-spin loading"></i></span>
|
||||
</li>
|
||||
{% trans '正在实时搜索站外条目' %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pagination">
|
||||
{% if pagination.has_prev %}
|
||||
|
|
Loading…
Add table
Reference in a new issue