Search posts

This commit is contained in:
2024-10-13 21:25:15 +08:00
parent 1e16e5c343
commit 362e691b37
5 changed files with 114 additions and 116 deletions

View File

@ -97,6 +97,11 @@ func FilterPostDraft(tx *gorm.DB) *gorm.DB {
return tx.Where("is_draft = ? OR is_draft IS NULL", false)
}
func FilterPostWithFuzzySearch(tx *gorm.DB, probe string) *gorm.DB {
probe = "%" + probe + "%"
return tx.Where("? AND body->>'content' ILIKE ?", gorm.Expr("body ? 'content'"), probe)
}
func PreloadGeneral(tx *gorm.DB) *gorm.DB {
return tx.
Preload("Tags").