Skip to content

Commit

Permalink
use postgres full-text search
Browse files Browse the repository at this point in the history
  • Loading branch information
edulauer committed Apr 16, 2024
1 parent 1e4ea17 commit ed5c95a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/hooks/inlabs_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,21 @@ def _generate_sql(payload: dict) -> str:

conditions = []
for key, values in filtered_dict.items():
key_conditions = " OR ".join(
[
rf"dou_inlabs.unaccent({key}) ~* dou_inlabs.unaccent('\y{value}\y')"
for value in values
]
)
key_conditions = ''
if key == 'texto':
key_conditions += " OR " .join(
[
rf"to_tsvector('portuguese', dou_inlabs.unaccent(texto)) @@ to_tsquery('portuguese', '{value}')"
for value in values
]
)
else:
key_conditions += " OR ".join(
[
rf"dou_inlabs.unaccent({key}) ~* dou_inlabs.unaccent('\y{value}\y')"
for value in values
]
)
conditions.append(f"({key_conditions})")

if conditions:
Expand Down

0 comments on commit ed5c95a

Please sign in to comment.