2021-06-02 17:25:04 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MarkerByID returns a Marker based on the ID.
|
|
|
|
func MarkerByID(id uint) (marker entity.Marker, err error) {
|
|
|
|
if err := UnscopedDb().Where("id = ?", id).
|
|
|
|
First(&marker).Error; err != nil {
|
|
|
|
return marker, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return marker, nil
|
|
|
|
}
|
2021-08-12 04:54:20 +02:00
|
|
|
|
|
|
|
// Markers finds a list of file markers filtered by type, embeddings, and sorted by id.
|
2021-08-12 12:05:10 +02:00
|
|
|
func Markers(limit, offset int, markerType string, embeddings, unmatched bool) (result entity.Markers, err error) {
|
2021-08-12 04:54:20 +02:00
|
|
|
stmt := Db()
|
|
|
|
|
|
|
|
if markerType != "" {
|
|
|
|
stmt = stmt.Where("marker_type = ?", markerType)
|
|
|
|
}
|
|
|
|
|
|
|
|
if embeddings {
|
|
|
|
stmt = stmt.Where("embeddings <> ''")
|
|
|
|
}
|
|
|
|
|
2021-08-12 12:05:10 +02:00
|
|
|
if unmatched {
|
|
|
|
stmt = stmt.Where("ref_uid = ''")
|
2021-08-12 04:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stmt = stmt.Order("id").Limit(limit).Offset(offset)
|
|
|
|
err = stmt.Find(&result).Error
|
|
|
|
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Embeddings finds all face embeddings.
|
|
|
|
func Embeddings() (result entity.Embeddings, err error) {
|
|
|
|
var col []string
|
|
|
|
|
|
|
|
stmt := Db().
|
|
|
|
Model(&entity.Marker{}).
|
|
|
|
Where("marker_type = ?", entity.MarkerFace).
|
|
|
|
Where("embeddings <> ''").
|
|
|
|
Order("id")
|
|
|
|
|
|
|
|
if err := stmt.Pluck("embeddings", &col).Error; err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, embeddingsJson := range col {
|
|
|
|
if embeddings := entity.UnmarshalEmbeddings(embeddingsJson); len(embeddings) > 0 {
|
|
|
|
result = append(result, embeddings...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|