Shakeel
Shakeel

Reputation: 1059

How can I implement a text search in node.js using a Postgres database?

I want to add search functionality to an expressjs node application using Postgres as my database. I know how to do the filtering I'll need by date and some other column of finite values, but I don't know how to do a text search on a specific column. Given a string "chair", should my search algorithm return results with text like "my armchair", or "my chair"?

Maybe this question is so simple I'm just overlooking something. Thanks!

Upvotes: 0

Views: 2102

Answers (1)

saladinxu
saladinxu

Reputation: 392

Try this:

SELECT * FROM <table> WHERE <colume> ~* '\ychair\y'

Where \y denotes the beginning/end of words

Upvotes: 1

Related Questions