Eric Larson
Eric Larson

Reputation: 519

Extract Keywords From Text Using Postgres

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

Upvotes: 0

Views: 710

Answers (1)

jjanes
jjanes

Reputation: 44177

Getting your desired answer is pretty simple:

SELECT * FROM keywords WHERE 
    'I saw the news of lending club on facebook, your story and quora' LIKE 
        '%'||keyword||'%' ;

Now I don't know what you want to do with case, or word boundaries, or what you expect for performance. But your example didn't address any of those.

Upvotes: 1

Related Questions