Skip to content

Commit 544c12e

Browse files
committed
Added special handling to search tokens beginning with @. Implicitely
double quoting before passing to mysql stops @whatever being mistaken for a fulltext search proximity operator. Resolves #606
1 parent 1ab32c8 commit 544c12e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

handlers/search.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def get(self, base36_id=None):
3737

3838
current_user_obj = self.get_current_user_object()
3939
q = self.get_argument("q", "")
40+
41+
# Take care of an mysql specific case where prepending an @ to a token
42+
# causes a query syntax error. Wrap any token like that in double
43+
# quotes first.
44+
# More info: @distance fulltext search proximity operator
45+
# https://dev.mysql.com/doc/refman/8.4/en/fulltext-boolean.html
46+
q = re.sub(r'(?<!")(\B@[\w\-]+)(?!")', r'"\1"', q)
47+
4048
context = self.get_argument("context", "")
4149
if context:
4250
q = q + " " + context

0 commit comments

Comments
 (0)