Parse the entry string into words (aka tokens) and assemble with the and operator. E.g. 'red cat' becomes 'red & cat'. >Then add vector; more info in articles I provide links to later in this note. WHERE to_tsvector ( productname || ' ' || productdescription ) @@ to_tsquery ( 'red & cat' )

Since there were no responces for a while, I went with another solution.
Splitted search string to words like you but converted query to

select
+case when productname ilike '%red%'  then 2 else 0 end
+case when productdescription ilike '%red%'  then 1 else 0 end
+case when productname ilike '%cat%'  then 1.7 else 0 end
+case when productdescription ilike '%cat%'  then 0.7 else 0 end
from products
order by 1 desc
limit 100

This allows to define relevance.
Is my solution reasonable ?

Andrus
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to