WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] AJAX search from P2P_Box broken (+fix?) (14 posts)

  1. Ruud Laan
    Member
    Posted 1 year ago #

    Hi Mikko

    When I enable the admin search option, I stop having results in my P2P_box where you can search for posts.
    See http://wordpress.org/extend/plugins/posts-to-posts/ for details on this plugin by Scribu.

    I did some debugging and boiled it down to some problems i seem to be having with regards to the 'the_posts' filter and its checks on whether or not its an searchable query.
    This is my current (crappy)work-around which seems to at least fix this problem, but could cause other problems instead (haven't checked yet)

    init.php line 4:
    add_filter('the_posts', 'relevanssi_query', 9, 2);

    search.php line 36:
    if ( $query->is_search ) {
    $wp_query = apply_filters('relevanssi_modify_wp_query', $query);
    $posts = relevanssi_do_query($wp_query);
    }
    elseif ($search_ok) {
    $wp_query = apply_filters('relevanssi_modify_wp_query', $wp_query);
    $posts = relevanssi_do_query($wp_query);
    }

    Please let me know if you get similar results when combining the P2P plugin and Relevanssi and enabling the admin search option.

    Ystävällisin terveisin,
    Ruud

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

  2. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    If $query->is_search is true, $search_ok should be true as well, if you've enabled admin search.

    Could you just add a relevanssi_search_ok filter that would return true when doing a P2P admin search? That way you would not have to modify Relevanssi files.

  3. Ruud Laan
    Member
    Posted 1 year ago #

    Hi Mikko,

    Thanks for replying. I took a good look at your suggestion. It didn't work out. The thing is that somehow (don't know how) but by the time the query is going through your 'the_posts' filter, the wp_query seems totally unusable for specific tests in the relevanssi_search_ok filter (unusable as in totally empty/default).

    There also seems to be a discrepancy between the global $wp_query and the $query var in the function.

    I'm a bit lost here and had to switch off your admin search completely so far to get it working again.
    I've checked my custom theme for any related 'the_posts' filters etc, but to no avail.

    Could you verify my findings by using the p2p plugin (by scribu) yourself? Perhaps we could invite Scribu himself to this problem too? (not sure how to do that..)

  4. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Unfortunately working on compatibility issues with other plugins goes beyond the time I have available, since these kinds of problems tend to be somewhat complicated.

  5. Ruud Laan
    Member
    Posted 1 year ago #

    Hi Mikko,

    Fair enough. I'll drop a line with Scribu to see if he can shed some light on this.

  6. Ruud Laan
    Member
    Posted 1 year ago #

    Hi Mikko,

    I found a better solution after I found the cause of the incompatibility problem. You we're right that I want to try to exclude the search when doing an p2p_ajax_admin search... however I'm not able to because your 'relevanssi_prevent_default_request' method unconditionally 'destroys' the current query.
    So I propose the following:

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    $admin_search_ok = true;
    $admin_search_ok = apply_filters('relevanssi_admin_search_ok', $admin_search_ok, $query );
    if (!is_admin())
    $request = "SELECT * FROM $wpdb->posts WHERE 1=2";
    		else if ('on' == get_option('relevanssi_admin_search') && $admin_search_ok ) {
    			$request = "SELECT * FROM $wpdb->posts WHERE 1=2";
    		}'

    In this filter I can selectively exclude all p2p related searches.
    What do you think?

  7. Ruud Laan
    Member
    Posted 1 year ago #

  8. Ruud Laan
    Member
    Posted 1 year ago #

    Hi Mikko,

    Scribu added a variable in the query on which I can base the filter to exclude the search on the basis of that variable.

    Could you please consider adding the suggested filter (or something like it) into the 'relevanssi_prevent_default_request' method, so I can truly filter out this usage of your plugin in this particular case?

    Besides me using this feature, the option for other users to be able to use it in their cases would make this enhancement a nice addition I would think, especially because you already made the 'relevanssi_search_ok' filter in order to be able to do that.

    Ystävällisin terveisin,
    Ruud

  9. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    I'm all for adding filters, so what exactly it is you want?

    If relevanssi_prevent_default_request is bugging you, can't you just remove the filter when necessary?

  10. Ruud Laan
    Member
    Posted 1 year ago #

    Hi Mikko,

    I looked into your suggestion for removing the filter. This is a viable option, however the timing of removing the filter and the precise call when removing the filter both makes this a somewhat hacky way of doing things I think, and prone to errors later on the road, for instance if you decide to change the behaviour of the method or the way in adding the filter yourself.

    I suggested a filter for use in common.php (line 430:)

    $admin_search_ok = true;
    		$admin_search_ok = apply_filters('relevanssi_admin_search_ok', $admin_search_ok, $query );
    		if (!is_admin())
    			$request = "SELECT * FROM $wpdb->posts WHERE 1=2";
    		else if ('on' == get_option('relevanssi_admin_search') && $admin_search_ok ) {
    			$request = "SELECT * FROM $wpdb->posts WHERE 1=2";
    		}

    This way, a user can do on a per query basis check if the want the query to be prevented or not. This of course in conjunction with the actual search later on.

  11. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Ok, I'll add that filter in the next version.

  12. Ruud Laan
    Member
    Posted 1 year ago #

    Great!
    Any thoughts on when the next version is coming out?

  13. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    No idea, and I've learnt not to make any promises. Anyway, you can add the filter now, and rest assured it won't break when you update.

  14. Ruud Laan
    Member
    Posted 1 year ago #

    OK, I understand.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic