Experimental: Allow search results to include albums.

I've been thinking about this for a while but couldn't think of
the perfect way to implement it. I still haven't, so instead I'm
just starting with something and we'll see how to improve later.
At any rate, I can update the rest of the system to expect Albums
coming out of search so that if I ever have a better algorithm
everything else will already be ready for it.
For this first experiment, just any photos that are part of an album
will send that album out as a result. It doesn't even respect the
limit parameter, it's really just to see how it feels to use.
This commit is contained in:
voussoir 2020-04-02 22:36:40 -07:00
parent 83c2ed7882
commit dd3d40de53
3 changed files with 13 additions and 1 deletions

View file

@ -628,6 +628,7 @@ class PDBPhotoMixin:
#explain = self.sql_execute('EXPLAIN QUERY PLAN ' + query, bindings) #explain = self.sql_execute('EXPLAIN QUERY PLAN ' + query, bindings)
#print('\n'.join(str(x) for x in explain.fetchall())) #print('\n'.join(str(x) for x in explain.fetchall()))
generator = self.sql_select(query, bindings) generator = self.sql_select(query, bindings)
seen_albums = set()
photos_received = 0 photos_received = 0
for row in generator: for row in generator:
photo = self.get_cached_instance('photo', row) photo = self.get_cached_instance('photo', row)
@ -654,6 +655,11 @@ class PDBPhotoMixin:
if limit is not None and photos_received >= limit: if limit is not None and photos_received >= limit:
break break
for album in photo.get_containing_albums():
if album not in seen_albums:
seen_albums.add(album)
yield album
photos_received += 1 photos_received += 1
yield photo yield photo

View file

@ -408,6 +408,7 @@ def get_search_core():
# TAGS ON THIS PAGE # TAGS ON THIS PAGE
total_tags = set() total_tags = set()
for photo in photos: for photo in photos:
if isinstance(photo, etiquette.objects.Photo):
total_tags.update(photo.get_tags()) total_tags.update(photo.get_tags())
total_tags = sorted(total_tags, key=lambda t: t.name) total_tags = sorted(total_tags, key=lambda t: t.name)

View file

@ -2,6 +2,7 @@
<html> <html>
<head> <head>
{% import "photo_card.html" as photo_card %} {% import "photo_card.html" as photo_card %}
{% import "album_card.html" as album_card %}
{% import "header.html" as header %} {% import "header.html" as header %}
{% import "tag_object.html" as tag_object %} {% import "tag_object.html" as tag_object %}
{% import "clipboard_tray.html" as clipboard_tray %} {% import "clipboard_tray.html" as clipboard_tray %}
@ -348,7 +349,11 @@
{{prev_next_buttons()}} {{prev_next_buttons()}}
<div id="search_results_holder"> <div id="search_results_holder">
{% for photo in photos %} {% for photo in photos %}
{% if photo.__class__.__name__ == 'Photo' %}
{{photo_card.create_photo_card(photo, view=search_kwargs["view"])}} {{photo_card.create_photo_card(photo, view=search_kwargs["view"])}}
{% elif photo.__class__.__name__ == 'Album' %}
{{album_card.create_album_card(photo, view=search_kwargs["view"])}}
{% endif %}
{% endfor %} {% endfor %}
</div> </div>