anlutro / qdb

IRC quote database
MIT License
1 stars 4 forks source link

Make search use fulltext search #4

Open anlutro opened 8 years ago

anlutro commented 8 years ago

So that we can sort by match score etc.

FredG71 commented 8 years ago

@x89

anlutro commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 https://github.com/anlutro/qdb/issues/4#issuecomment-137396669.

anlutro commented 8 years ago

@x89 fix

FredG71 commented 8 years ago

@x89 what is that @rgarnier

anlutro commented 8 years ago

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 commented 8 years ago

just use microsoft sql server

x89 commented 8 years ago

Nice haircut @anlutro