-
Notifications
You must be signed in to change notification settings - Fork 26
/
querytranslate.go
66 lines (54 loc) · 1.7 KB
/
querytranslate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package querytranslate
import (
"sync"
"github.com/appbaseio/reactivesearch-api/middleware"
"github.com/appbaseio/reactivesearch-api/plugins"
pluralize "github.com/gertd/go-pluralize"
log "github.com/sirupsen/logrus"
)
const (
logTag = "[querytranslate]"
typeName = "_doc"
)
var (
rsPluralize *pluralize.Client
singleton *QueryTranslate
once sync.Once
)
// QueryTranslate plugin deals with managing query translation.
type QueryTranslate struct {
apiSchema []byte
}
// Instance returns the singleton instance of the plugin. Instance
// should be the only way (both within or outside the package) to fetch
// the instance of the plugin, in order to avoid stateless duplicates.
func Instance() *QueryTranslate {
once.Do(func() {
singleton = &QueryTranslate{}
rsPluralize = pluralize.NewClient()
})
return singleton
}
// Name returns the name of the plugin: [querytranslate]
func (r *QueryTranslate) Name() string {
return logTag
}
// InitFunc initializes the dao, i.e. elasticsearch client, and should be executed
// only once in the lifetime of the plugin.
func (r *QueryTranslate) InitFunc(mw []middleware.Middleware) error {
// Parse the api schema
marshalledSchema, schemaGenerationErr := GetReactiveSearchSchema()
if schemaGenerationErr != nil {
log.Errorln(logTag, ": error while generating schema for RS API body, ", schemaGenerationErr)
return schemaGenerationErr
}
r.apiSchema = marshalledSchema
return r.preprocess(mw)
}
// Routes returns an empty slices since the plugin solely acts as a middleware.
func (r *QueryTranslate) Routes() []plugins.Route {
return r.routes()
}
func (r *QueryTranslate) ESMiddleware() []middleware.Middleware {
return make([]middleware.Middleware, 0)
}