Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Created September 11, 2016 22:05
Show Gist options
  • Save 2ndkauboy/7bfa7c544b0731cc000e39e91174267c to your computer and use it in GitHub Desktop.
Save 2ndkauboy/7bfa7c544b0731cc000e39e91174267c to your computer and use it in GitHub Desktop.
<?php
/**
* ElasticPress Fine Tuning
*
* @package ElasticPressFineTuning
* @author Bernhard Kau
* @license GPLv3
*
* @wordpress-plugin
* Plugin Name: ElasticPress Fine Tuning
* Description: This plugin changes some ElasticPress parameters for better search results.
* Version: 1.0.0
* Author: Bernhard Kau
* Author URI: http://kau-boys.de
* Plugin URI: https://gist.github.com/2ndkauboy/
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0
*/
/**
* Fine tune the arguments
*
* @param array $formatted_args The formatted args array for the query.
* @param array $args The raw query args array.
*
* @return array The changed formatted args array
*/
function elasticpress_fine_tuning_ep_formatted_args( $formatted_args, $args ) {
$search_fields = array(
'post_title^4',
'post_excerpt^2',
'post_content',
);
$query = array(
'bool' => array(
'should' => array(
array(
'multi_match' => array(
'query' => $args['s'],
'type' => 'phrase',
'fields' => $search_fields,
'fuzziness' => 'AUTO',
'minimum_should_match' => '2<-25%',
),
),
array(
'multi_match' => array(
'query' => $args['s'],
'fields' => $search_fields,
'operator' => 'and',
'fuzziness' => 'AUTO',
),
),
),
),
);
$formatted_args['query'] = $query;
return $formatted_args;
}
add_filter( 'ep_formatted_args', 'elasticpress_fine_tuning_ep_formatted_args', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment