Created
February 14, 2019 05:00
-
-
Save mikeyarce/96e656b56baa2c334a7dcb2f7cfc2214 to your computer and use it in GitHub Desktop.
fuzzy search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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