hide books from same works
This commit is contained in:
parent
02c781067d
commit
41a98d77a6
5 changed files with 43 additions and 18 deletions
|
@ -35,7 +35,7 @@ def search_item(
|
|||
query = query.strip()
|
||||
if not query:
|
||||
return 400, {"message": "Invalid query"}
|
||||
items, num_pages, count = query_index(
|
||||
items, num_pages, count, _ = query_index(
|
||||
query, page=page, category=category, prepare_external=False
|
||||
)
|
||||
return 200, {"data": items, "pages": num_pages, "count": count}
|
||||
|
|
|
@ -39,22 +39,38 @@ else:
|
|||
|
||||
def query_index(keywords, category=None, tag=None, page=1, prepare_external=True):
|
||||
result = Indexer.search(keywords, page=page, category=category, tag=tag)
|
||||
keys = []
|
||||
keys = set()
|
||||
items = []
|
||||
duplicated_items = []
|
||||
urls = []
|
||||
for i in result.items:
|
||||
key = (
|
||||
i.isbn
|
||||
if i.is_deleted or i.merged_to_item: # only happen if index is delayed
|
||||
continue
|
||||
my_key = (
|
||||
[i.isbn]
|
||||
if hasattr(i, "isbn")
|
||||
else (i.imdb_code if hasattr(i, "imdb_code") else None)
|
||||
else ([i.imdb_code] if hasattr(i, "imdb_code") else [])
|
||||
)
|
||||
if key is None:
|
||||
items.append(i)
|
||||
elif key not in keys: # skip dup with same imdb or isbn
|
||||
keys.append(key)
|
||||
if hasattr(i, "works"):
|
||||
my_key += [i[0] for i in i.works.all().values_list("id")]
|
||||
if len(my_key):
|
||||
l = len(keys) + len(my_key)
|
||||
keys.update(my_key)
|
||||
# check and skip dup with same imdb or isbn or works id
|
||||
if len(keys) < l:
|
||||
duplicated_items.append(i)
|
||||
else:
|
||||
items.append(i)
|
||||
else:
|
||||
items.append(i)
|
||||
for res in i.external_resources.all():
|
||||
urls.append(res.url)
|
||||
# hide show if its season exists
|
||||
seasons = [i for i in items if i.__class__ == TVSeason]
|
||||
for season in seasons:
|
||||
if season.show in items:
|
||||
duplicated_items.append(season.show)
|
||||
items.remove(season.show)
|
||||
|
||||
if prepare_external:
|
||||
# store site url to avoid dups in external search
|
||||
|
@ -62,13 +78,7 @@ def query_index(keywords, category=None, tag=None, page=1, prepare_external=True
|
|||
urls = list(set(cache.get(cache_key, []) + urls))
|
||||
cache.set(cache_key, urls, timeout=300)
|
||||
|
||||
# hide show if its season exists
|
||||
seasons = [i for i in items if i.__class__ == TVSeason]
|
||||
for season in seasons:
|
||||
if season.show in items:
|
||||
items.remove(season.show)
|
||||
|
||||
return items, result.num_pages, result.count
|
||||
return items, result.num_pages, result.count, duplicated_items
|
||||
|
||||
|
||||
def enqueue_fetch(url, is_refetch):
|
||||
|
|
|
@ -97,12 +97,13 @@ def search(request):
|
|||
if site:
|
||||
return fetch(request, keywords, False, site)
|
||||
|
||||
items, num_pages, _ = query_index(keywords, category, tag, p)
|
||||
items, num_pages, _, dup_items = query_index(keywords, category, tag, p)
|
||||
return render(
|
||||
request,
|
||||
"search_results.html",
|
||||
{
|
||||
"items": items,
|
||||
"dup_items": dup_items,
|
||||
"pagination": PageLinksGenerator(PAGE_LINK_NUMBER, p, num_pages),
|
||||
"sites": SiteName.labels,
|
||||
"hide_category": category is not None and category != "movietv",
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
{% include '_people.html' with people=item.genre role='' max=2 %}
|
||||
{% include '_people.html' with people=item.troupe role='' max=2 %}
|
||||
{% include '_people.html' with people=item.location role='' max=2 %}
|
||||
{% include '_people.html' with people=item.language role='' max=5 %}
|
||||
{% comment %} {% include '_people.html' with people=item.language role='' max=5 %} {% endcomment %}
|
||||
{% include '_people.html' with people=item.platform role='' max=5 %}
|
||||
{% if item.show %}
|
||||
<span>{{ item.show.type.label }}:<a href="{{ item.show.url }}">{{ item.show.title }}</a></span>
|
||||
|
|
|
@ -81,6 +81,20 @@
|
|||
{% empty %}
|
||||
<p class="empty">{% trans '无站内条目匹配' %}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if dup_items %}
|
||||
<p class="empty">
|
||||
已从结果中略去了来自同一著作或有相同标识号的 {{ dup_items|length }}个条目,<a href="#" _="on click toggle .hidden on #dup">点击这里可重新显示</a>
|
||||
</p>
|
||||
<div class="item-card-list hidden" id="dup">
|
||||
{% for item in dup_items %}
|
||||
{% with "list_item_"|add:item.class_name|add:".html" as template %}
|
||||
{% include template with show_tags=1 %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="item-card-list">
|
||||
{% if request.GET.q and user.is_authenticated %}
|
||||
<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"
|
||||
|
|
Loading…
Add table
Reference in a new issue