Created
February 5, 2013 14:53
-
-
Save clouddueling/4714933 to your computer and use it in GitHub Desktop.
multi column sorted fulltext search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function search_contacts($terms) | |
{ | |
$terms = escape($terms); | |
$contacts = Contact::where_account_user_id(Auth::user()->account_user_id) | |
->raw_where("match (`first`, `last`) against ('{$terms}*' IN BOOLEAN MODE)", array()) | |
->where_account_user_id(Auth::user()->account_user_id) | |
->where_deleted(0) | |
->take(20) | |
->get(); | |
$contacts_array = array(); | |
foreach ($contacts as $contact) { | |
$contacts_array[] = array_merge( | |
$contact->to_array(), | |
array('rank' => similar_text($terms, $contact->first . ' ' . $contact->last)) | |
); | |
} | |
aasort($contacts_array, 'rank'); | |
return array_reverse($contacts_array); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment