Replies: 1 comment
-
I was wondering about the same thing and just found this SO answer: https://stackoverflow.com/a/9552871/12423765 Translated it into roughly this sqlmodel code below, and it seems to work! (I omitted all the irrelevant details of my code from this, please let me know if I failed to include something important) from typing import Sequence, Self
from sqlalchemy.dialects.postgresql.ext import to_tsquery
from sqlmodel import Field, SQLModel, select, col
from sqlmodel.ext.asyncio.session import AsyncSession
class Note(SQLModel, table=True):
content: str = Field(nullable=False)
@classmethod
async def search_by_text(cls, session: AsyncSession, query: str) -> Sequence[Self]:
return (
await session.exec(
select(cls).filter(col(cls.content).op("@@")(to_tsquery(query)))
)
).all() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Hi, I read all the docs and user guide but can't figure out how to implement fulltext search in sqlmodel. For example, search all hero contains name "spider". I'd like to perform some analayis like ascii folding if possible.
Thanks in advanced.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.14
Python Version
Python 3.11.6
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions