Skip to content

Commit

Permalink
Merge pull request #12 from PDOK/search-suggest-endpoint
Browse files Browse the repository at this point in the history
feat: add search endpoint
  • Loading branch information
rkettelerij authored Dec 23, 2024
2 parents e135f5b + 449e581 commit 8123787
Show file tree
Hide file tree
Showing 34 changed files with 4,297 additions and 90 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/e2e-test.yml

This file was deleted.

17 changes: 14 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

"github.com/PDOK/gomagpie/config"
"github.com/PDOK/gomagpie/internal/search"
"github.com/iancoleman/strcase"

eng "github.com/PDOK/gomagpie/internal/engine"
Expand Down Expand Up @@ -117,9 +118,11 @@ var (
EnvVars: []string{strcase.ToScreamingSnake(dbPortFlag)},
},
dbNameFlag: &cli.StringFlag{
Name: dbNameFlag,
Usage: "Connect to this database",
EnvVars: []string{strcase.ToScreamingSnake(dbNameFlag)},
Name: dbNameFlag,
Usage: "Connect to this database",
Value: "postgres",
Required: false,
EnvVars: []string{strcase.ToScreamingSnake(dbNameFlag)},
},
dbSslModeFlag: &cli.StringFlag{
Name: dbSslModeFlag,
Expand Down Expand Up @@ -166,6 +169,12 @@ func main() {
commonDBFlags[dbUsernameFlag],
commonDBFlags[dbPasswordFlag],
commonDBFlags[dbSslModeFlag],
&cli.PathFlag{
Name: searchIndexFlag,
EnvVars: []string{strcase.ToScreamingSnake(searchIndexFlag)},
Usage: "Name of search index to use",
Value: "search_index",
},
},
Action: func(c *cli.Context) error {
log.Println(c.Command.Usage)
Expand All @@ -186,6 +195,8 @@ func main() {
}
// Each OGC API building block makes use of said Engine
ogc.SetupBuildingBlocks(engine, dbConn)
// Create search endpoint
search.NewSearch(engine, dbConn, c.String(searchIndexFlag))

return engine.Start(address, debugPort, shutdownDelay)
},
Expand Down
12 changes: 11 additions & 1 deletion config/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *Config) HasCollections() bool {
return c.AllCollections() != nil
}

// AllCollections get all collections - with for example features, tiles, 3d tiles - offered through this OGC API.
// AllCollections get all collections - with for example features, tiles, 3d tiles - offered through this OGC API.
// Results are returned in alphabetic or literal order.
func (c *Config) AllCollections() GeoSpatialCollections {
if len(c.CollectionOrder) > 0 {
Expand All @@ -134,6 +134,16 @@ func (c *Config) AllCollections() GeoSpatialCollections {
return c.Collections
}

func (g GeoSpatialCollections) WithSearch() GeoSpatialCollections {
result := make([]GeoSpatialCollection, 0, len(g))
for _, collection := range g {
if collection.Search != nil {
result = append(result, collection)
}
}
return result
}

// Unique lists all unique GeoSpatialCollections (no duplicate IDs).
// Don't use in hot path (creates a map on every invocation).
func (g GeoSpatialCollections) Unique() []GeoSpatialCollection {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/go-playground/validator/v10 v10.22.1
github.com/go-spatial/geom v0.1.0
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
github.com/goccy/go-json v0.10.3
github.com/gomarkdown/markdown v0.0.0-20240930133441-72d49d9543d8
github.com/iancoleman/strcase v0.3.0
github.com/jackc/pgx/v5 v5.7.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/gomarkdown/markdown v0.0.0-20240930133441-72d49d9543d8 h1:4txT5G2kqVAKMjzidIabL/8KqjIK71yj30YOeuxLn10=
Expand Down
16 changes: 10 additions & 6 deletions internal/engine/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
)

const (
specPath = templatesDir + "openapi/"
preamble = specPath + "preamble.go.json"
problems = specPath + "problems.go.json"
commonCollections = specPath + "common-collections.go.json"
commonSpec = specPath + "common.go.json"
HTMLRegex = `<[/]?([a-zA-Z]+).*?>`
specPath = templatesDir + "openapi/"
preamble = specPath + "preamble.go.json"
problems = specPath + "problems.go.json"
commonCollections = specPath + "common-collections.go.json"
commonSpec = specPath + "common.go.json"
featuresSearchSpec = specPath + "features-search.go.json"
HTMLRegex = `<[/]?([a-zA-Z]+).*?>`
)

type OpenAPI struct {
Expand All @@ -51,6 +52,9 @@ func newOpenAPI(config *gomagpieconfig.Config) *OpenAPI {
if config.AllCollections() != nil {
defaultOpenAPIFiles = append(defaultOpenAPIFiles, commonCollections)
}
if len(config.Collections.WithSearch()) > 0 {
defaultOpenAPIFiles = append(defaultOpenAPIFiles, featuresSearchSpec)
}

// add preamble first
openAPIFiles := []string{preamble}
Expand Down
Loading

0 comments on commit 8123787

Please sign in to comment.