If I run a search with uniq, eg. prefix_search("fuel").uniq.limit(5), the query contains SELECT DISTINCT but it still returns duplicate results.
For now I can use Ruby's standard uniq afterwards, but this will give me less results than I wanted (via the limit).
Is there any solution for this, or is it a limit of PostgreSQL's full text search?
I believe this one is also related to #60. The problem is probably that pg_search is adding a big expression to the select part of the query called pg_search_rank, and so the distinct is applying to that part as well, which means every record that has a slightly different rank value calculated is considered distinct.
I hope to get some time to dig into this soon.
@nertzy That makes sense. I suppose the only way around that would be to move the ts_rank code directly into an order by scope and not select it at all?
Update: I guess that won't even work -- "PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list"
If you want to remove the rank from the order expression, you could chain ActiveRecord::QueryMethods#reorder onto the end.
I'm not sure, but you might then need to add another order clause after that.
Sounds good. Thanks.