Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make search use fulltext search #4

Open
anlutro opened this issue Sep 3, 2015 · 9 comments
Open

Make search use fulltext search #4

anlutro opened this issue Sep 3, 2015 · 9 comments

Comments

@anlutro
Copy link
Owner

anlutro commented Sep 3, 2015

So that we can sort by match score etc.

@FredG71
Copy link

FredG71 commented Sep 3, 2015

@x89

@anlutro
Copy link
Owner Author

anlutro commented Sep 3, 2015

http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html#full-text-search

I can't really make sense of how to translate this to the ORM though.

There's also a package: https://sqlalchemy-searchable.readthedocs.org/en/latest/

@anlutro
Copy link
Owner Author

anlutro commented Sep 3, 2015

Apparently to sort by relevance with a fulltext search in psql you need to do this, which I have no idea how to do in SQLAlchemy.

SELECT ts_rank_cd(
  to_tsvector('english', table.column),
  to_tsquery('search string')
) AS score

@x89
Copy link

x89 commented Sep 3, 2015

Ty for the highlight @rgarnier
On 3 Sep 2015 11:00, "Andreas Lutro" notifications@github.com wrote:

Apparently to sort by relevance with a fulltext search in psql you need to
do this, which I have no idea how to do in SQLAlchemy.

SELECT ts_rank_cd(
to_tsvector('english', table.column),
to_tsquery('search string')
) AS score


Reply to this email directly or view it on GitHub
#4 (comment).

@anlutro
Copy link
Owner Author

anlutro commented Sep 3, 2015

@x89 fix

@FredG71
Copy link

FredG71 commented Sep 3, 2015

@x89 what is that @rgarnier

@anlutro
Copy link
Owner Author

anlutro commented Apr 20, 2016

Got me a working query

select id, body, ts_rank_cd(to_tsvector('english', body), query) as score
from quotes, to_tsquery('linux') query
where query @@ to_tsvector('english', body)
order by score desc;

Doing the to_tsvector twice seems unnecessary, though.

@moopie
Copy link

moopie commented Jun 6, 2016

just use microsoft sql server

@x89
Copy link

x89 commented Jun 6, 2016

Nice haircut @anlutro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants