refactor registry package and bleve_registry utility
This commit is contained in:
parent
9e78643bad
commit
22911888c4
|
@ -60,3 +60,19 @@ func (c AnalyzerCache) DefineAnalyzer(name string, typ string, config map[string
|
|||
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
|
||||
}
|
||||
|
|
|
@ -29,3 +29,19 @@ 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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c CharFilterCache) DefineCharFilter(name string, typ string, config map[st
|
|||
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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c DateTimeParserCache) DefineDateTimeParser(name string, typ string, confi
|
|||
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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c FragmentFormatterCache) DefineFragmentFormatter(name string, typ string,
|
|||
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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c FragmenterCache) DefineFragmenter(name string, typ string, config map[st
|
|||
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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c HighlighterCache) DefineHighlighter(name string, typ string, config map[
|
|||
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
|
||||
}
|
||||
|
|
|
@ -175,126 +175,3 @@ func (c *Cache) DefineHighlighter(name string, config map[string]interface{}) (h
|
|||
}
|
||||
return c.Highlighters.DefineHighlighter(name, typ, config, c)
|
||||
}
|
||||
|
||||
func PrintRegistry() {
|
||||
sorted := make(sort.StringSlice, 0, len(charFilters))
|
||||
for name := range charFilters {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Char Filters:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(tokenizers))
|
||||
for name := range tokenizers {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Tokenizers:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(tokenMaps))
|
||||
for name := range tokenMaps {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Token Maps:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(tokenFilters))
|
||||
for name := range tokenFilters {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Token Filters:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(analyzers))
|
||||
for name := range analyzers {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Analyzers:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(dateTimeParsers))
|
||||
for name := range dateTimeParsers {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("DateTime Parsers:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(stores))
|
||||
for name := range stores {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("KV Stores:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(byteArrayConverters))
|
||||
for name := range byteArrayConverters {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Byte Array Converters:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(fragmentFormatters))
|
||||
for name := range fragmentFormatters {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Fragment Formatters:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(fragmenters))
|
||||
for name := range fragmenters {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Fragmenters:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
sorted = make(sort.StringSlice, 0, len(highlighters))
|
||||
for name := range highlighters {
|
||||
sorted = append(sorted, name)
|
||||
}
|
||||
sorted.Sort()
|
||||
fmt.Printf("Highlighters:\n")
|
||||
for _, name := range sorted {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
|
|
@ -29,3 +29,18 @@ 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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c TokenFilterCache) DefineTokenFilter(name string, typ string, config map[
|
|||
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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c TokenMapCache) DefineTokenMap(name string, typ string, config map[string
|
|||
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
|
||||
}
|
||||
|
|
|
@ -60,3 +60,19 @@ func (c TokenizerCache) DefineTokenizer(name string, typ string, config map[stri
|
|||
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
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
_ "github.com/blevesearch/bleve"
|
||||
"github.com/blevesearch/bleve/registry"
|
||||
|
@ -18,5 +19,64 @@ import (
|
|||
|
||||
func main() {
|
||||
fmt.Printf("Bleve Registry:\n")
|
||||
registry.PrintRegistry()
|
||||
printRegistry()
|
||||
}
|
||||
|
||||
func printRegistry() {
|
||||
types, instances := registry.CharFilterTypesAndInstances()
|
||||
printType("Char Filter", types, instances)
|
||||
|
||||
types, instances = registry.TokenizerTypesAndInstances()
|
||||
printType("Tokenizer", types, instances)
|
||||
|
||||
types, instances = registry.TokenMapTypesAndInstances()
|
||||
printType("Token Map", types, instances)
|
||||
|
||||
types, instances = registry.TokenFilterTypesAndInstances()
|
||||
printType("Token Filter", types, instances)
|
||||
|
||||
types, instances = registry.AnalyzerTypesAndInstances()
|
||||
printType("Analyzer", types, instances)
|
||||
|
||||
types, instances = registry.DateTimeParserTypesAndInstances()
|
||||
printType("Date Time Parser", types, instances)
|
||||
|
||||
types, instances = registry.KVStoreTypesAndInstances()
|
||||
printType("KV Store", types, instances)
|
||||
|
||||
types, instances = registry.ByteArrayConverterTypesAndInstances()
|
||||
printType("ByteArrayConverter", types, instances)
|
||||
|
||||
types, instances = registry.FragmentFormatterTypesAndInstances()
|
||||
printType("Fragment Formatter", types, instances)
|
||||
|
||||
types, instances = registry.FragmenterTypesAndInstances()
|
||||
printType("Fragmenter", types, instances)
|
||||
|
||||
types, instances = registry.HighlighterTypesAndInstances()
|
||||
printType("Highlighter", types, instances)
|
||||
}
|
||||
|
||||
func sortStrings(in []string) []string {
|
||||
sortedStrings := make(sort.StringSlice, 0, len(in))
|
||||
for _, str := range in {
|
||||
sortedStrings = append(sortedStrings, str)
|
||||
}
|
||||
sortedStrings.Sort()
|
||||
return sortedStrings
|
||||
}
|
||||
|
||||
func printType(label string, types, instances []string) {
|
||||
sortedTypes := sortStrings(types)
|
||||
sortedInstances := sortStrings(instances)
|
||||
fmt.Printf(label + " Types:\n")
|
||||
for _, name := range sortedTypes {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Printf(label + " Instances:\n")
|
||||
for _, name := range sortedInstances {
|
||||
fmt.Printf("\t%s\n", name)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue