We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f0b19d commit 4dd25ebCopy full SHA for 4dd25eb
4 files changed
fuzzymatcher/data_getter_sqlite.py
@@ -177,17 +177,29 @@ def _tokens_to_matches(self, tokens, misspelling = False):
177
"""
178
179
# This fails if the special tokens 'and' or 'or' are in fts string! See issue 35!
180
- tokens_to_remove = ["AND", "OR"]
181
- tokens = [t for t in tokens if t not in tokens_to_remove]
+ tokens_to_escape = ["AND", "OR", "NEAR"]
+
182
+ def escape_token(t):
183
+ # return t
184
+ if t in tokens_to_escape:
185
+ return '"' + t + '"'
186
+ else:
187
+ return t
188
189
190
+ tokens = [escape_token(t) for t in tokens]
191
192
fts_string = " ".join(tokens)
193
194
195
if misspelling:
196
table_name = "_concat_all_alternatives"
197
else:
198
table_name = "_concat_all"
199
200
sql = get_records_sql.format(table_name, fts_string, self.return_records_limit)
201
202
203
cur = self.con.cursor()
204
cur.execute(sql)
205
results = cur.fetchall()
tests/data/left_token_escape.csv
@@ -0,0 +1,5 @@
1
+id,fname,mname,lname,dob,another_field
2
+1,or,or and,and,20/05/1980,other data
3
+2,or,or,or smith or,15/06/1990,more data
4
+3,near,and,near,20/05/1960,another thing
5
tests/data/right_token_escape.csv
@@ -0,0 +1,4 @@
+id,name,middlename,surname,date,other
+1,or,or,or smith or,15/06/1990,more data
+2,near,and,near,20/05/1960,another thing
+3,or,or and,and,20/05/1980,other data
tests/test_misc.py
@@ -17,4 +17,31 @@ def test_nulls_no_errors(self):
17
18
on = ["first_name", "surname", "dob", "city"]
19
20
- flj = link_table(df_left, df_right, on, on)
+ flj = link_table(df_left, df_right, on, on)
21
22
23
+class TestNulls(unittest.TestCase):
24
+ """
25
+ Test what happens when the user provides input data with
26
+ fts4 match expression keyworks like AND, OR, NEAR
27
28
29
+ def test_nulls_no_errors(self):
30
31
32
33
34
35
+ df_left = pd.read_csv("tests/data/left_token_escape.csv")
36
+ df_right = pd.read_csv("tests/data/right_token_escape.csv")
37
38
+ # Columns to match on from df_left
39
+ left_on = ["fname", "mname", "lname"]
40
41
+ # Columns to match on from df_right
42
+ right_on = ["name", "middlename", "surname"]
43
44
+ on = ["first_name", "surname", ]
45
46
+ flj = link_table(df_left, df_right, left_on, right_on,
47
+ left_id_col="id", right_id_col="id")
0 commit comments