From ebc33ce352d8da8892490c562305d5ac6eebc2bc Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 22 Jan 2022 14:04:21 -0500 Subject: [PATCH] make external search async --- common/index.py | 5 ++ .../common/external_search_result.html | 48 +++++++++++++++++++ common/templates/common/search_result.html | 48 ++++--------------- common/urls.py | 1 + common/utils.py | 2 + common/views.py | 17 ++++++- 6 files changed, 79 insertions(+), 42 deletions(-) create mode 100644 common/templates/common/external_search_result.html diff --git a/common/index.py b/common/index.py index 5494802e..42227b60 100644 --- a/common/index.py +++ b/common/index.py @@ -5,3 +5,8 @@ if settings.SEARCH_BACKEND == 'MEILISEARCH': from .search.meilisearch import Indexer elif settings.SEARCH_BACKEND == 'TYPESENSE': from .search.typesense import Indexer +else: + class Indexer: + @classmethod + def update_model_indexable(self, cls): + pass diff --git a/common/templates/common/external_search_result.html b/common/templates/common/external_search_result.html new file mode 100644 index 00000000..9d2132bb --- /dev/null +++ b/common/templates/common/external_search_result.html @@ -0,0 +1,48 @@ +{% load static %} +{% load i18n %} +{% load l10n %} +{% load humanize %} +{% load admin_url %} +{% load mastodon %} +{% load oauth_token %} +{% load truncate %} +{% load highlight %} +{% load thumb %} + +{% for item in external_items %} +
  • +
    + + + +
    +
    +
    + + {% if request.GET.q %} + {{ item.title | highlight:request.GET.q }} + {% else %} + {{ item.title }} + {% endif %} + + + {% if not request.GET.c or not request.GET.c in categories %} + [{{item.verbose_category_name}}] + {% endif %} + + {{ item.source_site.label }} + +
    + + + {{item.subtitle}} + +

    + {{ item.brief }} +

    +
    +
    +
    + +
  • +{% endfor %} \ No newline at end of file diff --git a/common/templates/common/search_result.html b/common/templates/common/search_result.html index 096adf00..4f73bbc9 100644 --- a/common/templates/common/search_result.html +++ b/common/templates/common/search_result.html @@ -16,6 +16,7 @@ {{ site_name }} - {% trans '搜索结果' %} + @@ -49,51 +50,18 @@ {% trans '无站内条目匹配' %} {% endfor %} - - {% for item in external_items %} -
  • -
    - - - -
    -
    -
    - - {% if request.GET.q %} - {{ item.title | highlight:request.GET.q }} - {% else %} - {{ item.title }} - {% endif %} - - - {% if not request.GET.c or not request.GET.c in categories %} - [{{item.verbose_category_name}}] - {% endif %} - - {{ item.source_site.label }} - -
    - - - {{item.subtitle}} - -

    - {{ item.brief }} -

    -
    -
    -
    - -
  • - {% endfor %} + {% if request.GET.q %} +
  • + {% trans '正在实时搜索站外条目' %} +
  • + {% endif %}