Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add search endpoint #12

Merged
merged 41 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
84612ff
feat: add search endpoint - groundwork
rkettelerij Nov 29, 2024
668face
feat: add search endpoint - connect to postgres
rkettelerij Dec 2, 2024
85e6f0d
feat: add search endpoint - disable e2e test (already covered by test…
rkettelerij Dec 3, 2024
927cd70
feat: add search endpoint - expand query parameter parsing
rkettelerij Dec 4, 2024
5598b60
feat: add search endpoint - make args with defaults optional
rkettelerij Dec 9, 2024
1ec613b
feat: add search endpoint - return more columns in select in orde to …
rkettelerij Dec 9, 2024
6d3da80
feat: add search endpoint - weird test failure, fixing
rkettelerij Dec 9, 2024
100655f
feat: add search endpoint - return GeoJSON response
rkettelerij Dec 9, 2024
d5a83cc
Merge branch 'master' into search-suggest-endpoint
rkettelerij Dec 9, 2024
a06da94
feat: add search endpoint - sync with master
rkettelerij Dec 9, 2024
09fd6ac
feat: add search endpoint - linting
rkettelerij Dec 9, 2024
50ec5ee
feat: add search endpoint - add numberReturned
rkettelerij Dec 9, 2024
b0c3ab4
feat: add search endpoint - add href to allow users to get the actual…
rkettelerij Dec 10, 2024
927f96e
feat: add search endpoint - add self link (alternate links to HTML/JS…
rkettelerij Dec 10, 2024
4faae30
feat: add search endpoint - highlight display name, not suggest
rkettelerij Dec 10, 2024
2e36235
Merge branch 'master' into search-suggest-endpoint
rkettelerij Dec 10, 2024
5c923f4
feat: add search endpoint - merge
rkettelerij Dec 10, 2024
f5805c9
feat: add search endpoint - linting
rkettelerij Dec 10, 2024
6806f81
feat: add search endpoint - refactor magic strings to constants + spl…
rkettelerij Dec 11, 2024
5b4fefc
feat: add search endpoint - use prepared statement for query term
rkettelerij Dec 11, 2024
06879d2
feat: add search endpoint - search in specific collection
rkettelerij Dec 11, 2024
b98f265
feat: add search endpoint - make collections parameter(s) required
rkettelerij Dec 12, 2024
2c48234
feat: add search endpoint - remove log
rkettelerij Dec 12, 2024
5b3315c
feat: add search endpoint - remove log
rkettelerij Dec 12, 2024
95ebdd3
feat: add search endpoint - move funcs in line with GoKoala
rkettelerij Dec 12, 2024
d8311ca
feat: add search endpoint - move consts to url.go
rkettelerij Dec 12, 2024
876f778
feat: add search endpoint - require collection version in requests
rkettelerij Dec 13, 2024
dcf0d5c
feat: add search endpoint - refactoring + add extra tst with differen…
rkettelerij Dec 13, 2024
dbe21fe
feat: add search endpoint - add order by in subquery + naming
rkettelerij Dec 16, 2024
aa58e77
Merge branch 'master' into search-suggest-endpoint
rkettelerij Dec 16, 2024
c2572e0
feat: add search endpoint - merge master
rkettelerij Dec 16, 2024
1cdb9ea
feat: add search endpoint - fix test
rkettelerij Dec 16, 2024
1ebd5c8
feat: add search endpoint - use collection_id + collection_version as…
rkettelerij Dec 18, 2024
00e0399
feat: add search endpoint - fix test
rkettelerij Dec 18, 2024
f36887e
feat: add search endpoint - fix test
rkettelerij Dec 19, 2024
8be5610
feat: add search endpoint - fix tests, multiple changes:
rkettelerij Dec 19, 2024
d6d2f01
feat: add search endpoint - add OpenAPI spec
rkettelerij Dec 20, 2024
71fa65e
feat: add search endpoint - add OpenAPI spec, with all params
rkettelerij Dec 23, 2024
5724870
feat: add search endpoint - remove e2e test for search, already cover…
rkettelerij Dec 23, 2024
941c4c3
feat: add search endpoint - add OpenAPI request validation
rkettelerij Dec 23, 2024
449e581
feat: add search endpoint - formatting
rkettelerij Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading