Search: revert labelIDs to labelIds for improved merging

This commit is contained in:
Keith Martin 2025-11-23 10:50:24 +10:00
parent 8e37a114c7
commit 293e7bc9e9
2 changed files with 18 additions and 18 deletions

View file

@ -287,23 +287,23 @@ func searchPhotos(frm form.SearchPhotos, sess *entity.Session, resultCols string
// Filter by label, label category and keywords.
if txt.NotEmpty(frm.Label) {
var categories []entity.Category
var labelIDs []uint
var labelIds []uint
if labels, labelErr := entity.FindLabels(frm.Label, txt.Or, false); len(labels) == 0 || labelErr != nil {
log.Debugf("search: label %s not found", txt.LogParamLower(frm.Label))
return PhotoResults{}, 0, nil
} else {
for _, l := range labels {
labelIDs = append(labelIDs, l.ID)
labelIds = append(labelIds, l.ID)
Log("find categories", Db().Where("category_id = ?", l.ID).Find(&categories).Error)
log.Debugf("search: label %s includes %d categories", txt.LogParamLower(l.LabelName), len(categories))
for _, category := range categories {
labelIDs = append(labelIDs, category.LabelID)
labelIds = append(labelIds, category.LabelID)
}
}
s = s.Joins("JOIN photos_labels ON photos_labels.photo_id = files.photo_id AND photos_labels.uncertainty < 100 AND photos_labels.label_id IN (?)", labelIDs).
s = s.Joins("JOIN photos_labels ON photos_labels.photo_id = files.photo_id AND photos_labels.uncertainty < 100 AND photos_labels.label_id IN (?)", labelIds).
Group("photos.id, files.id")
}
}
@ -395,7 +395,7 @@ func searchPhotos(frm form.SearchPhotos, sess *entity.Session, resultCols string
// Filter by query string.
if frm.Query != "" {
var categories []entity.Category
var labelIDs []uint
var labelIds []uint
if labels, labelsErr := entity.FindLabels(frm.Query, " ", false); len(labels) == 0 || labelsErr != nil {
log.Tracef("search: label %s not found, using fuzzy search", txt.LogParamLower(frm.Query))
@ -405,23 +405,23 @@ func searchPhotos(frm form.SearchPhotos, sess *entity.Session, resultCols string
}
} else {
for _, l := range labels {
labelIDs = append(labelIDs, l.ID)
labelIds = append(labelIds, l.ID)
Log("find categories", Db().Where("category_id = ?", l.ID).Find(&categories).Error)
log.Tracef("search: label %s includes %d categories", txt.LogParamLower(l.LabelName), len(categories))
for _, category := range categories {
labelIDs = append(labelIDs, category.LabelID)
labelIds = append(labelIds, category.LabelID)
}
}
if wheres := LikeAnyKeyword("k.keyword", frm.Query); len(wheres) > 0 {
for _, where := range wheres {
s = s.Where("files.photo_id IN (SELECT pk.photo_id FROM keywords k JOIN photos_keywords pk ON k.id = pk.keyword_id WHERE (?)) OR "+
"files.photo_id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", gorm.Expr(where), labelIDs)
"files.photo_id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", gorm.Expr(where), labelIds)
}
} else {
s = s.Where("files.photo_id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", labelIDs)
s = s.Where("files.photo_id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", labelIds)
}
}
}

View file

@ -209,24 +209,24 @@ func UserPhotosGeo(frm form.SearchPhotosGeo, sess *entity.Session) (results GeoR
// Filter by label, label category and keywords.
if txt.NotEmpty(frm.Label) {
var categories []entity.Category
var labelIDs []uint
var labelIds []uint
if labels, labelsErr := entity.FindLabels(frm.Label, txt.Or, false); len(labels) == 0 || labelsErr != nil {
log.Debugf("search: label %s not found with error %+v", txt.LogParamLower(frm.Label), labelsErr)
return GeoResults{}, nil
} else {
for _, l := range labels {
labelIDs = append(labelIDs, l.ID)
labelIds = append(labelIds, l.ID)
Log("find categories", Db().Where("category_id = ?", l.ID).Find(&categories).Error)
log.Debugf("search: label %s includes %d categories", txt.LogParamLower(l.LabelName), len(categories))
for _, category := range categories {
labelIDs = append(labelIDs, category.LabelID)
labelIds = append(labelIds, category.LabelID)
}
}
s = s.Joins("JOIN photos_labels ON photos_labels.photo_id = files.photo_id AND photos_labels.uncertainty < 100 AND photos_labels.label_id IN (?)", labelIDs).
s = s.Joins("JOIN photos_labels ON photos_labels.photo_id = files.photo_id AND photos_labels.uncertainty < 100 AND photos_labels.label_id IN (?)", labelIds).
Group("photos.id, files.id")
}
}
@ -308,7 +308,7 @@ func UserPhotosGeo(frm form.SearchPhotosGeo, sess *entity.Session) (results GeoR
// Filter by label, label category, and keywords.
if frm.Query != "" {
var categories []entity.Category
var labelIDs []uint
var labelIds []uint
if labels, labelsErr := entity.FindLabels(frm.Query, " ", false); len(labels) == 0 || labelsErr != nil {
log.Tracef("search: label %s not found, using fuzzy search", txt.LogParamLower(frm.Query))
@ -318,23 +318,23 @@ func UserPhotosGeo(frm form.SearchPhotosGeo, sess *entity.Session) (results GeoR
}
} else {
for _, l := range labels {
labelIDs = append(labelIDs, l.ID)
labelIds = append(labelIds, l.ID)
Log("find categories", Db().Where("category_id = ?", l.ID).Find(&categories).Error)
log.Tracef("search: label %s includes %d categories", txt.LogParamLower(l.LabelName), len(categories))
for _, category := range categories {
labelIDs = append(labelIDs, category.LabelID)
labelIds = append(labelIds, category.LabelID)
}
}
if wheres := LikeAnyKeyword("k.keyword", frm.Query); len(wheres) > 0 {
for _, where := range wheres {
s = s.Where("photos.id IN (SELECT pk.photo_id FROM keywords k JOIN photos_keywords pk ON k.id = pk.keyword_id WHERE (?)) OR "+
"photos.id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", gorm.Expr(where), labelIDs)
"photos.id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", gorm.Expr(where), labelIds)
}
} else {
s = s.Where("photos.id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", labelIDs)
s = s.Where("photos.id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))", labelIds)
}
}
}