I'm following this example of running to_tsvector()
over an item as its added to a postgres DB: https://github.com/sachaarbonel/pgsearch-gorm-example/blob/master/search/main.go
articles := []Article{
Article{Title: "Title of Pack my box with five dozen liquor jugs.", PublishDate: now, Summary: "Summary of Pack my box with five dozen liquor jugs.", TopImage: "url"},
Article{Title: "Title of Jackdaws love my big sphinx of quartz.", PublishDate: now, Summary: "Summary of Jackdaws love my big sphinx of quartz.", TopImage: "url"},
Article{Title: "Title of The five boxing wizards jump quickly.", PublishDate: now, Summary: "Summary of The five boxing wizards jump quickly.", TopImage: "url"},
Article{Title: "Title of How vexingly quick daft zebras jump!", PublishDate: now, Summary: "Summary of How vexingly quick daft zebras jump!", TopImage: "url"},
}
for _, a := range articles {
db.Exec("INSERT INTO articles (title, title_tokens, publish_date, summary, summary_tokens, top_image) VALUES (?, to_tsvector(?), ?, ?, to_tsvector(?), ?)", a.Title, a.Title, now, a.Summary, a.Summary, a.TopImage)
}
This example works fine, but I am wondering if theres a way to do this more succinctly without executing raw SQL. Example:
db.Model(Article{}).Create(map[string]interface{}{
Title: "Title of Pack my box with five dozen liquor jugs.", PublishDate: now, Summary: "Summary of Pack my box with five dozen liquor jugs.", TopImage: "url",
})
With the above example, how would I also then include to_tsvector
over several of the key/values?
I have tried the following documentation but I just can't seem to get it to work. Is this even the correct way?