This commit is contained in:
Simon Martens
2026-01-07 20:03:49 +01:00
parent f9fb077518
commit 54a6714e76
9 changed files with 1692 additions and 924 deletions

View File

@@ -0,0 +1,43 @@
package dbmodels
import (
"strings"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/core"
)
const (
defaultPlacesSearchLimit = 10
maxPlacesSearchLimit = 50
)
// SearchPlaces performs a lightweight search against the places table using the provided term.
// It matches against the place name and pseudonyms fields.
func SearchPlaces(app core.App, term string, limit int) ([]*Place, error) {
places := []*Place{}
trimmed := strings.TrimSpace(term)
if limit <= 0 {
limit = defaultPlacesSearchLimit
}
if limit > maxPlacesSearchLimit {
limit = maxPlacesSearchLimit
}
query := app.RecordQuery(PLACES_TABLE).
Limit(int64(limit))
if trimmed != "" {
query = query.Where(dbx.Or(
dbx.Like(PLACES_NAME_FIELD, trimmed).Match(true, true),
dbx.Like(PLACES_PSEUDONYMS_FIELD, trimmed).Match(true, true),
))
}
if err := query.All(&places); err != nil {
return nil, err
}
return places, nil
}