andychev, you didn't metioned DB name you're using: MySQL or PostgreSQL. I presume it is MySQL.
To search exact term in the varchar or text field you can use LIKE. If from the records like:
- this is red
- this is_red
- this is reddddd
... you want only the first, you should use query like:
Code:
SELECT * FROM tbl_name WHERE text_field LIKE '% red %';
Note the gaps before & after 'red'. I sure that search terms will not be always enclosed by gaps, so we should modify our query:
Code:
SELECT * FROM tbl_name WHERE text_field LIKE '% red %' OR text_field LIKE '%red %' OR text_field LIKE '% red%' ORDER BY field_name;
Notice, I've added other alternatives + ORDER statement. The only minusofthis query is that if the fieldwill contain only 'red' - it will not be selected.
If you want to order selected items by the number of searched terms (relevancy) you can use MATCH AGAINS syntax.
Let me know if you need futher explanations.