Skip to content

Instantly share code, notes, and snippets.

@mikeyarce
Created February 14, 2019 05:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeyarce/96e656b56baa2c334a7dcb2f7cfc2214 to your computer and use it in GitHub Desktop.
Save mikeyarce/96e656b56baa2c334a7dcb2f7cfc2214 to your computer and use it in GitHub Desktop.
fuzzy search
<?php
// Fuzzy search
add_filter( 'jetpack_search_es_query_args', 'es_fuzzy_search', 10, 2);
function es_fuzzy_search( $es_query_args, $query ) {
$query = get_search_query();
$es_query_args['query']['function_score']['query']['bool'] = array(
'must' => array(
array(
'multi_match' => array(
'fields' => array(
"meta.search_content.value^3",
"taxonomy.search_tag.name^2",
"title"
),
'fuzziness' => 'auto',
'query' => $query,
'operator' => 'and',
),
),
),
'should' => array(
array(
'multi_match' => array(
'fields' => array(
"meta.search_content.value^3",
"taxonomy.search_tag.name^2",
"title"
),
'fuzziness' => 'auto',
'query' => $query,
'operator' => 'and',
'type' => 'phrase',
),
),
),
);
return $es_query_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment