2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2020-04-26 14:31:33 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2019-12-08 15:05:35 +01:00
|
|
|
)
|
|
|
|
|
2020-02-21 01:14:45 +01:00
|
|
|
// Keyword used for full text search
|
2019-12-08 15:05:35 +01:00
|
|
|
type Keyword struct {
|
|
|
|
ID uint `gorm:"primary_key"`
|
|
|
|
Keyword string `gorm:"type:varchar(64);index;"`
|
|
|
|
Skip bool
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:14:45 +01:00
|
|
|
// NewKeyword registers a new keyword in database
|
2019-12-08 15:05:35 +01:00
|
|
|
func NewKeyword(keyword string) *Keyword {
|
2020-04-26 14:31:33 +02:00
|
|
|
keyword = strings.ToLower(txt.Clip(keyword, txt.ClipKeyword))
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
result := &Keyword{
|
|
|
|
Keyword: keyword,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:07:03 +02:00
|
|
|
// FirstOrCreate checks if the keyword already exist in the database
|
|
|
|
func (m *Keyword) FirstOrCreate() *Keyword {
|
|
|
|
if err := Db().FirstOrCreate(m, "keyword = ?", m.Keyword).Error; err != nil {
|
2019-12-19 09:37:10 +01:00
|
|
|
log.Errorf("keyword: %s", err)
|
|
|
|
}
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|