0

I have a table called 'products' where i have product names like 'Iphone5 with 1GB Data', 'Iphone5 with 10GB Data', etc... and so on...

When user use a search box to search this products i make a query like the following...

 select *
 from products
 where product_name like '%USER_SEARCH_KEY%'
 limit 5;

now when i search 'iphone5 with' i get the rows which has 'iphone5 with' word in it. but when i search 'iphone5 1gb' i get no records found... i had to enter 'iphone5 with 1gb' to get that result. Is there any way i get the record on result set when i search for 'iphone5 1gb' keyword also ?

Thanks in advance.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
user2301765
  • 669
  • 2
  • 8
  • 22

2 Answers2

1

You have 3 way for a solution to this task:

  1. You can create full-text index and search by it
  2. You can break a user search query on words and make database query like the following:

    SELECT * FROM products WHERE product_name LIKE '%iphone5%1gb%' limit 5

  3. You can use a search engine, for example, Elastic Search. I think this way is better

JIJOMON K.A
  • 1,290
  • 3
  • 12
  • 29
Maksym Fedorov
  • 6,383
  • 2
  • 11
  • 31
0

you can use just 1gb in search string

 select * from t1 where  item like '%1GB%'

otherwise you have to use fulltext search but for using this to have to implement that in your table

Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63