|
<?php |
|
|
|
/* |
|
Plugin Name: Solr + WPML |
|
Plugin URI: |
|
Description: Integrate Advanced Search By My Solr Server with WPML. |
|
This plugin hooks into advanced-search-by-my-solr-server |
|
and adds the language code of the document about to be stored |
|
in Solr to it, and filter search results by the current language. |
|
Version: 1.0 |
|
Author: Kryzalid |
|
Author URI: http://kryzalid.com |
|
*/ |
|
|
|
add_filter('mss_build_document', 'sw_filter_build_document', 10, 3); |
|
add_filter('mss_query', 'sw_filter_query', 10, 2); |
|
add_filter('mss_autocomplete', 'sw_filter_autocomplete', 10, 2); |
|
|
|
function sw_filter_build_document(Apache_Solr_Document $doc, WP_Post $post, array $options = array()) |
|
{ |
|
$lang = sw_get_post_language_code($post); |
|
|
|
if($lang) { |
|
$doc->setField('lang', $lang); |
|
} |
|
|
|
return $doc; |
|
} |
|
|
|
function sw_filter_query(array $args, array $options = array()) |
|
{ |
|
if(defined('ICL_LANGUAGE_CODE')) { |
|
$args['params']['fq'] = '+lang:' . ICL_LANGUAGE_CODE; |
|
} |
|
|
|
return $args; |
|
} |
|
|
|
function sw_filter_autocomplete(array $args, array $options = array()) |
|
{ |
|
if(defined('ICL_LANGUAGE_CODE')) { |
|
$args['params']['fq'] = '+lang:' . ICL_LANGUAGE_CODE; |
|
} |
|
|
|
return $args; |
|
} |
|
|
|
function sw_get_post_language_code(WP_Post $post) |
|
{ |
|
global $wpdb; |
|
|
|
$query = $wpdb->prepare( |
|
'SELECT `language_code` FROM `wp_icl_translations` WHERE `element_id` = %d LIMIT 1', |
|
$post->ID |
|
); |
|
|
|
$res = $wpdb->get_row($query); |
|
|
|
if(!is_object($res)) { |
|
return; |
|
} |
|
|
|
return $res->language_code; |
|
} |
Hello, great plugin, thanks! Small question: search results are displayed by language but I can't have facets by language (they are all displayed). Any idea?