Labels: Sort results by quality and uncertainty

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-27 14:41:22 +02:00
parent d6dc411a88
commit 8cd075cf0f
2 changed files with 9 additions and 3 deletions

View file

@ -76,7 +76,8 @@ func (q *Query) LabelThumbByUUID(labelUUID string) (file entity.File, err error)
err = q.db.Where("files.file_primary AND files.deleted_at IS NULL").
Joins("JOIN labels ON labels.label_uuid = ?", labelUUID).
Joins("JOIN photos_labels ON photos_labels.label_id = labels.id AND photos_labels.photo_id = files.photo_id").
Order("photos_labels.uncertainty ASC").
Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL").
Order("photos.photo_quality DESC, photos_labels.uncertainty ASC").
First(&file).Error
if err == nil {
@ -88,7 +89,8 @@ func (q *Query) LabelThumbByUUID(labelUUID string) (file entity.File, err error)
Joins("JOIN photos_labels ON photos_labels.photo_id = files.photo_id").
Joins("JOIN categories c ON photos_labels.label_id = c.label_id").
Joins("JOIN labels ON c.category_id = labels.id AND labels.label_uuid= ?", labelUUID).
Order("photos_labels.uncertainty ASC").
Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL").
Order("photos.photo_quality DESC, photos_labels.uncertainty ASC").
First(&file).Error
return file, err

View file

@ -365,7 +365,11 @@ func (q *Query) Photos(f form.PhotoSearch) (results PhotoResults, count int, err
switch f.Order {
case entity.SortOrderRelevance:
s = s.Order("photo_quality DESC, taken_at DESC, files.file_primary DESC")
if f.Label != "" {
s = s.Order("photo_quality DESC, photos_labels.uncertainty ASC, taken_at DESC, files.file_primary DESC")
} else {
s = s.Order("photo_quality DESC, taken_at DESC, files.file_primary DESC")
}
case entity.SortOrderNewest:
s = s.Order("taken_at DESC, photos.photo_uuid, files.file_primary DESC")
case entity.SortOrderOldest: