Splitting up search keywords for search engine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
allyhazell
Forum Newbie
Posts: 9
Joined: Mon Sep 13, 2004 12:43 pm

Splitting up search keywords for search engine

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
allyhazell
Forum Newbie
Posts: 9
Joined: Mon Sep 13, 2004 12:43 pm

Post by allyhazell »

Ok thanks, that's great. I will have a look and see how I get on with it.
Post Reply