Switch from Godep to go vendoring

This commit is contained in:
Ken-Håvard Lieng 2016-03-01 01:51:26 +01:00
parent 6b37713bc0
commit cd317761c5
1504 changed files with 263076 additions and 34441 deletions

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterAnalyzer(name string, constructor AnalyzerConstructor) {
_, exists := analyzers[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate analyzer named '%s'", name))
}
analyzers[name] = constructor
}
type AnalyzerConstructor func(config map[string]interface{}, cache *Cache) (*analysis.Analyzer, error)
type AnalyzerRegistry map[string]AnalyzerConstructor
type AnalyzerCache map[string]*analysis.Analyzer
func (c AnalyzerCache) AnalyzerNamed(name string, cache *Cache) (*analysis.Analyzer, error) {
analyzer, cached := c[name]
if cached {
return analyzer, nil
}
analyzerConstructor, registered := analyzers[name]
if !registered {
return nil, fmt.Errorf("no analyzer with name or type '%s' registered", name)
}
analyzer, err := analyzerConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building analyzer: %v", err)
}
c[name] = analyzer
return analyzer, nil
}
func (c AnalyzerCache) DefineAnalyzer(name string, typ string, config map[string]interface{}, cache *Cache) (*analysis.Analyzer, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("analyzer named '%s' already defined", name)
}
analyzerConstructor, registered := analyzers[typ]
if !registered {
return nil, fmt.Errorf("no analyzer type '%s' registered", typ)
}
analyzer, err := analyzerConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building analyzer: %v", err)
}
c[name] = analyzer
return analyzer, nil
}
func AnalyzerTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range analyzers {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,47 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterByteArrayConverter(name string, constructor ByteArrayConverterConstructor) {
_, exists := byteArrayConverters[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate byte array converter named '%s'", name))
}
byteArrayConverters[name] = constructor
}
type ByteArrayConverterConstructor func(config map[string]interface{}, cache *Cache) (analysis.ByteArrayConverter, error)
type ByteArrayConverterRegistry map[string]ByteArrayConverterConstructor
func ByteArrayConverterByName(name string) ByteArrayConverterConstructor {
return byteArrayConverters[name]
}
func ByteArrayConverterTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range byteArrayConverters {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterCharFilter(name string, constructor CharFilterConstructor) {
_, exists := charFilters[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate char filter named '%s'", name))
}
charFilters[name] = constructor
}
type CharFilterConstructor func(config map[string]interface{}, cache *Cache) (analysis.CharFilter, error)
type CharFilterRegistry map[string]CharFilterConstructor
type CharFilterCache map[string]analysis.CharFilter
func (c CharFilterCache) CharFilterNamed(name string, cache *Cache) (analysis.CharFilter, error) {
charFilter, cached := c[name]
if cached {
return charFilter, nil
}
charFilterConstructor, registered := charFilters[name]
if !registered {
return nil, fmt.Errorf("no char filter with name or type '%s' registered", name)
}
charFilter, err := charFilterConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building char filter: %v", err)
}
c[name] = charFilter
return charFilter, nil
}
func (c CharFilterCache) DefineCharFilter(name string, typ string, config map[string]interface{}, cache *Cache) (analysis.CharFilter, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("char filter named '%s' already defined", name)
}
charFilterConstructor, registered := charFilters[typ]
if !registered {
return nil, fmt.Errorf("no char filter type '%s' registered", typ)
}
charFilter, err := charFilterConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building char filter: %v", err)
}
c[name] = charFilter
return charFilter, nil
}
func CharFilterTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range charFilters {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterDateTimeParser(name string, constructor DateTimeParserConstructor) {
_, exists := dateTimeParsers[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate date time parser named '%s'", name))
}
dateTimeParsers[name] = constructor
}
type DateTimeParserConstructor func(config map[string]interface{}, cache *Cache) (analysis.DateTimeParser, error)
type DateTimeParserRegistry map[string]DateTimeParserConstructor
type DateTimeParserCache map[string]analysis.DateTimeParser
func (c DateTimeParserCache) DateTimeParserNamed(name string, cache *Cache) (analysis.DateTimeParser, error) {
dateTimeParser, cached := c[name]
if cached {
return dateTimeParser, nil
}
dateTimeParserConstructor, registered := dateTimeParsers[name]
if !registered {
return nil, fmt.Errorf("no date time parser with name or type '%s' registered", name)
}
dateTimeParser, err := dateTimeParserConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building date time parse: %v", err)
}
c[name] = dateTimeParser
return dateTimeParser, nil
}
func (c DateTimeParserCache) DefineDateTimeParser(name string, typ string, config map[string]interface{}, cache *Cache) (analysis.DateTimeParser, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("date time parser named '%s' already defined", name)
}
dateTimeParserConstructor, registered := dateTimeParsers[typ]
if !registered {
return nil, fmt.Errorf("no date time parser type '%s' registered", typ)
}
dateTimeParser, err := dateTimeParserConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building date time parser: %v", err)
}
c[name] = dateTimeParser
return dateTimeParser, nil
}
func DateTimeParserTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range dateTimeParsers {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/search/highlight"
)
func RegisterFragmentFormatter(name string, constructor FragmentFormatterConstructor) {
_, exists := fragmentFormatters[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate fragment formatter named '%s'", name))
}
fragmentFormatters[name] = constructor
}
type FragmentFormatterConstructor func(config map[string]interface{}, cache *Cache) (highlight.FragmentFormatter, error)
type FragmentFormatterRegistry map[string]FragmentFormatterConstructor
type FragmentFormatterCache map[string]highlight.FragmentFormatter
func (c FragmentFormatterCache) FragmentFormatterNamed(name string, cache *Cache) (highlight.FragmentFormatter, error) {
fragmentFormatter, cached := c[name]
if cached {
return fragmentFormatter, nil
}
fragmentFormatterConstructor, registered := fragmentFormatters[name]
if !registered {
return nil, fmt.Errorf("no fragment formatter with name or type '%s' registered", name)
}
fragmentFormatter, err := fragmentFormatterConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building fragment formatter: %v", err)
}
c[name] = fragmentFormatter
return fragmentFormatter, nil
}
func (c FragmentFormatterCache) DefineFragmentFormatter(name string, typ string, config map[string]interface{}, cache *Cache) (highlight.FragmentFormatter, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("fragment formatter named '%s' already defined", name)
}
fragmentFormatterConstructor, registered := fragmentFormatters[typ]
if !registered {
return nil, fmt.Errorf("no fragment formatter type '%s' registered", typ)
}
fragmentFormatter, err := fragmentFormatterConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building fragment formatter: %v", err)
}
c[name] = fragmentFormatter
return fragmentFormatter, nil
}
func FragmentFormatterTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range fragmentFormatters {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/search/highlight"
)
func RegisterFragmenter(name string, constructor FragmenterConstructor) {
_, exists := fragmenters[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate fragmenter named '%s'", name))
}
fragmenters[name] = constructor
}
type FragmenterConstructor func(config map[string]interface{}, cache *Cache) (highlight.Fragmenter, error)
type FragmenterRegistry map[string]FragmenterConstructor
type FragmenterCache map[string]highlight.Fragmenter
func (c FragmenterCache) FragmenterNamed(name string, cache *Cache) (highlight.Fragmenter, error) {
fragmenter, cached := c[name]
if cached {
return fragmenter, nil
}
fragmenterConstructor, registered := fragmenters[name]
if !registered {
return nil, fmt.Errorf("no fragmenter with name or type '%s' registered", name)
}
fragmenter, err := fragmenterConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building fragmenter: %v", err)
}
c[name] = fragmenter
return fragmenter, nil
}
func (c FragmenterCache) DefineFragmenter(name string, typ string, config map[string]interface{}, cache *Cache) (highlight.Fragmenter, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("fragmenter named '%s' already defined", name)
}
fragmenterConstructor, registered := fragmenters[typ]
if !registered {
return nil, fmt.Errorf("no fragmenter type '%s' registered", typ)
}
fragmenter, err := fragmenterConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building fragmenter: %v", err)
}
c[name] = fragmenter
return fragmenter, nil
}
func FragmenterTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range fragmenters {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/search/highlight"
)
func RegisterHighlighter(name string, constructor HighlighterConstructor) {
_, exists := highlighters[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate highlighter named '%s'", name))
}
highlighters[name] = constructor
}
type HighlighterConstructor func(config map[string]interface{}, cache *Cache) (highlight.Highlighter, error)
type HighlighterRegistry map[string]HighlighterConstructor
type HighlighterCache map[string]highlight.Highlighter
func (c HighlighterCache) HighlighterNamed(name string, cache *Cache) (highlight.Highlighter, error) {
highlighter, cached := c[name]
if cached {
return highlighter, nil
}
highlighterConstructor, registered := highlighters[name]
if !registered {
return nil, fmt.Errorf("no highlighter with name or type '%s' registered", name)
}
highlighter, err := highlighterConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building highlighter: %v", err)
}
c[name] = highlighter
return highlighter, nil
}
func (c HighlighterCache) DefineHighlighter(name string, typ string, config map[string]interface{}, cache *Cache) (highlight.Highlighter, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("highlighter named '%s' already defined", name)
}
highlighterConstructor, registered := highlighters[typ]
if !registered {
return nil, fmt.Errorf("no highlighter type '%s' registered", typ)
}
highlighter, err := highlighterConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building highlighter: %v", err)
}
c[name] = highlighter
return highlighter, nil
}
func HighlighterTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range highlighters {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,176 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
"github.com/blevesearch/bleve/search/highlight"
)
var stores = make(KVStoreRegistry, 0)
var byteArrayConverters = make(ByteArrayConverterRegistry, 0)
// highlight
var fragmentFormatters = make(FragmentFormatterRegistry, 0)
var fragmenters = make(FragmenterRegistry, 0)
var highlighters = make(HighlighterRegistry, 0)
// analysis
var charFilters = make(CharFilterRegistry, 0)
var tokenizers = make(TokenizerRegistry, 0)
var tokenMaps = make(TokenMapRegistry, 0)
var tokenFilters = make(TokenFilterRegistry, 0)
var analyzers = make(AnalyzerRegistry, 0)
var dateTimeParsers = make(DateTimeParserRegistry, 0)
type Cache struct {
CharFilters CharFilterCache
Tokenizers TokenizerCache
TokenMaps TokenMapCache
TokenFilters TokenFilterCache
Analyzers AnalyzerCache
DateTimeParsers DateTimeParserCache
FragmentFormatters FragmentFormatterCache
Fragmenters FragmenterCache
Highlighters HighlighterCache
}
func NewCache() *Cache {
return &Cache{
CharFilters: make(CharFilterCache, 0),
Tokenizers: make(TokenizerCache, 0),
TokenMaps: make(TokenMapCache, 0),
TokenFilters: make(TokenFilterCache, 0),
Analyzers: make(AnalyzerCache, 0),
DateTimeParsers: make(DateTimeParserCache, 0),
FragmentFormatters: make(FragmentFormatterCache, 0),
Fragmenters: make(FragmenterCache, 0),
Highlighters: make(HighlighterCache, 0),
}
}
func typeFromConfig(config map[string]interface{}) (string, error) {
typ, ok := config["type"].(string)
if ok {
return typ, nil
}
return "", fmt.Errorf("unable to determine type")
}
func (c *Cache) CharFilterNamed(name string) (analysis.CharFilter, error) {
return c.CharFilters.CharFilterNamed(name, c)
}
func (c *Cache) DefineCharFilter(name string, config map[string]interface{}) (analysis.CharFilter, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.CharFilters.DefineCharFilter(name, typ, config, c)
}
func (c *Cache) TokenizerNamed(name string) (analysis.Tokenizer, error) {
return c.Tokenizers.TokenizerNamed(name, c)
}
func (c *Cache) DefineTokenizer(name string, config map[string]interface{}) (analysis.Tokenizer, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.Tokenizers.DefineTokenizer(name, typ, config, c)
}
func (c *Cache) TokenMapNamed(name string) (analysis.TokenMap, error) {
return c.TokenMaps.TokenMapNamed(name, c)
}
func (c *Cache) DefineTokenMap(name string, config map[string]interface{}) (analysis.TokenMap, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.TokenMaps.DefineTokenMap(name, typ, config, c)
}
func (c *Cache) TokenFilterNamed(name string) (analysis.TokenFilter, error) {
return c.TokenFilters.TokenFilterNamed(name, c)
}
func (c *Cache) DefineTokenFilter(name string, config map[string]interface{}) (analysis.TokenFilter, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.TokenFilters.DefineTokenFilter(name, typ, config, c)
}
func (c *Cache) AnalyzerNamed(name string) (*analysis.Analyzer, error) {
return c.Analyzers.AnalyzerNamed(name, c)
}
func (c *Cache) DefineAnalyzer(name string, config map[string]interface{}) (*analysis.Analyzer, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.Analyzers.DefineAnalyzer(name, typ, config, c)
}
func (c *Cache) DateTimeParserNamed(name string) (analysis.DateTimeParser, error) {
return c.DateTimeParsers.DateTimeParserNamed(name, c)
}
func (c *Cache) DefineDateTimeParser(name string, config map[string]interface{}) (analysis.DateTimeParser, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.DateTimeParsers.DefineDateTimeParser(name, typ, config, c)
}
func (c *Cache) FragmentFormatterNamed(name string) (highlight.FragmentFormatter, error) {
return c.FragmentFormatters.FragmentFormatterNamed(name, c)
}
func (c *Cache) DefineFragmentFormatter(name string, config map[string]interface{}) (highlight.FragmentFormatter, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.FragmentFormatters.DefineFragmentFormatter(name, typ, config, c)
}
func (c *Cache) FragmenterNamed(name string) (highlight.Fragmenter, error) {
return c.Fragmenters.FragmenterNamed(name, c)
}
func (c *Cache) DefineFragmenter(name string, config map[string]interface{}) (highlight.Fragmenter, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.Fragmenters.DefineFragmenter(name, typ, config, c)
}
func (c *Cache) HighlighterNamed(name string) (highlight.Highlighter, error) {
return c.Highlighters.HighlighterNamed(name, c)
}
func (c *Cache) DefineHighlighter(name string, config map[string]interface{}) (highlight.Highlighter, error) {
typ, err := typeFromConfig(config)
if err != nil {
return nil, err
}
return c.Highlighters.DefineHighlighter(name, typ, config, c)
}

46
vendor/github.com/blevesearch/bleve/registry/store.go generated vendored Normal file
View file

@ -0,0 +1,46 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/index/store"
)
func RegisterKVStore(name string, constructor KVStoreConstructor) {
_, exists := stores[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate store named '%s'", name))
}
stores[name] = constructor
}
type KVStoreConstructor func(config map[string]interface{}) (store.KVStore, error)
type KVStoreRegistry map[string]KVStoreConstructor
func KVStoreConstructorByName(name string) KVStoreConstructor {
return stores[name]
}
func KVStoreTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range stores {
_, err := cons(emptyConfig)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterTokenFilter(name string, constructor TokenFilterConstructor) {
_, exists := tokenFilters[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate token filter named '%s'", name))
}
tokenFilters[name] = constructor
}
type TokenFilterConstructor func(config map[string]interface{}, cache *Cache) (analysis.TokenFilter, error)
type TokenFilterRegistry map[string]TokenFilterConstructor
type TokenFilterCache map[string]analysis.TokenFilter
func (c TokenFilterCache) TokenFilterNamed(name string, cache *Cache) (analysis.TokenFilter, error) {
tokenFilter, cached := c[name]
if cached {
return tokenFilter, nil
}
tokenFilterConstructor, registered := tokenFilters[name]
if !registered {
return nil, fmt.Errorf("no token filter with name or type '%s' registered", name)
}
tokenFilter, err := tokenFilterConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building token filter: %v", err)
}
c[name] = tokenFilter
return tokenFilter, nil
}
func (c TokenFilterCache) DefineTokenFilter(name string, typ string, config map[string]interface{}, cache *Cache) (analysis.TokenFilter, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("token filter named '%s' already defined", name)
}
tokenFilterConstructor, registered := tokenFilters[typ]
if !registered {
return nil, fmt.Errorf("no token filter type '%s' registered", typ)
}
tokenFilter, err := tokenFilterConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building token filter: %v", err)
}
c[name] = tokenFilter
return tokenFilter, nil
}
func TokenFilterTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range tokenFilters {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterTokenMap(name string, constructor TokenMapConstructor) {
_, exists := tokenMaps[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate token map named '%s'", name))
}
tokenMaps[name] = constructor
}
type TokenMapConstructor func(config map[string]interface{}, cache *Cache) (analysis.TokenMap, error)
type TokenMapRegistry map[string]TokenMapConstructor
type TokenMapCache map[string]analysis.TokenMap
func (c TokenMapCache) TokenMapNamed(name string, cache *Cache) (analysis.TokenMap, error) {
tokenMap, cached := c[name]
if cached {
return tokenMap, nil
}
tokenMapConstructor, registered := tokenMaps[name]
if !registered {
return nil, fmt.Errorf("no token map with name or type '%s' registered", name)
}
tokenMap, err := tokenMapConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building token map: %v", err)
}
c[name] = tokenMap
return tokenMap, nil
}
func (c TokenMapCache) DefineTokenMap(name string, typ string, config map[string]interface{}, cache *Cache) (analysis.TokenMap, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("token map named '%s' already defined", name)
}
tokenMapConstructor, registered := tokenMaps[typ]
if !registered {
return nil, fmt.Errorf("no token map type '%s' registered", typ)
}
tokenMap, err := tokenMapConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building token map: %v", err)
}
c[name] = tokenMap
return tokenMap, nil
}
func TokenMapTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range tokenMaps {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}

View file

@ -0,0 +1,78 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package registry
import (
"fmt"
"github.com/blevesearch/bleve/analysis"
)
func RegisterTokenizer(name string, constructor TokenizerConstructor) {
_, exists := tokenizers[name]
if exists {
panic(fmt.Errorf("attempted to register duplicate tokenizer named '%s'", name))
}
tokenizers[name] = constructor
}
type TokenizerConstructor func(config map[string]interface{}, cache *Cache) (analysis.Tokenizer, error)
type TokenizerRegistry map[string]TokenizerConstructor
type TokenizerCache map[string]analysis.Tokenizer
func (c TokenizerCache) TokenizerNamed(name string, cache *Cache) (analysis.Tokenizer, error) {
tokenizer, cached := c[name]
if cached {
return tokenizer, nil
}
tokenizerConstructor, registered := tokenizers[name]
if !registered {
return nil, fmt.Errorf("no tokenizer with name or type '%s' registered", name)
}
tokenizer, err := tokenizerConstructor(nil, cache)
if err != nil {
return nil, fmt.Errorf("error building tokenizer: %v", err)
}
c[name] = tokenizer
return tokenizer, nil
}
func (c TokenizerCache) DefineTokenizer(name string, typ string, config map[string]interface{}, cache *Cache) (analysis.Tokenizer, error) {
_, cached := c[name]
if cached {
return nil, fmt.Errorf("tokenizer named '%s' already defined", name)
}
tokenizerConstructor, registered := tokenizers[typ]
if !registered {
return nil, fmt.Errorf("no tokenizer type '%s' registered", typ)
}
tokenizer, err := tokenizerConstructor(config, cache)
if err != nil {
return nil, fmt.Errorf("error building tokenizer: %v", err)
}
c[name] = tokenizer
return tokenizer, nil
}
func TokenizerTypesAndInstances() ([]string, []string) {
emptyConfig := map[string]interface{}{}
emptyCache := NewCache()
types := make([]string, 0)
instances := make([]string, 0)
for name, cons := range tokenizers {
_, err := cons(emptyConfig, emptyCache)
if err == nil {
instances = append(instances, name)
} else {
types = append(types, name)
}
}
return types, instances
}