2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
2020-01-08 19:51:21 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/mutex"
|
2019-12-08 15:05:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Keyword for full text search
|
|
|
|
type Keyword struct {
|
|
|
|
ID uint `gorm:"primary_key"`
|
|
|
|
Keyword string `gorm:"type:varchar(64);index;"`
|
|
|
|
Skip bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewKeyword(keyword string) *Keyword {
|
|
|
|
keyword = strings.ToLower(strings.TrimSpace(keyword))
|
|
|
|
|
|
|
|
result := &Keyword{
|
|
|
|
Keyword: keyword,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Keyword) FirstOrCreate(db *gorm.DB) *Keyword {
|
2020-01-08 19:51:21 +01:00
|
|
|
mutex.Db.Lock()
|
|
|
|
defer mutex.Db.Unlock()
|
|
|
|
|
2019-12-19 09:37:10 +01:00
|
|
|
if err := db.FirstOrCreate(m, "keyword = ?", m.Keyword).Error; err != nil {
|
|
|
|
log.Errorf("keyword: %s", err)
|
|
|
|
}
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|