pg_search
pg_search copied to clipboard
Negating terms by prefixing them with !
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?
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.
@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.