photoprism/internal/entity/subjects.go
Michael Mayer 24eff21aa4 Search: Default to photo names and keywords #1517 #1560
Default to photo name when search term is too short or on the stop list.
Search full text index otherwise, which now include names of people
(requires reindexing).
2021-09-29 20:09:34 +02:00

42 lines
802 B
Go

package entity
import (
"fmt"
)
// Subjects represents a list of subjects.
type Subjects []Subject
// Delete (soft) deletes all subjects.
func (m Subjects) Delete() error {
for _, subj := range m {
if err := subj.Delete(); err != nil {
return err
}
}
return nil
}
// OrphanPeople returns unused subjects.
func OrphanPeople() (Subjects, error) {
orphans := Subjects{}
err := Db().
Where("subj_type = ?", SubjPerson).
Where(fmt.Sprintf("subj_uid NOT IN (SELECT DISTINCT subj_uid FROM %s)", Marker{}.TableName())).
Find(&orphans).Error
return orphans, err
}
// DeleteOrphanPeople finds and (soft) deletes all unused people.
func DeleteOrphanPeople() (count int, err error) {
subj, err := OrphanPeople()
if err != nil {
return 0, err
}
return len(subj), subj.Delete()
}