$itemList = DB::table('items') ->orderBy('id', 'desc') ->where('item_status', 2) ->where(function($query) use($queryArr) { foreach($queryArr as $uID){ $query->whereRaw("tags LIKE '%$uID%'"); } })->paginate(21);
I have encountered this problem since ancient times. The problem when doing a LIKE search is that it captures WOMAN data when it is simple: MEN
Mainly because MEN is inside women
I also tried the following but failed (this type of word capture) men without women data
$query->where('tags', 'LIKE', '%'.$uID.'%'); SELECT 'a word a' REGEXP '[[:<:]]word[[:>:]]';
How to use this query on Word boundary in laravel query builder
Tried this and still failed $ query-> whereRaw ("tags LIKE REGEXP" [[: <:]] Men [[:>:]] '");
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REGEXP '[[:<:]]Men[[:>:]]')' at line 1 (SQL: select count(*) as aggregate from items where item_status = ? and (tags LIKE REGEXP '[[:<:]]Men[[:>:]]')) (Bindings: array ( 0 => 2, ))
I also understand that some ask why I didnβt just create the right way to handle this category of positions. Well, I think that now using full-text search is no more suitable for me, when it comes to scaling, I will use voltage search. true?
UPDATE
Sorry for not giving an example tag.
bag, shoes, Men , wedges
bag, shoes, men
Men shoes bag
source share