Skip to content

Commit abeee2c

Browse files
committed
MB-56946: Introduce AnalyzerV2 and Runtime registry
+ Introduce new analyzer interface (AnalyzerV2) capable of: + Generating values other than tokenStream, like embedding vectors + Error can be returned during the analysis + Update the analyzers registry to allow runtime registration/removal (*) Note on Backward compatibility - Old Analyzers are all wrapped under AnalyzerAdapter to ensure backward compatibility. - Test cases which register analyzer in the cache and call the Analyze method must be updated to deal with error returned by it (Refer the test cases updated in the PR)
1 parent e9c45ff commit abeee2c

42 files changed

Lines changed: 292 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

analysis/benchmark_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ func BenchmarkAnalysis(b *testing.B) {
3232
b.Fatal(err)
3333
}
3434

35-
ts := analyzer.Analyze(bleveWikiArticle)
35+
ts, err := analysis.AnalyzeForTokens(analyzer, bleveWikiArticle)
36+
if err != nil {
37+
b.Fatalf("error analyzing text: %v", err)
38+
}
3639
freqs := analysis.TokenFrequency(ts, nil, index.IncludeTermVectors)
3740
if len(freqs) != 511 {
3841
b.Errorf("expected %d freqs, got %d", 511, len(freqs))

analysis/lang/ar/analyzer_ar_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ func TestArabicAnalyzer(t *testing.T) {
175175
t.Fatal(err)
176176
}
177177
for _, test := range tests {
178-
actual := analyzer.Analyze(test.input)
178+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
179+
if err != nil {
180+
t.Fatalf("error analyzing input: %v", err)
181+
}
179182
if !reflect.DeepEqual(actual, test.output) {
180183
t.Errorf("expected %v, got %v", test.output, actual)
181184
t.Errorf("expected % x, got % x", test.output[0].Term, actual[0].Term)

analysis/lang/cjk/analyzer_cjk_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ func TestCJKAnalyzer(t *testing.T) {
617617
if err != nil {
618618
t.Fatal(err)
619619
}
620-
actual := analyzer.Analyze(test.input)
620+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
621+
if err != nil {
622+
t.Fatalf("error analyzing input: %v", err)
623+
}
621624
if !reflect.DeepEqual(actual, test.output) {
622625
t.Errorf("expected %v, got %v", test.output, actual)
623626
}

analysis/lang/ckb/analyzer_ckb_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ func TestSoraniAnalyzer(t *testing.T) {
6969
t.Fatal(err)
7070
}
7171
for _, test := range tests {
72-
actual := analyzer.Analyze(test.input)
72+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
73+
if err != nil {
74+
t.Fatalf("error analyzing input: %v", err)
75+
}
7376
if !reflect.DeepEqual(actual, test.output) {
7477
t.Errorf("expected %v, got %v", test.output, actual)
7578
}

analysis/lang/ckb/sorani_stemmer_filter_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestSoraniStemmerFilter(t *testing.T) {
2626

2727
// in order to match the lucene tests
2828
// we will test with an analyzer, not just the stemmer
29-
analyzer := analysis.DefaultAnalyzer{
29+
analyzer := &analysis.DefaultAnalyzer{
3030
Tokenizer: single.NewSingleTokenTokenizer(),
3131
TokenFilters: []analysis.TokenFilter{
3232
NewSoraniNormalizeFilter(),
@@ -283,7 +283,11 @@ func TestSoraniStemmerFilter(t *testing.T) {
283283
}
284284

285285
for _, test := range tests {
286-
actual := analyzer.Analyze(test.input)
286+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
287+
if err != nil {
288+
t.Errorf("error analyzing input: %v", err)
289+
}
290+
287291
if !reflect.DeepEqual(actual, test.output) {
288292
t.Errorf("for input %s(% x)", test.input, test.input)
289293
t.Errorf("\texpected:")

analysis/lang/da/analyzer_da_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ func TestDanishAnalyzer(t *testing.T) {
6363
t.Fatal(err)
6464
}
6565
for _, test := range tests {
66-
actual := analyzer.Analyze(test.input)
66+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
67+
if err != nil {
68+
t.Fatalf("error analyzing input: %v", err)
69+
}
6770
if !reflect.DeepEqual(actual, test.output) {
6871
t.Errorf("expected %v, got %v", test.output, actual)
6972
}

analysis/lang/de/analyzer_de_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ func TestGermanAnalyzer(t *testing.T) {
147147
t.Fatal(err)
148148
}
149149
for _, test := range tests {
150-
actual := analyzer.Analyze(test.input)
150+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
151+
if err != nil {
152+
t.Fatalf("error analyzing input: %v", err)
153+
}
151154
if !reflect.DeepEqual(actual, test.output) {
152155
t.Errorf("expected %v, got %v", test.output, actual)
153156
}

analysis/lang/en/analyzer_en_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ func TestEnglishAnalyzer(t *testing.T) {
9797
t.Fatal(err)
9898
}
9999
for _, test := range tests {
100-
actual := analyzer.Analyze(test.input)
100+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
101+
if err != nil {
102+
t.Fatalf("error analyzing input: %v", err)
103+
}
101104
if !reflect.DeepEqual(actual, test.output) {
102105
t.Errorf("expected %v, got %v", test.output, actual)
103106
}

analysis/lang/es/analyzer_es_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ func TestSpanishAnalyzer(t *testing.T) {
114114
t.Fatal(err)
115115
}
116116
for _, test := range tests {
117-
actual := analyzer.Analyze(test.input)
117+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
118+
if err != nil {
119+
t.Fatalf("error analyzing input: %v", err)
120+
}
118121
if !reflect.DeepEqual(actual, test.output) {
119122
t.Errorf("expected %v, got %v", test.output, actual)
120123
}

analysis/lang/fa/analyzer_fa_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ func TestPersianAnalyzerVerbs(t *testing.T) {
305305
t.Fatal(err)
306306
}
307307
for _, test := range tests {
308-
actual := analyzer.Analyze(test.input)
308+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
309+
if err != nil {
310+
t.Fatalf("error analyzing input: %v", err)
311+
}
309312
if len(actual) != len(test.output) {
310313
t.Fatalf("expected length: %d, got %d", len(test.output), len(actual))
311314
}
@@ -600,7 +603,10 @@ func TestPersianAnalyzerVerbsDefective(t *testing.T) {
600603
t.Fatal(err)
601604
}
602605
for _, test := range tests {
603-
actual := analyzer.Analyze(test.input)
606+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
607+
if err != nil {
608+
t.Fatalf("error analyzing input: %v", err)
609+
}
604610
if len(actual) != len(test.output) {
605611
t.Fatalf("expected length: %d, got %d", len(test.output), len(actual))
606612
}
@@ -671,7 +677,10 @@ func TestPersianAnalyzerOthers(t *testing.T) {
671677
t.Fatal(err)
672678
}
673679
for _, test := range tests {
674-
actual := analyzer.Analyze(test.input)
680+
actual, err := analysis.AnalyzeForTokens(analyzer, test.input)
681+
if err != nil {
682+
t.Fatalf("error analyzing input: %v", err)
683+
}
675684
if len(actual) != len(test.output) {
676685
t.Fatalf("expected length: %d, got %d", len(test.output), len(actual))
677686
}

0 commit comments

Comments
 (0)