Better Model Searching in ExpressionEngine 3.4

by: Pascal Kriete on: 8/12/2016

With ExpressionEngine 3.4 we’ve added a new search() function to our models. It’s a clean API that developers will love. No more debugging of LIKE queries or complex string pre-processing. In the past you may have done something like this:

    ->join('channel_data', 'exp_channel_titles.entry_id = exp_channel_data.entry_id ', 'left');

$words = explode(' ', $search);

foreach ($words as $word)
    ee()->db->like('title', $word);

$entries = ee()->db->get();

Now all you need is this:

$entries = ee('Model')
    ->search('title', $search)

Under the hood it’s fully packed with the things your users expect from search. Quoted strings are treated as phrase searches and minus signs can be used to exclude words or phrases. A consistent, easy to implement experience.

Happy finding!

.(JavaScript must be enabled to view this email address) or share your feedback on this entry with @eecms on Twitter.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases