Skip to content

Commit

Permalink
index check query change
Browse files Browse the repository at this point in the history
  • Loading branch information
jlonge4 committed Apr 9, 2024
1 parent fdb5d5b commit 32e53fe
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,20 @@ def _create_keyword_index(self):
"""
Internal method to create the keyword index if not exists.
"""
sql_check_index = SQL("SELECT * FROM pg_indexes WHERE tablename = {table_name};").format(
table_name=Identifier(self.table_name)
index_exists = bool(
self._execute_sql(
"SELECT * FROM pg_indexes WHERE tablename = %s",
(self.table_name),
"Could not check if keyword index exists",
).fetchone()
)
result = self._execute_sql(sql_check_index, error_msg="Could not create keyword index on table")

if result.fetchone():
return

sql_create_index = SQL("CREATE INDEX ON {table_name} USING GIN (to_tsvector({language}, content))").format(
table_name=Identifier(self.table_name), language=SQLLiteral(self.language)
sql_create_index = SQL('CREATE INDEX ON "{table_name}" USING GIN (to_tsvector({language}, content))').format(
table_name=SQLLiteral(self.table_name), language=SQLLiteral(self.language)
)

self._execute_sql(sql_create_index, error_msg="Could not create keyword index on table")
if not index_exists:
self._execute_sql(sql_create_index, error_msg="Could not create keyword index on table")

def _handle_hnsw(self):
"""
Expand Down

0 comments on commit 32e53fe

Please sign in to comment.