WPML – Indexing & falling back to default language

  • phillmill
    Participant
    1 month, 4 weeks ago #31662

    I’m using WPML + WP SOLR pro, and there are 3 different languages on the site.

    There is a post type (Resorts) that is has only English posts (English is the default language). The Resort post type is configured in WPML to be “Translatable – use translation if available or fallback to default language”.

    What I want is for the secondary language indexes to index the English Resorts. I don’t want to have to duplicate all of the English resorts to each of the secondary languages to be able to index because there are 1000s of them. Keeping them all in just English is intentional.

    Currently when I attempt to index the Resort post type in a secondary language, it does nothing – nothing gets indexed. My assumption is this is because there are technically no Resorts in that language.

    Is there any way to make this work the way I want?

    Thank you

    wpsolr
    Keymaster
    1 month, 4 weeks ago #31663

    My assumption is this is because there are technically no Resorts in that language.

    Indeed: WPSOLR is using a “join” SQL statement on WPML language tables to retrieving the post types to index.

    You can see the SQL by checking the “debug” option while indexing.

    phillmill
    Participant
    1 month, 4 weeks ago #31664

    Is there a hook or filter I can use to modify that SQL statement? I want to index the English resorts on the secondary index

    wpsolr
    Keymaster
    1 month, 4 weeks ago #31665

    Yes indeed.

    An exemple of that can be found on https://www.wpsolr.com/forums/reply/30869/

    You can also find the code that generates the WPML SQL in file wpsolr-pro/wpsolr/pro/extensions/wpml/class-wpsolr-plugin-wpml.php:

    /**
     * Customize the sql query statements.
     * Add a join with the current indexing language
     *
     * @param $sql_statements
     *
     * @return mixed
     */
    function set_sql_query_statement( $sql_statements, $parameters ) {
    	global $wpdb;
    
    	// Get the index indexing language
    	$language = $this->get_solr_index_indexing_language( $parameters['index_indice'] );
    
    	if ( isset( $language ) ) {
    		global $sitepress;
    
    		// Ensure all WP functions are using the current index language, not the current admin language.
    		$sitepress->switch_lang( $language, true );
    
    		// Join statement
    		/** @var WPSOLR_Model_Meta_Type_Abstract $model_type */
    		$model_type          = $parameters['model_type'];
    		$sql_joint_statement = $model_type->get_sql_join_on_for_wpml();
    
    		$sql_statements['JOIN'] .= sprintf( $sql_joint_statement, $language );
    	}
    
    	return $sql_statements;
    }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.