pg_search icon indicating copy to clipboard operation
pg_search copied to clipboard

Negating terms by prefixing them with !

Open derek-watson opened this issue 11 years ago • 2 comments

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?

derek-watson avatar Jun 18 '13 19:06 derek-watson

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.

nertzy avatar Jun 18 '13 20:06 nertzy

@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.

amnesia7 avatar Jan 09 '16 23:01 amnesia7