Files
sm-bm-plugin/search.go
Jakub Zych ffd19342b2 feat: keep the materials index in sync and add bm:materials-reindex
- the materials admin syncs after create and update and removes after
  delete, once the save transaction commits (UseMaterialIndex, set at Boot)
- POST and PUT /api/v1/bm/materials sync after the transaction, DELETE
  removes the document (its statement has no primary key, so no callback)
- bm:materials-reindex [--fresh] [--if-configured] ensures the index and
  syncs every material; it refuses without an engine and runs nightly
  at 04:15 with --if-configured
- TestMaterialSearchAgainstDatabase (Postgres) is written for the final
  verification phase
2026-11-08 19:50:50 +01:00

27 lines
989 B
Go

package bm
import (
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/beachcomber"
_ "git.golem15.com/golem15/summercms/modules/beachcomber/typesense"
"git.golem15.com/jakub/sm-bm-plugin/classes"
"git.golem15.com/jakub/sm-bm-plugin/controllers"
)
// wireSearch builds the app's beachcomber service (search.driver; the
// typesense engine registers itself through the blank import), installs the
// jz.bm-only Gate and the material indexer, which the API handlers and the
// materials admin hooks use. The Gate is app-wide, so it is on only for
// contexts jz.bm marks: golem15.chatchannels' message syncs stay off and
// chat messages never reach the index.
func (p *Plugin) wireSearch(app *backpack.App) error {
svc, err := beachcomber.From(app)
if err != nil {
return err
}
svc.SetGate(classes.MaterialSearchGate())
p.materialIndex = classes.NewMaterialIndexer(app)
controllers.UseMaterialIndex(p.materialIndex)
return nil
}