Skip to content

Commit 1080322

Browse files
Merge pull request #3909 from manticoresoftware/test/issue-3853-auto-force-bigrams
Add comprehensive tests for force_bigrams option (issue #3853)
2 parents ff11f11 + cb89b7e commit 1080322

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
––– comment –––
2+
Test for force_bigrams option in CALL AUTOCOMPLETE, CALL SUGGEST, and fuzzy search
3+
Issue: https://github.com/manticoresoftware/manticoresearch/issues/3853
4+
5+
This test verifies that force_bigrams parameter works correctly in three contexts:
6+
1. CALL AUTOCOMPLETE (tests 1-9): autocomplete with bigram-based fuzzy matching
7+
2. CALL SUGGEST (tests 10-15): suggestions with bigram-based fuzzy matching
8+
3. SELECT with OPTION fuzzy=1 (tests 16-21): regular search with fuzzy option
9+
––– block: ../base/start-searchd-with-buddy –––
10+
––– input –––
11+
mysql -P9306 -h0 -e "drop table if exists t"
12+
––– output –––
13+
––– input –––
14+
mysql -P9306 -h0 -e "create table t(f text) min_infix_len='2'"
15+
––– output –––
16+
––– input –––
17+
mysql -P9306 -h0 -e "insert into t values(1,'iphone george planet letter')"
18+
––– output –––
19+
––– comment –––
20+
Test 1: force_bigrams=1 finds transposition errors
21+
––– input –––
22+
mysql -P9306 -h0 -e "call autocomplete('ipohne', 't', 1 as force_bigrams)\G"
23+
––– output –––
24+
*************************** 1. row ***************************
25+
query: iphone
26+
––– comment –––
27+
Test 2: force_bigrams=0 does NOT find transpositions in long words
28+
––– input –––
29+
mysql -P9306 -h0 -e "call autocomplete('ipohne', 't', 0 as force_bigrams)\G"
30+
––– output –––
31+
––– comment –––
32+
Test 3: Transposition with force_bigrams=1
33+
––– input –––
34+
mysql -P9306 -h0 -e "call autocomplete('geroge', 't', 1 as force_bigrams)\G"
35+
––– output –––
36+
*************************** 1. row ***************************
37+
query: george
38+
––– comment –––
39+
Test 4: Same word with force_bigrams=0 - does NOT find transposition
40+
––– input –––
41+
mysql -P9306 -h0 -e "call autocomplete('geroge', 't', 0 as force_bigrams)\G"
42+
––– output –––
43+
––– comment –––
44+
Test 5: 6-char word "planet" (boundary case), force_bigrams=0, expect: found
45+
Note: "lanet" uses bigrams, "planet" uses trigrams, but fuzzy matching still works (edit distance=1)
46+
––– input –––
47+
mysql -P9306 -h0 -e "call autocomplete('lanet', 't', 0 as force_bigrams)\G"
48+
––– output –––
49+
*************************** 1. row ***************************
50+
query: planet
51+
––– comment –––
52+
Test 6: Same word with force_bigrams=1, expect: found (same result as Test 5)
53+
––– input –––
54+
mysql -P9306 -h0 -e "call autocomplete('lanet', 't', 1 as force_bigrams)\G"
55+
––– output –––
56+
*************************** 1. row ***************************
57+
query: planet
58+
––– comment –––
59+
Test 7: Append option with force_bigrams
60+
––– input –––
61+
mysql -P9306 -h0 -e "call autocomplete('geor', 't', 1 as append, 1 as force_bigrams)\G"
62+
––– output –––
63+
*************************** 1. row ***************************
64+
query: george
65+
––– comment –––
66+
Test 8: Prepend option with force_bigrams
67+
––– input –––
68+
mysql -P9306 -h0 -e "call autocomplete('eorge', 't', 1 as prepend, 1 as force_bigrams)\G"
69+
––– output –––
70+
*************************** 1. row ***************************
71+
query: george
72+
––– comment –––
73+
Test 9: Multiple options with force_bigrams
74+
––– input –––
75+
mysql -P9306 -h0 -e "call autocomplete('geor', 't', 1 as fuzziness, 1 as append, 1 as prepend, 1 as force_bigrams)\G"
76+
––– output –––
77+
*************************** 1. row ***************************
78+
query: george
79+
––– comment –––
80+
Test 10: CALL SUGGEST with force_bigrams=1, transposition in 6-char word
81+
––– input –––
82+
mysql -P9306 -h0 -e "call suggest('ipohne', 't', 1 as force_bigrams)\G"
83+
––– output –––
84+
*************************** 1. row ***************************
85+
suggest: iphone
86+
distance: 2
87+
docs: 1
88+
*************************** 2. row ***************************
89+
suggest: planet
90+
distance: 4
91+
docs: 1
92+
––– comment –––
93+
Test 11: CALL SUGGEST with force_bigrams=0, same word, expect: NOT found
94+
––– input –––
95+
mysql -P9306 -h0 -e "call suggest('ipohne', 't', 0 as force_bigrams)\G"
96+
––– output –––
97+
––– comment –––
98+
Test 12: CALL SUGGEST with force_bigrams=1, transposition in "george"
99+
––– input –––
100+
mysql -P9306 -h0 -e "call suggest('geroge', 't', 1 as force_bigrams)\G"
101+
––– output –––
102+
*************************** 1. row ***************************
103+
suggest: george
104+
distance: 2
105+
docs: 1
106+
––– comment –––
107+
Test 13: CALL SUGGEST with force_bigrams=0, same word, expect: NOT found
108+
––– input –––
109+
mysql -P9306 -h0 -e "call suggest('geroge', 't', 0 as force_bigrams)\G"
110+
––– output –––
111+
––– comment –––
112+
Test 14: CALL SUGGEST with force_bigrams=0, "planet" boundary case, expect: found
113+
––– input –––
114+
mysql -P9306 -h0 -e "call suggest('lanet', 't', 0 as force_bigrams)\G"
115+
––– output –––
116+
*************************** 1. row ***************************
117+
suggest: planet
118+
distance: 1
119+
docs: 1
120+
*************************** 2. row ***************************
121+
suggest: letter
122+
distance: 4
123+
docs: 1
124+
––– comment –––
125+
Test 15: CALL SUGGEST with force_bigrams=1, same word, expect: found (same result)
126+
––– input –––
127+
mysql -P9306 -h0 -e "call suggest('lanet', 't', 1 as force_bigrams)\G"
128+
––– output –––
129+
*************************** 1. row ***************************
130+
suggest: planet
131+
distance: 1
132+
docs: 1
133+
*************************** 2. row ***************************
134+
suggest: letter
135+
distance: 4
136+
docs: 1
137+
––– comment –––
138+
Test 16: SELECT with force_bigrams=1, transposition in 6-char word
139+
––– input –––
140+
mysql -P9306 -h0 -e "SELECT * FROM t WHERE MATCH('ipohne') OPTION fuzzy=1, force_bigrams=1"
141+
––– output –––
142+
+------+-----------------------------+
143+
| id | f |
144+
+------+-----------------------------+
145+
| 1 | iphone george planet letter |
146+
+------+-----------------------------+
147+
––– comment –––
148+
Test 17: SELECT with force_bigrams=0, same word, expect: NOT found
149+
––– input –––
150+
mysql -P9306 -h0 -e "SELECT * FROM t WHERE MATCH('ipohne') OPTION fuzzy=1, force_bigrams=0"
151+
––– output –––
152+
––– comment –––
153+
Test 18: SELECT with force_bigrams=1, transposition in "george"
154+
––– input –––
155+
mysql -P9306 -h0 -e "SELECT * FROM t WHERE MATCH('geroge') OPTION fuzzy=1, force_bigrams=1"
156+
––– output –––
157+
+------+-----------------------------+
158+
| id | f |
159+
+------+-----------------------------+
160+
| 1 | iphone george planet letter |
161+
+------+-----------------------------+
162+
––– comment –––
163+
Test 19: SELECT with force_bigrams=0, same word, expect: NOT found
164+
––– input –––
165+
mysql -P9306 -h0 -e "SELECT * FROM t WHERE MATCH('geroge') OPTION fuzzy=1, force_bigrams=0"
166+
––– output –––
167+
––– comment –––
168+
Test 20: SELECT with force_bigrams=0, "planet" boundary case, expect: found
169+
––– input –––
170+
mysql -P9306 -h0 -e "SELECT * FROM t WHERE MATCH('lanet') OPTION fuzzy=1, force_bigrams=0"
171+
––– output –––
172+
+------+-----------------------------+
173+
| id | f |
174+
+------+-----------------------------+
175+
| 1 | iphone george planet letter |
176+
+------+-----------------------------+
177+
––– comment –––
178+
Test 21: SELECT with force_bigrams=1, same word, expect: found (same result)
179+
––– input –––
180+
mysql -P9306 -h0 -e "SELECT * FROM t WHERE MATCH('lanet') OPTION fuzzy=1, force_bigrams=1"
181+
––– output –––
182+
+------+-----------------------------+
183+
| id | f |
184+
+------+-----------------------------+
185+
| 1 | iphone george planet letter |
186+
+------+-----------------------------+
187+
––– input –––
188+
mysql -P9306 -h0 -e "drop table t"
189+
––– output –––

0 commit comments

Comments
 (0)