What you are looking for is word stemming .
You can't really create a language like English using a bunch of regular expressions, there are too many exceptions. You need a big dictionary.
Full-text search PostgreSQL offers such a dictionary, and I highly recommend that you use full-text search for this work:
regress=# WITH vals(a,b) AS (VALUES ('goose','geese'), ('query','queries'), ('arrays','array')) SELECT to_tsquery(a), to_tsvector(b), to_tsquery(a) @@ to_tsvector(b) FROM vals; to_tsquery | to_tsvector | ?column? ------------+-------------+---------- 'goos' | 'gees':1 | f 'queri' | 'queri':1 | t 'array' | 'array':1 | t (3 rows)
although you will notice that the dictionary dictionary is not perfect; I would expect the search for "goose" to match "geese", but it is not. You may need to improve your vocabulary. The PostgreSQL dictionary can also be a little overpriced because it may occur from time to time .
An alternative is to use a tool that is more and more customizable, such as Apache Solr.
source share