luistinygod / WordPress-geeSearch-plus

Improves the WordPress search engine without messing with the database, sorts results by relevance, and more. Simple and clean!
1 stars 0 forks source link

Conceptual: Extend the search to BuddyPress components #1

Open zedejose opened 10 years ago

zedejose commented 10 years ago

Following this conversation on FB, I'd like to start a conversation about extending the plugin's search scope to BuddyPress components.

The way I see it, it would need (at least) 3 enhancements:

Additional settings on the dashboard

Basically allowing the user to switch on/off which BP components should be searched. Looks pretty easy to implement, thanks to your very handy admin functions. I've tried it like the example below, in /inc/class-gsp-admin.php:

if ( class_exists('BuddyPress' ) )
            add_settings_section( 'gee-settings-section-buddypress', __( 'BuddyPress Components', 'gee-search-plus' ) , array( $this,'settings_section_buddypress'), 'gee-search-plus' );

// some more code...

        //SECTION: BuddyPress
        if ( class_exists('BuddyPress' ) ) {
            // Enable search Members - Members component is active by default, no need to check
            add_settings_field( 'gee-settings-bp-members', __( 'Search on Members', 'gee-search-plus' ), array( $this,'settings_checkbox'), 'gee-search-plus', 'gee-settings-section-buddypress', array( 'name' => 'gee_searchplus_options[enable_bp_members]', 'key' => 'enable_bp_members', 'value' => $options ) );
            // Enable search Profile fields
            if ( bp_is_active( 'xprofile' ) )
                add_settings_field( 'gee-settings-bp-xprofile', __( 'Search on Profile Fields', 'gee-search-plus' ), array( $this,'settings_checkbox'), 'gee-search-plus', 'gee-settings-section-buddypress', array( 'name' => 'gee_searchplus_options[enable_bp_xprofile]', 'key' => 'enable_bp_xprofile', 'value' => $options ) );
            // Enable search Messages
            if ( bp_is_active( 'messages' ) )
                add_settings_field( 'gee-settings-bp-messages', __( 'Search on Messages', 'gee-search-plus' ), array( $this,'settings_checkbox'), 'gee-search-plus', 'gee-settings-section-buddypress', array( 'name' => 'gee_searchplus_options[enable_bp_messages]', 'key' => 'enable_bp_messages', 'value' => $options ) );
            // Enable search Activity
            if ( bp_is_active( 'activity' ) )
                add_settings_field( 'gee-settings-bp-activity', __( 'Search on Activity', 'gee-search-plus' ), array( $this,'settings_checkbox'), 'gee-search-plus', 'gee-settings-section-buddypress', array( 'name' => 'gee_searchplus_options[enable_bp_activity]', 'key' => 'enable_bp_activity', 'value' => $options ) );
            // Enable search Groups
            if ( bp_is_active( 'groups' ) )
                add_settings_field( 'gee-settings-bp-groups', __( 'Search on Groups', 'gee-search-plus' ), array( $this,'settings_checkbox'), 'gee-search-plus', 'gee-settings-section-buddypress', array( 'name' => 'gee_searchplus_options[enable_bp_groups]', 'key' => 'enable_bp_groups', 'value' => $options ) );
            // Enable search Forums
            if ( bp_is_active( 'forums' ) )
                add_settings_field( 'gee-settings-bp-forums', __( 'Search on Forums', 'gee-search-plus' ), array( $this,'settings_checkbox'), 'gee-search-plus', 'gee-settings-section-buddypress', array( 'name' => 'gee_searchplus_options[enable_bp_forums]', 'key' => 'enable_bp_forums', 'value' => $options ) );
        }

The search functions themselves

Which would be a variation of the ones used in my plugin, see https://github.com/zedejose/bp-search-everything/blob/master/includes/bp-search-everything-functions.php

Adding the BP results to the global search results

This is where I hesitated. BP Search Everything returns x of each component, with a link to further results. The logic behind this is that BP content is stored in different tables and (mostly) not in a format compatible with the WP_Post object, which is what gSearch is returning (via a WP_Query object).

The only way I can imagine to do this without a major architectural refactoring (and I may very well be wrong), is to create "pseudo-posts", i.e. arrays of $var = new WP_Post(), and array_push'ing those into the query results.

_The above approach, by the way, would have the benefit of allowing for a theoretically limitless extension of the plugin, since virtually any WP or direct SQL search query results could be added to the object_

In short

This was an idea of an approach, I'm not even sure it's the best one, but I'd like to discuss it.

luistinygod commented 10 years ago

Nice overview, Zé!

I agree with your approach on the dashboard and core functions. Merging the results is the issue here.

Philosophical speaking, geeSearch Plus was meant to inject a list of posts (pages, custom post types) matching a certain search criteria into the main search query, without messing with the templates (search.php or other).

So, it seems that your idea of converting BP Search Everything results as WP_Post objects and inject them into $wp_query at the very end of method 'extend_search_at_wp' could do the magic.

Pressure points of this approach (the way I see it):

zedejose commented 10 years ago