Skip to content

Commit

Permalink
Feature: ~ uses ILIKE rather than LIKE
Browse files Browse the repository at this point in the history
Using `~` on a query field (e.g. `name~`) will do a PostgreSQL `ILIKE`
query, though because of internetarchive/openlibrary#137
`_` will not work as expected.
  • Loading branch information
scottbarnes committed May 8, 2024
1 parent 3a65087 commit 1aac4f2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions infogami/infobase/dbstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ def process(c, ordering_func=None):
raise StopIteration
c.value = metadata.id
if c.op == '~':
op = Literal('LIKE')
c.value = c.value.replace('*', '%').replace('_', r'\_')
op = Literal('ILIKE')
# Asterisks as part of the author's name query from patron input are escaped in Open Library
# so they don't become % wild card searches. E.g. an author styled as "Muñ*z" shouldn't have
# their "*" become a wild card. Other wild cards added by code should be converted to %, though.
c.value = r'\*'.join(part.replace('*', '%') for part in c.value.split(r'\*')).replace('_', r'\_')
else:
op = Literal(c.op)

Expand Down

0 comments on commit 1aac4f2

Please sign in to comment.