Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.35k stars 371 forks source link

Phrase Search #420

Closed arcreative closed 3 weeks ago

arcreative commented 5 years ago

Apologies if I missed something, but is there support for phrase searches like "business analyst" in the middle of a search string, like the following:

word1 "word2 word3" word4

Where the results include word1 or word2 anywhere, but only word2 and word3 in proximity? It looks like this is supported with Postgres' term & term or term <-> term search, but it looks like the pg_search query parser splits the queries in a more basic way.

arcreative commented 4 years ago

@nertzy Any possibility the parser could recognize quoted phrases when separating search terms? I don't think we need full lucene or anything, but some of the native functions of PG might be nice. Quite a few people at my company are angry at me at the moment since our search functionality is lacking!

Ripchanskiy commented 3 weeks ago

@arcreative Hi. Any good news ?

arcreative commented 3 weeks ago

@Ripchanskiy I fixed this issue by creating my own gem. Turns out there’s very little to do in Ruby land if you just spend a little more thought creating your tsv column for fulltext search, including associated records. Mine allows this:

MyModel.search('foo bar "include this phrase" -butnotthis -"and and also not this phrase"')

and is more efficient since you’re doing “pain on write” and not doing tsvector calculations on the fly.

Find it here, and let me know your thoughts! https://github.com/arcreative/pg_fulltext