I have a table of keywords. I want to query the keywords table given a string of text and return the keywords found. I was able to get this working in Elasticsearch using this solution. Is this something that is possible in Postgres using the available text search functions? How would the text search query look?
Example:
Keywords table:
id keyword
--------------
1 thousand eyes
2 facebook
3 superdoc
4 quora
5 your story
6 Surgery
7 lending club
8 ad roll
9 the honest company
10 Draft kings
Given the following text: "I saw the news of lending club on facebook, your story and quora"
Output:
id keyword
--------------
3 facebook
4 quora
5 your story
7 lending club
select regexp_matches('1 2 3 4 5 666', '\m(1|3 4|6)\M', 'g');'\m(1|3 4|6)\M'you should to build it dynamically using yourKeywordstable:select '\m(' || string_agg(keyword, '|') || ')\M' from Keywords;The complete query could be:select regexp_matches('I saw the news of lending club on facebook, your story and quora', (select '\m(' || string_agg(keyword, '|') || ')\M' from Keywords));Then join it withKeywordsto get IDs.