Boost Search on Taxonomy Pages

  • wpsolr
    Keymaster
    1 year, 5 months ago #31404

    Something like that should work:

    <?php
    
    use wpsolr\core\classes\ui\WPSOLR_Query;
    use wpsolr\core\classes\WPSOLR_Events;
    
    add_action( WPSOLR_Events::WPSOLR_FILTER_UPDATE_WPSOLR_QUERY, 'update_keywords', 10, 1 );
    
    /**
     *
     * Update the WPSOLR keywords based on some conditions.
     *
     * @param WPSOLR_Query $wpsolr_query
     *
     * @return WPSOLR_Query
     */
    function update_keywords( WPSOLR_Query $wpsolr_query ) {
    
    	$current_keywords = $wpsolr_query->get_wpsolr_query();
    
    	/**
    	 * Change keywords based on your conditions here
    	 */
    	if ( 'test' === $current_keywords ) {
    		$wpsolr_query->set_wpsolr_query( 'trial' );
    	}
    
    	return $wpsolr_query;
    }
    1 year, 5 months ago #31405

    Okay, this worked.

    1 year, 5 months ago #31437

    Can we pass like this too : As we don’t want to miss results related to test, Can we have results of test and trial both, instead of mapping it to trial only.

    if ( 'test' === $current_keywords ) {
    	$wpsolr_query->set_wpsolr_query( 'trial or test' );
    }
    wpsolr
    Keymaster
    1 year, 5 months ago #31439

    It should work with ‘trial OR test’

    Check out Elasticsearch guilde for query_string

Viewing 4 posts - 46 through 49 (of 49 total)

You must be logged in to reply to this topic.