photoprism/internal/entity/faces.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

58 lines
1.1 KiB
Go

package entity
import "fmt"
// Faces represents a Face slice.
type Faces []Face
// Embeddings returns all face embeddings in this slice.
func (f Faces) Embeddings() (embeddings Embeddings) {
for _, m := range f {
embeddings = append(embeddings, m.Embedding())
}
return embeddings
}
// IDs returns all face IDs in this slice.
func (f Faces) IDs() (ids []string) {
for _, m := range f {
ids = append(ids, m.ID)
}
return ids
}
// Delete (soft) deletes all subjects.
func (f Faces) Delete() error {
for _, m := range f {
if err := m.Delete(); err != nil {
return err
}
}
return nil
}
// OrphanFaces returns unused faces.
func OrphanFaces() (Faces, error) {
orphans := Faces{}
err := Db().
Where(fmt.Sprintf("id NOT IN (SELECT DISTINCT face_id FROM %s)", Marker{}.TableName())).
Find(&orphans).Error
return orphans, err
}
// DeleteOrphanFaces finds and (soft) deletes all unused face clusters.
func DeleteOrphanFaces() (count int, err error) {
orphans, err := OrphanFaces()
if err != nil {
return 0, err
}
return len(orphans), orphans.Delete()
}