laravel - Search using words in any order or combination and return row -


my table has row stored d1234 hex screw gs0090 o109. can d1234 hex or screw gs0090 , return row. want able enter words in combination or order d1234 gs0090or hex d1234 , have return row. how can done?

edit: i'm using laravel 5.4, mysql database uses myisam engine

$products = db::connection('it')             ->table('it')             ->join('units','units.code', '=', 's.code')             ->join('vendors', 'vendors.code', '=', 's.code')             ->where('s.deleted', '=', 0)             ->where('vendors.deleted', '=', 0)             ->where('s.description', 'like', '%'.$term.'%')             ->orwhere('s.vendorcode', 'like', '%'.$term.'%' )             ->orwhere('s.vendordefaultcode','like', '%'.$term.'%')             ->orwhere('vendors.partnumber', 'like', '%'.$term.'%')             ->orwhere('vendors.partvendorcode', 'like', '%'.$term.'%')             ->get()); 

i recommend using full text search if using mysql. used advanced searching, enhances search well.

first need add fulltext index table each column want use full text search:

alter table tablename add fulltext(description); 

next modify query:

$products = db::connection('it')             ->table('it')             ->join('units','units.code', '=', 's.code')             ->join('vendors', 'vendors.code', '=', 's.code')             ->where('s.deleted', '=', 0)             ->where('vendors.deleted', '=', 0)             ->whereraw("match (s.description) against ('{$term}*' in boolean mode)")             ->orwhereraw("match (s.vendorcode) against ('{$term}*' in boolean mode)")             ->orwhereraw("match (s.vendordefaultcode) against ('{$term}*' in boolean mode)")             ->orwhereraw("match (vendors.partnumber) against ('{$term}*' in boolean mode)")             ->orwhereraw("match (vendors.partvendorcode) against ('{$term}*' in boolean mode)")             ->get()); 

some links out

mysql full-text search multiple words

mysql full text search percentage scoring


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -