I found something interesting. I looked at the pg_search_rank for the results and noticed that the ones that don't have any occurrence of the keyword parameter all have the same rank of 0.398494.
res.map(&:pg_search_rank)
=> [0.917802, 0.894996, 0.854458, 0.854458, 0.76326, 0.76326, 0.76326, 0.76326, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494, 0.398494]
So then I ran the query with just the pg_search_scope:
Location.has_keyword('food')
and noticed the same thing! It returns a ton of results, but only a fraction are actually relevant!
So, the question is, is it normal for pg_search to return results that don't match the string? I would think not. It seems like pg_search is returning results even if they don't match, but just ranking them lower. Is that the default behavior? If so, how can I change it? Would it be safe to assume that any rank below 0.398494 is not relevant?
Moncef