Skip to content

Commit

Permalink
Add support for pipeline analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Paterson committed May 24, 2024
1 parent 5e50ad4 commit e7c1446
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions impls.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,28 @@ func (i SkiplistIndex) Migrate(ctx context.Context, db driver.Database, _ map[st
}
}

func (i PipelineAnalyzer) Migrate(ctx context.Context, db driver.Database, _ map[string]interface{}) error {
switch i.Action {
case DELETE:
a, err := db.Analyzer(ctx, i.Name)
if (e(err)) {
return errors.Wrapf(err, "Error removing analyzer %s", i.Name)
}
err = a.Remove(ctx, true)
return errors.Wrapf(err, "Failed %s", i.Action)
case CREATE:
_, _, err := db.EnsureAnalyzer(ctx, driver.ArangoSearchAnalyzerDefinition{
Name: i.Name,
Type: "pipeline",
Properties: i.Properties,
Features: i.Features,
})
return errors.Wrapf(err, "Failed %s", i.Action)
default:
return errors.Errorf("Unknown action %s", i.Action)
}
}

func (a AQL) Migrate(ctx context.Context, db driver.Database, extras map[string]interface{}) error {
escaped := make(map[string]interface{})
for k, v := range a.BindVars {
Expand Down
Binary file added main
Binary file not shown.
8 changes: 8 additions & 0 deletions migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var persistentidx = regexp.MustCompile(`^type:\spersistentindex`)
var ttlidx = regexp.MustCompile(`^type:\sttlindex`)
var skipidx = regexp.MustCompile(`^type:\sskiplistindex`)
var view = regexp.MustCompile(`^type:\sview`)
var pipeline = regexp.MustCompile(`type:\spipeline`)

// User the data used to update a user account
type User struct {
Expand Down Expand Up @@ -250,6 +251,12 @@ type SearchElementProperties struct {
TrackListPositions *bool `yaml:"trackListPositions,omitempty"`
}

type PipelineAnalyzer struct {
Operation `yaml:",inline"`
Properties driver.ArangoSearchAnalyzerProperties `yaml:"properties,omitempty"`
Features []driver.ArangoSearchAnalyzerFeature `yaml:"features,omitempty"`
}

var validVersion = regexp.MustCompile(`^\d*(\.\d*)*?$`)

// Pairs migrations together.
Expand Down Expand Up @@ -398,6 +405,7 @@ func pickT(contents []byte) (Migration, error) {
return new(SkiplistIndex), nil
case view.MatchString(s):
return new(SearchView), nil
case pipeline.MatchString(s):return new(PipelineAnalyzer), nil
default:
return nil, errors.New("Can't determine YAML type")
}
Expand Down
17 changes: 17 additions & 0 deletions testdata/complete/21.migration
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type: pipeline
action: create
name: testPipelineAnalyzer
properties:
pipeline:
- type: "norm"
properties:
locale: "en.utf-8"
accent: true
case: "lower"
- type: "delimiter"
properties:
delimiter: " "
features:
- position
- norm
- frequency

0 comments on commit e7c1446

Please sign in to comment.