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.36k stars 371 forks source link

Negating terms by prefixing them with ! #117

Open derek-watson opened 11 years ago

derek-watson commented 11 years ago

Hello,

Unless I'm missing something, it seems difficult/impossible to build a search scope that matches some terms and excludes others. I'm considering extending this gem so allow the following case:

pg_search_scope :search_title, against: :title

Post.search_title('jaguar !cat')

Which would match documents with 'jaguar' in the title and exclude those with 'cat', leveraging the basic feature of tsquery documented here: http://www.postgresql.org/docs/9.2/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES

Would a pull request implementing this feature be accepted?

nertzy commented 11 years ago

That seems reasonable enough to me. One caveat is that it won't be handled by the dmetaphone or trigram search features in an expected manner, but I'm not sure how to reconcile that.

amnesia7 commented 8 years ago

@derek-watson since normal practice with google searches for excluding search terms is to put a dash/hyphen before terms 'jaguar -cat', would I need to check if the user done that and replace them in the search terms string with ! to do this negation or would it be better if the gem allowed for negation by that format -term as well? If application users doing the search are more familiar with oracle's text search query format I think an exclamation before the word actually triggers the oracle search to use soundex which is like dmetaphone.