Skip to content

Commit

Permalink
move Search ETL config to separate struct
Browse files Browse the repository at this point in the history
PDOK-17304
  • Loading branch information
roelarents committed Nov 27, 2024
1 parent 587a490 commit 1e605dd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
20 changes: 12 additions & 8 deletions config/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,24 @@ type Search struct {
// Template that indicates how a search record is displayed. Uses Go text/template syntax to reference fields.
DisplayNameTemplate string `yaml:"displayNameTemplate,omitempty" json:"displayNameTemplate,omitempty" validate:"required"`

// One or more optional templates that make up the autosuggestions. Uses Go text/template syntax to reference fields.
SuggestTemplates []string `yaml:"suggestTemplates,omitempty" json:"suggestTemplates,omitempty"`

// SQLite WHERE clause to filter features when importing/ETL-ing
// (Without the WHERE keyword, only the clause)
// +Optional
ETLFilter string `yaml:"etlFilter,omitempty" json:"etlFilter,omitempty"`

// Version of the collection used to link to search results
Version int `yaml:"version,omitempty" json:"version,omitempty" default:"1"`

// (Links to) the individual OGC API (feature) collections that are searchable in this collection.
// +kubebuilder:validation:MinItems=1
OGCCollections []RelatedOGCAPIFeaturesCollection `yaml:"ogcCollections" json:"ogcCollections" validate:"required,min=1"`

ETL SearchETL `yaml:"etl" json:"etl" validate:"required"`
}

type SearchETL struct {
// One or more optional templates that make up the autosuggestions. Uses Go text/template syntax to reference fields.
SuggestTemplates []string `yaml:"suggestTemplates,omitempty" json:"suggestTemplates,omitempty"`

// SQLite WHERE clause to filter features when importing/ETL-ing
// (Without the WHERE keyword, only the clause)
// +Optional
Filter string `yaml:"filter,omitempty" json:"filter,omitempty"`
}

type RelatedOGCAPIFeaturesCollection struct {
Expand Down
7 changes: 4 additions & 3 deletions internal/engine/testdata/config_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ collections:
- huisletter
- postcode
- woonplaats
suggestTemplates:
- "{{.straatnaam}} {{.huisnummer}} {{.huisletter}} {{.postcode}} {{.woonplaats}}"
- "{{.straatnaam}} {{.huisnummer}}{{.huisletter}} {{.postcode}} {{.woonplaats}}"
etl:
suggestTemplates:
- "{{.straatnaam}} {{.huisnummer}} {{.huisletter}} {{.postcode}} {{.woonplaats}}"
- "{{.straatnaam}} {{.huisnummer}}{{.huisletter}} {{.postcode}} {{.woonplaats}}"
version: 1
links: {} # placeholder
ogcCollections:
Expand Down
2 changes: 1 addition & 1 deletion internal/etl/etl.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ImportFile(cfg *config.Config, searchIndex string, filePath string, table c
// import records in batches depending on page size
offset := 0
for {
sourceRecords, err := source.Extract(table, collection.Search.Fields, collection.Search.ETLFilter, pageSize, offset)
sourceRecords, err := source.Extract(table, collection.Search.Fields, collection.Search.ETL.Filter, pageSize, offset)
if err != nil {
return fmt.Errorf("failed extracting source records: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/etl/etl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestImportGeoPackage(t *testing.T) {
assert.NotNil(t, cfg)
for _, collection := range cfg.Collections {
if collection.Search != nil {
collection.Search.ETLFilter = tt.where
collection.Search.ETL.Filter = tt.where
}
}

Expand Down
7 changes: 4 additions & 3 deletions internal/etl/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ collections:
- component_postaldescriptor
- component_addressareaname
displayNameTemplate: "{{ .component_thoroughfarename }} - {{ .component_addressareaname }}"
suggestTemplates:
- "{{ .component_thoroughfarename }} {{ .component_addressareaname }}"
- "{{ .component_thoroughfarename }}, {{ .component_postaldescriptor }} {{ .component_addressareaname }}"
etl:
suggestTemplates:
- "{{ .component_thoroughfarename }} {{ .component_addressareaname }}"
- "{{ .component_thoroughfarename }}, {{ .component_postaldescriptor }} {{ .component_addressareaname }}"
ogcCollections:
- api: https://example.com/ogc/v1
collection: addresses
Expand Down
4 changes: 2 additions & 2 deletions internal/etl/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (t Transformer) Transform(records []RawRecord, collection config.GeoSpatial
if err != nil {
return nil, err
}
suggestions := make([]string, 0, len(collection.Search.SuggestTemplates))
for _, suggestTemplate := range collection.Search.SuggestTemplates {
suggestions := make([]string, 0, len(collection.Search.ETL.SuggestTemplates))
for _, suggestTemplate := range collection.Search.ETL.SuggestTemplates {
suggestion, err := t.renderTemplate(suggestTemplate, fieldValuesByName)
if err != nil {
return nil, err
Expand Down

0 comments on commit 1e605dd

Please sign in to comment.