The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/searchV2/ngram_test.go

59 lines
1.4 KiB

package searchV2
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func Test_punctuationCharFilter_Filter(t1 *testing.T) {
type args struct {
input []byte
}
tests := []struct {
name string
args args
want []byte
}{
{
name: "1",
args: args{
input: []byte("x-Rays"),
},
want: []byte("x Rays"),
},
{
name: "2",
args: args{
input: []byte("x.Rays"),
},
want: []byte("x Rays"),
},
{
name: "3",
args: args{
input: []byte("[x,Rays]"),
},
want: []byte(" x Rays "),
},
}
for _, tt := range tests {
t1.Run(tt.name, func(t1 *testing.T) {
t := &punctuationCharFilter{}
if got := t.Filter(tt.args.input); !reflect.DeepEqual(got, tt.want) {
t1.Errorf("Filter() = %v, want %v", string(got), string(tt.want))
}
})
}
}
func TestNgramIndexAnalyzer(t *testing.T) {
stream := ngramIndexAnalyzer.Analyze([]byte("x-rays.and.xRays, and НемногоКириллицы"))
expectedTerms := []string{"x", "r", "ra", "ray", "rays", "a", "an", "and", "x", "r", "ra", "ray", "rays", "a", "an", "and", "н", "не", "нем", "немн", "немно", "немног", "немного", "к", "ки", "кир", "кири", "кирил", "кирилл", "кирилли"}
var actualTerms []string
for _, t := range stream {
actualTerms = append(actualTerms, string(t.Term))
}
require.Equal(t, expectedTerms, actualTerms)
}