Page 1 of 1

Splitting up search keywords for search engine

Posted: Thu Sep 23, 2004 8:27 am
by allyhazell
Hi,

I am trying to build an abbreviations search system. I have the Mysql database set up. People type in keywords and it searches the database for them. At the moment people are using a mixture of boolean commands and commas to separate their search terms. What I would like to know is which PHP command is best to separate those off?

So if someone was to search for:
bnm AND ghj OR pok NOT fda

Also people may search using commas (I am making it so that a comma would mean 'AND' in boolean). So:
bnm, ghj

I am currently using STRTOK to go through and find the spaces and look what is after them. It then creates the Mysql query as it goes through. But this seems overly complex. Is there another command that I could use instead?

Thanks

Alastair

Posted: Thu Sep 23, 2004 11:45 am
by feyd
[php_man]preg_split[/php_man] and a good regular expression are rather good at doing things like this. Given the proper regular expression, it'll return a nice neat array of all the words to look for, and the boolean values to use between them.

Posted: Thu Sep 23, 2004 1:09 pm
by allyhazell
Ok thanks, that's great. I will have a look and see how I get on with it.