-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scientific Metadata Search Engine (Fulltext) implementation for Postg…
…reSQL 🔎 (#640) * Merge and reset with head upstream 👷♀️ Conform to pep∞ * 🗂️ Implement `jsonb_to_tsvector` which actually engages the index for real this time. * 📜 Implement fulltext query in adapter.py * ⬆️ Alembic migration creates text search index * Upstream merge removed paren 🔣 * Add new migration to list in `core.py` ➕ * Black formatting for precommit 🧹 * Verbose index naming convention 🪪 * Change from a list of conditions to a single condition * Skip unsupported `ts_vector` index creation for sqlite * Preformat with black ⬛️ and enable tests ✅ * change op from sqlalchemy match to `to_tsquery` 🪄 * Fix oddity with plainto_tsquery vs to_tsquery * Isolate migration from orm; orm may change! * Provide a more useful high-level comment. * Put index creation in its own function. * Remove all allusions to case sensitivity from fulltext 🔠🧽 * Taking a heavier hand to some light-touch changes --------- Co-authored-by: Dan Allan <[email protected]>
- Loading branch information
1 parent
1ff0885
commit eb79bdb
Showing
9 changed files
with
165 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tiled/catalog/migrations/versions/1cd99c02d0c7_create_index_for_fulltext_search.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Create index for fulltext search | ||
Revision ID: 1cd99c02d0c7 | ||
Revises: a66028395cab | ||
Create Date: 2024-01-24 15:53:12.348880 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.postgresql import JSONB | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1cd99c02d0c7" | ||
down_revision = "a66028395cab" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
# Make JSONB available in column | ||
JSONVariant = sa.JSON().with_variant(JSONB(), "postgresql") | ||
|
||
|
||
def upgrade(): | ||
connection = op.get_bind() | ||
if connection.engine.dialect.name == "postgresql": | ||
with op.get_context().autocommit_block(): | ||
# There is no sane way to perform this using op.create_index() | ||
op.execute( | ||
""" | ||
CREATE INDEX metadata_tsvector_search | ||
ON nodes | ||
USING gin (jsonb_to_tsvector('simple', metadata, '["string"]')) | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
# This _could_ be implemented but we will wait for a need since we are | ||
# still in alpha releases. | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters