How can I filter some product(s) with multi keywords efficient? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, November 3, 2023

How can I filter some product(s) with multi keywords efficient?

I use PHP as backend and MYSQL as DB. Should I use PHP's array_filter instead of use multi LIKE in SQL query to filter keywords?

data structure in db:

Product_ID INT(6) UNSIGNED ZEROFILL AUTO_INCREMENT PRIMARY KEY,
Product_Name VARCHAR(30) NOT NULL,
Product_Des VARCHAR(10240) NULL,
Product_Price FLOAT(20) NOT NULL,
Product_Brand_ID INT(6) UNSIGNED ZEROFILL NOT NULL,
FOREIGN KEY (Product_brand) REFERENCES brand(Brand_ID),
Product_keyword VARCHAR(1024) NOT NULL,
Product_Catagory VARCHAR(30) NOT NULL

the product's keyword is store as JSON in Product_keyword like that:

{
  keywords: ["test1", "test2"]
}

Now I want filter product with Brand_ID = 1 or 2 and keyword have "test2" and "test9"

the Brand_ID part I can use SQL "IN" , but I not sure how to do with keyword

follow is the sample date

enter image description here

How can I filter some product(s) with multi keywords efficient?



source https://stackoverflow.com/questions/77411960/how-can-i-filter-some-products-with-multi-keywords-efficient

No comments:

Post a Comment