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 gs0090
or 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
Comments
Post a Comment