/** * Search custom fields as well as content. * Replaces WC_Admin_Post_Types::Replaces shop_order_search_custom_fields. * * @param \Wallmander\ElasticsearchIndexer\Model\Query $query */ public static function actionOrderSearch(Query $query) { global $pagenow; $wpQuery = $query->wp_query; if ('edit.php' != $pagenow || !$wpQuery->get('s') || $wpQuery->get('post_type') != 'shop_order') { return; } $search = str_replace('Order #', '', $wpQuery->get('s')); $searchFields = apply_filters('woocommerce_shop_order_search_fields', ['_billing_first_name', '_billing_last_name', '_shipping_first_name', '_shipping_last_name', '_billing_company', '_billing_address_1', '_billing_address_2', '_billing_city', '_billing_postcode', '_billing_country', '_billing_state', '_billing_email', '_billing_phone', '_shipping_address_1', '_shipping_address_2', '_shipping_city', '_shipping_postcode', '_shipping_country', '_shipping_state']); foreach ($searchFields as $key => $value) { $searchFields[$key] = 'post_meta.' . $value; } $searchFields[] = 'order_item_names'; $searchFields[] = '_id'; $query->setQuery(['bool' => ['should' => [['multi_match' => ['fields' => $searchFields, 'type' => 'phrase_prefix', 'analyzer' => 'esi_simple_analyzer', 'query' => $search]], ['multi_match' => ['fields' => $searchFields, 'type' => 'cross_fields', 'operator' => 'and', 'analyzer' => 'esi_simple_analyzer', 'query' => $search]]]]]); if (!$wpQuery->get('orderby')) { $query->setSort('post_date', 'desc'); } }
public static function argS(Query $query, $value, &$q) { $query->setQuery(['bool' => ['should' => [['multi_match' => ['fields' => apply_filters('esi_search_fields_multi_match', ['post_title^10', 'terms.*.name^4', 'post_excerpt^2', 'post_content']), 'query' => $value]], ['fuzzy_like_this' => ['fields' => apply_filters('esi_search_fields_fuzzy', ['post_title', 'post_excerpt']), 'like_text' => $value, 'min_similarity' => apply_filters('esi_min_similarity', 0.75)]]]]]); }