Jump to content

Creating a comprehensive search of products


Go to solution Solved by mallen,

Recommended Posts

I have been asked to create a more comprehensive search on my website. I have listed products. The table consists of id, name, model, description, watt_range, terms.

The problem I have having is if someone searches with multiple words the search won't give results. If I have an item like this.  AreaLight2, xyz light, here is the description, 70-100w, area.

If someone searches "AreaLight2" it returns the result. If you search "Arealight2 100w" it won't return any results. Can anyone help me point me in the right direction to get this to work? Thanks.

Here is the query 'SELECT cat.cat_name, cat.cat_id, prod.prod_id, prod.prod_name, prod.prod_mainImage, prod.prod_description, prod_model, prod.terms
FROM `products` as prod LEFT JOIN `category_assoc` AS assoc ON assoc.prod_id = prod.prod_id
LEFT JOIN `categories` AS cat ON cat.cat_id = assoc.cat_id
WHERE prod.terms LIKE '%Arealight2%' OR LIKE '%100w%'
OR prod.prod_name LIKE '%Arealight2%' OR LIKE '%100w%''

You can't write

... some_column LIKE '...' OR LIKE '...' ...

This may make sense in colloquial language, but to a computer, this is gibberish. The boolean OR operator can only be applied to two boolean expressions. But “LIKE ...” is no expression at all, it's just a syntax fragment.

 

A syntactically valid query would look like this:

... some_column LIKE '...' OR some_column LIKE '...' ...
  • 2 weeks later...
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.