Update index after editing photo metadata
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
16e17b33bf
commit
ccd92a4715
|
@ -228,6 +228,10 @@ class Photo extends Abstract {
|
|||
values.ModifiedTitle = true
|
||||
}
|
||||
|
||||
if(values.PhotoKeywords) {
|
||||
values.ModifiedKeywords = true
|
||||
}
|
||||
|
||||
if(values.PhotoLat || values.PhotoLng || values.PhotoAltitude) {
|
||||
values.ModifiedLocation = true
|
||||
}
|
||||
|
|
|
@ -5457,16 +5457,16 @@ var rules = LabelRules{
|
|||
Categories: []string{},
|
||||
},
|
||||
"sunglass": {
|
||||
Label: "sunshine",
|
||||
Label: "sunglasses",
|
||||
Threshold: 0.200000,
|
||||
Priority: 2,
|
||||
Categories: []string{},
|
||||
Categories: []string{"portrait"},
|
||||
},
|
||||
"sunglasses": {
|
||||
Label: "sunshine",
|
||||
Label: "sunglasses",
|
||||
Threshold: 0.200000,
|
||||
Priority: 2,
|
||||
Categories: []string{},
|
||||
Categories: []string{"portrait"},
|
||||
},
|
||||
"sunscreen": {
|
||||
Label: "bottle",
|
||||
|
|
|
@ -3458,9 +3458,11 @@ ear:
|
|||
see: ignore
|
||||
|
||||
sunglasses:
|
||||
label: sunshine
|
||||
label: sunglasses
|
||||
priority: 2
|
||||
threshold: 0.2
|
||||
categories:
|
||||
- portrait
|
||||
|
||||
sunglass:
|
||||
see: sunglasses
|
||||
|
|
|
@ -86,18 +86,18 @@ func (m *Location) Find(db *gorm.DB, api string) error {
|
|||
}
|
||||
|
||||
// Keywords computes keyword based on a Location
|
||||
func (m *Location) Keywords() []string {
|
||||
result := []string{
|
||||
strings.ToLower(m.City()),
|
||||
strings.ToLower(m.State()),
|
||||
strings.ToLower(m.CountryName()),
|
||||
strings.ToLower(m.Category()),
|
||||
}
|
||||
func (m *Location) Keywords() (result []string) {
|
||||
result = append(result, txt.Keywords(m.City())...)
|
||||
result = append(result, txt.Keywords(m.State())...)
|
||||
result = append(result, txt.Keywords(m.CountryName())...)
|
||||
result = append(result, txt.Keywords(m.Category())...)
|
||||
|
||||
result = append(result, txt.Keywords(m.Name())...)
|
||||
result = append(result, txt.Keywords(m.Label())...)
|
||||
result = append(result, txt.Keywords(m.Notes())...)
|
||||
|
||||
result = txt.UniqueWords(result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ type Photo struct {
|
|||
ModifiedTitle bool `json:"ModifiedTitle"`
|
||||
ModifiedDetails bool `json:"ModifiedDetails"`
|
||||
ModifiedLocation bool `json:"ModifiedLocation"`
|
||||
ModifiedKeywords bool `json:"ModifiedKeywords"`
|
||||
ModifiedDate bool `json:"ModifiedDate"`
|
||||
Camera *Camera `json:"Camera"`
|
||||
Lens *Lens `json:"Lens"`
|
||||
|
@ -72,6 +73,8 @@ func SavePhoto(model Photo, form form.Photo, db *gorm.DB) error {
|
|||
return err
|
||||
}
|
||||
|
||||
model.IndexKeywords(db)
|
||||
|
||||
return db.Save(&model).Error
|
||||
}
|
||||
|
||||
|
@ -114,8 +117,9 @@ func (m *Photo) BeforeSave(scope *gorm.Scope) error {
|
|||
}
|
||||
|
||||
// IndexKeywords adds given keywords to the photo entry
|
||||
func (m *Photo) IndexKeywords(keywords []string, db *gorm.DB) {
|
||||
func (m *Photo) IndexKeywords(db *gorm.DB) {
|
||||
var keywordIds []uint
|
||||
var keywords []string
|
||||
|
||||
// Add title, description and other keywords
|
||||
keywords = append(keywords, txt.Keywords(m.PhotoTitle)...)
|
||||
|
|
|
@ -34,6 +34,7 @@ type Photo struct {
|
|||
TimeZone string `json:"TimeZone"`
|
||||
TakenAtLocal time.Time `json:"TakenAtLocal"`
|
||||
ModifiedTitle bool `json:"ModifiedTitle"`
|
||||
ModifiedKeywords bool `json:"ModifiedKeywords"`
|
||||
ModifiedDetails bool `json:"ModifiedDetails"`
|
||||
ModifiedLocation bool `json:"ModifiedLocation"`
|
||||
ModifiedDate bool `json:"ModifiedDate"`
|
||||
|
|
|
@ -36,7 +36,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) I
|
|||
var file, primaryFile entity.File
|
||||
var metaData meta.Data
|
||||
var photoQuery, fileQuery *gorm.DB
|
||||
var keywords []string
|
||||
var locKeywords []string
|
||||
|
||||
labels := classify.Labels{}
|
||||
fileBase := m.Base()
|
||||
|
@ -179,12 +179,12 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) I
|
|||
}
|
||||
|
||||
if fileChanged || o.UpdateKeywords || o.UpdateLocation || o.UpdateTitle {
|
||||
locKeywords, locLabels := ind.indexLocation(m, &photo, labels, fileChanged, o)
|
||||
keywords = append(keywords, locKeywords...)
|
||||
var locLabels classify.Labels
|
||||
locKeywords, locLabels = ind.indexLocation(m, &photo, labels, fileChanged, o)
|
||||
labels = append(labels, locLabels...)
|
||||
}
|
||||
|
||||
if photo.NoTitle() || (fileChanged || o.UpdateTitle) && photo.ModifiedTitle == false && photo.NoLocation() {
|
||||
if photo.NoTitle() || (fileChanged || o.UpdateTitle) && !photo.ModifiedTitle && photo.NoLocation() {
|
||||
if len(labels) > 0 && labels[0].Priority >= -1 && labels[0].Uncertainty <= 85 && labels[0].Name != "" {
|
||||
photo.PhotoTitle = fmt.Sprintf("%s / %s", txt.Title(labels[0].Name), m.DateCreated().Format("2006"))
|
||||
} else if !photo.TakenAtLocal.IsZero() {
|
||||
|
@ -273,14 +273,17 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) I
|
|||
if file.FilePrimary && (fileChanged || o.UpdateKeywords) {
|
||||
w := txt.Keywords(photo.PhotoKeywords)
|
||||
|
||||
if NonCanonical(fileBase) {
|
||||
w = append(w, txt.Keywords(filePath)...)
|
||||
w = append(w, txt.Keywords(fileBase)...)
|
||||
}
|
||||
if !photo.ModifiedKeywords {
|
||||
if NonCanonical(fileBase) {
|
||||
w = append(w, txt.Keywords(filePath)...)
|
||||
w = append(w, txt.Keywords(fileBase)...)
|
||||
}
|
||||
|
||||
w = append(w, txt.Keywords(file.OriginalName)...)
|
||||
w = append(w, file.FileMainColor)
|
||||
w = append(w, labels.Keywords()...)
|
||||
w = append(w, locKeywords...)
|
||||
w = append(w, txt.Keywords(file.OriginalName)...)
|
||||
w = append(w, file.FileMainColor)
|
||||
w = append(w, labels.Keywords()...)
|
||||
}
|
||||
|
||||
photo.PhotoKeywords = strings.Join(txt.UniqueWords(w), ", ")
|
||||
|
||||
|
@ -325,7 +328,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) I
|
|||
file.PhotoUUID = photo.PhotoUUID
|
||||
|
||||
if file.FilePrimary && (fileChanged || o.UpdateKeywords) {
|
||||
photo.IndexKeywords(keywords, ind.db)
|
||||
photo.IndexKeywords(ind.db)
|
||||
}
|
||||
|
||||
if fileQuery.Error == nil {
|
||||
|
@ -512,7 +515,7 @@ func (ind *Index) indexLocation(mediaFile *MediaFile, photo *entity.Photo, label
|
|||
labels = append(labels, classify.LocationLabel(locCategory, 0, -1))
|
||||
}
|
||||
|
||||
if (fileChanged || o.UpdateTitle) && photo.ModifiedTitle == false {
|
||||
if (fileChanged || o.UpdateTitle) && !photo.ModifiedTitle {
|
||||
if title := labels.Title(location.Name()); title != "" { // TODO: User defined title format
|
||||
log.Infof("index: using label \"%s\" to create photo title", title)
|
||||
if location.NoCity() || location.LongCity() || location.CityContains(title) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user