Page 1 of 1

exact words in a query

Posted: Thu Jun 12, 2003 5:08 pm
by phpScott
I currently have a table set up with a field for keywords extracted from some images, all the keywords are stored in a signle field called keywords (suprise).

Now I need to search through that field looking for exact words that a client will be able to type in.
id

client types in mountian
I want to search through the keyword field to see if the word mountian is in there.

Any ideas on how to best approach this?

Or would it be better to store every keyword seperately with the picId attached?

phpScott

Posted: Thu Jun 12, 2003 7:08 pm
by Paddy
$result = strpos($keywords,$keyword);

If $result != "" then a keyword has been found.

Personally though I would put the keywords individually into the DB. But that is just me...

Posted: Thu Jun 12, 2003 7:37 pm
by nielsene
Here's another vote for a keywords table -- ie picId, keyword -- one row per unique keyword/picID combo...

However if you don't do that you can also check if your database supports a "like" operator for full text search. In PostGreSQL, I would do

Code: Select all

SELECT "picId" FROM tablename WHERE keywords LIKE '%mountain%';
The %'s are a wildcard.

thanks guys

Posted: Thu Jun 12, 2003 7:51 pm
by phpScott
That's what I thought too but I'm sort of taking over this project so it is probally worth the effor to re-engineer it a bit.

phpScott