Jump to content

searching database for multiple words


seany123

Recommended Posts

Hi, I know this could probably be solved using either php or SQL, so i wasnt sure which board to post this on, but ive always been under the impression its best to solve the issues through SQL if possible as thats the most efficient way.

 

I have a products table which contains

product_name varchar (255)

 

then im allowing users to search for products,

with the current php code:

product_name LIKE '%$searchTerms%' //searchTerm would contain ie: "red apples"

it wont return results when the users type the plural for a word ie apples instead of apple,

or if they type apple red instead of red apple.

 

im wondering the best way to search products?

 

i thought i could explode the searchTerm variable and run the like query for every word

product_name LIKE '%$searchTerm[0]%' OR product_name LIKE '%$searchTerm[1]%'

but then im worried about relevance, if one of the search terms is the word "and" then it might return completely irrelevant results.

 

also how would i go about dealing with the plurals?

 

Any suggestions on the best way to do this?

 

thanks

Edited by seany123
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.