diff --git a/openlibrary/solr/query_utils.py b/openlibrary/solr/query_utils.py index 116733bb4cc..82d40d9cede 100644 --- a/openlibrary/solr/query_utils.py +++ b/openlibrary/solr/query_utils.py @@ -131,10 +131,12 @@ def fully_escape_query(query: str) -> str: 'x\\\\:\\\\[A TO Z\\\\}' >>> fully_escape_query('foo AND bar') 'foo and bar' + >>> fully_escape_query("foo's bar") + "foo\\\\'s bar" """ escaped = query # Escape special characters - escaped = re.sub(r'[\[\]\(\)\{\}:"\-+?~^/\\,]', r'\\\g<0>', escaped) + escaped = re.sub(r'[\[\]\(\)\{\}:"\-+?~^/\\,\']', r'\\\g<0>', escaped) # Remove boolean operators by making them lowercase escaped = re.sub(r'AND|OR|NOT', lambda _1: _1.group(0).lower(), escaped) return escaped