WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Relevanssi – A Better Search] Some possible improvements for Relevanssi

[Plugin: Relevanssi – A Better Search] Some possible improvements for Relevanssi

  • Hi, I use the plugin Relevanssi for the first time and I noticed some things that could be improved I think:

    1- I see lots of is_search() and is_admin() in the relevanssi_do_query() function. Since we have access to the $query object, wouldn’t it be better if they are replaced by $query->is_search and $query->admin? There’s a case where is_admin() can be a problem: if I use relevanssi_do_query() in a front-end ajax request. When we make ajax requests from the front-end, we generally use the “admin_ajax” hook, so the function is called from the admin area, so is_admin() always returns true but the result must be displayed in front-end (relevanssi_highlight_terms() is never triggered for example).
    This way we could do something like that:

    $my_query = new WP_Query( … );
    $my_query->is_admin = 0;
    relevanssi_do_query($my_query);

    (I didn’t try it, but I think it should work).

    2- line 733 we have this:

    $wpSearch_high = $wpSearch_low + $query->query_vars[“posts_per_page”] – 1;
    if ($wpSearch_high > sizeof($hits)) $wpSearch_high = sizeof($hits) – 1;

    for ($i = $wpSearch_low; $i <= $wpSearch_high; $i++) {

    And what if posts_per_page = -1? 😉

    3- In some rare cases, something like that could be useful:
    lines 1676 and 1677:

    $excerpt_length = apply_filters(“relevanssi_excerpt_length”, get_option(“relevanssi_excerpt_length”), $content, $terms);
    $type = apply_filters(“relevanssi_excerpt_type”, get_option(“relevanssi_excerpt_type”), $content, $terms);

    Thanks.
    Greg

    http://wordpress.org/extend/plugins/relevanssi/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    @msaari

    I’ll take a look at these. I’m all for adding new filter hooks if people need them.

    Thank you msaari.

    For the filter hook, I just discovered the “pre_option_” filter 10 minutes ago.
    So another hook in the plugin is not needed anymore, we can do something link this :

    add_filter(‘pre_option_relevanssi_excerpt_length’, ‘sf_relevanssi_excerpt_length’);
    function sf_relevanssi_excerpt_length() {
    return isset($_REQUEST[‘action’]) && $_REQUEST[‘action’] == ‘my-special-ajax-search’ ? 7 : false;
    }

    And of course we can add more conditions for a non-ajax search or other cases (return false means we keep the saved option as it, for checkboxes we must return ‘on’ or ‘off’).
    Very handy hook actually 🙂

    Plugin Author Mikko Saari

    @msaari

    Ooh, clever. WordPress has done that one right. Never heard of a feature like that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Some possible improvements for Relevanssi’ is closed to new replies.