0

I currently search for multiple words in a string like this:

select name from restaurant where regexp_split_to_array(lower(name), '\s+') @> array['bar', 'food'];

Which splits the string in an array like this: The Food Bar = [the, food, bar]

But it only works if the full words are in the string. I want to get the same result if I use "ba" and "foo" for example. How can I achieve it?

1 Answer 1

3

Full text search may do the trick:

WHERE to_tsvector('simple', name) @@ to_tsquery('simple', 'the:* | food:* | bar:*')
Sign up to request clarification or add additional context in comments.

2 Comments

Is ranking the results possible?
@KevinWaterson Should be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.