• Has anyone else noticed how poor WP’s built-in search function is? does anyone have any recommendations on how to improve it?

    (for example, I can search my posts for “brown” or “dog” fine, but if I enter “brown dog” (with quotes, to keep it as a unit), it can’t accomodate that).

    Thanks,
    Amir

Viewing 2 replies - 1 through 2 (of 2 total)
  • One thing I wondered is why the search does not use a MySQL index? Is it for performance? Below is the code for the search:

    if (!empty($q[‘s’])) {
    $q[‘s’] = addslashes_gpc($q[‘s’]);
    $search = ‘ AND (‘;
    $q[‘s’] = preg_replace(‘/, +/’, ‘ ‘, $q[‘s’]);
    $q[‘s’] = str_replace(‘,’, ‘ ‘, $q[‘s’]);
    $q[‘s’] = str_replace(‘”‘, ‘ ‘, $q[‘s’]);
    $q[‘s’] = trim($q[‘s’]);
    if ($q[‘exact’]) {
    $n = ”;
    } else {
    $n = ‘%’;
    }
    if (!$q[‘sentence’]) {
    $s_array = explode(‘ ‘,$q[‘s’]);
    $q[‘search_terms’] = $s_array;
    $search .= ‘((post_title LIKE \”.$n.$s_array[0].$n.’\’) OR (post_content LIKE \”.$n.$s_array[0].$n.’\’))’;
    for ( $i = 1; $i < count($s_array); $i = $i + 1) {
    $search .= ‘ AND ((post_title LIKE \”.$n.$s_array[$i].$n.’\’) OR (post_content LIKE \”.$n.$s_array[$i].$n.’\’))’;
    }
    $search .= ‘ OR (post_title LIKE \”.$n.$q[‘s’].$n.’\’) OR (post_content LIKE \”.$n.$q[‘s’].$n.’\’)’;
    $search .= ‘)’;
    } else {
    $search = ‘ AND ((post_title LIKE \”.$n.$q[‘s’].$n.’\’) OR (post_content LIKE \”.$n.$q[‘s’].$n.’\’))’;
    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Better search’ is closed to new replies.