/**
  * A convenient method that aggregates the results of all the other methods in the class. Example of output:
  *
  * <code>
  *    array(
  *        // the keys are names of fields and/or taxonomies
  *        'taxonomy' => array(
  *            'available' => array(
  *                'taxonomy1'    => array(
  *                    'count'    => 10,
  *                    'slug'    => 'taxonomy1',
  *                    'name'    => 'Taxonomy One',
  *                    'font'    => 24
  *                )
  *            ),
  *            'selected' => array(
  *                'taxonomy2'    => array(
  *                    'slug'    => 'taxonomy2',
  *                    'name'    => 'Taxonomy Two'
  *                )
  *            ),
  *            'total' => 10
  *        ),
  *        'rating' => array(
  *            'available' => array(
  *                '10-20' => array(
  *                    'count'    => 4,
  *                    'slug'    => '10-20',
  *                    'to'    => 20,
  *                    'from'    => 10
  *                )
  *            ),
  *            'total' => 4
  *        )
  *    )
  * </code>
  *
  * @param string $minFont The minimum font size to use for display in a tag cloud (defaults to : 12)
  * @param string $maxFont The maximum font size to use for display in a tag cloud (defaults to : 24)
  *
  * @return array An associative array where the keys represent the data point with a list of selected and/or available options.
  **/
 static function all($minFont = 12, $maxFont = 24)
 {
     $options = array();
     foreach (Config::taxonomies() as $tax) {
         $options[$tax] = self::taxonomy($tax);
     }
     $numeric = Config::option('numeric');
     $fields = array_merge(Config::fields(), Config::meta_fields());
     foreach ($fields as $field) {
         if (isset($numeric[$field])) {
             $options[$field] = self::range($field);
         }
         if ($field == 'post_type') {
             $options['post_type'] = self::types(Config::types());
         }
     }
     foreach (Config::customFacets() as $field) {
         $options[$field] = self::custom($field);
     }
     foreach ($options as $name => &$field) {
         if (isset($field['available'])) {
             foreach ($field['available'] as &$available) {
                 $available['font'] = self::cloud($field['available'], $available, $minFont, $maxFont);
             }
         }
     }
     return $options;
 }
 function facets($wp_query, $args)
 {
     if (!is_tax()) {
         return;
     }
     $taxonomies = Config::taxonomies();
     $taxType = null;
     $taxValue = null;
     foreach ($taxonomies as $taxonomy) {
         if (isset($wp_query->query_vars[$taxonomy])) {
             $taxType = $taxonomy;
             $taxValue = $wp_query->query_vars[$taxonomy];
             break;
         }
     }
     if (!$taxType) {
         return $args;
     }
     $args[$taxType]['and'][] = $taxValue;
     return $args;
 }
 /**
  * Add post taxonomies to elasticsearch object
  *
  * @param WP_Post $post
  * @param Array $document to write to es
  * @return Array $document
  * @internal
  **/
 static function _build_tax_values($post, $document)
 {
     if (!isset($post->post_type)) {
         return $document;
     }
     $taxes = array_intersect(Config::taxonomies(), get_object_taxonomies($post->post_type));
     foreach ($taxes as $tax) {
         $document[$tax] = array();
         foreach (wp_get_object_terms($post->ID, $tax) as $term) {
             if (!in_array($term->slug, $document[$tax])) {
                 $document[$tax][] = $term->slug;
                 $document[$tax . '_name'][] = $term->name;
             }
             if (isset($term->parent) && $term->parent) {
                 $parent = get_term($term->parent, $tax);
                 while ($parent != null) {
                     if (!in_array($parent->slug, $document[$tax])) {
                         $document[$tax][] = $parent->slug;
                         $document[$tax . '_name'][] = $parent->name;
                     }
                     if (isset($parent->parent) && $parent->parent) {
                         $parent = get_term($parent->parent, $tax);
                     } else {
                         $parent = null;
                     }
                 }
             }
         }
     }
     return $document;
 }
 /**
  * @internal
  **/
 public static function _buildQuery($search, $facets = array())
 {
     global $blog_id;
     $search = str_ireplace(array(' and ', ' or '), array(' AND ', ' OR '), $search);
     $fields = array();
     $musts = array();
     $filters = array();
     $scored = array();
     foreach (Config::taxonomies() as $tax) {
         if ($search) {
             $score = Config::score('tax', $tax);
             if ($score > 0) {
                 $scored[] = "{$tax}_name^{$score}";
             }
         }
         self::_filterBySelectedFacets($tax, $facets, 'term', $musts, $filters);
     }
     $args = array();
     $numeric = Config::option('numeric');
     $exclude = Config::apply_filters('searcher_query_exclude_fields', array('post_date'));
     $fields = Config::fields();
     self::_searchField($fields, 'field', $exclude, $search, $facets, $musts, $filters, $scored, $numeric);
     self::_searchField(Config::meta_fields(), 'meta', $exclude, $search, $facets, $musts, $filters, $scored, $numeric);
     if (count($scored) > 0 && $search) {
         $qs = array('fields' => $scored, 'query' => $search);
         $fuzzy = Config::option('fuzzy');
         if ($fuzzy && strpos($search, "~") > -1) {
             $qs['fuzzy_min_sim'] = $fuzzy;
         }
         $qs = Config::apply_filters('searcher_query_string', $qs);
         $musts[] = array('query_string' => $qs);
     }
     if (in_array('post_type', $fields)) {
         self::_filterBySelectedFacets('post_type', $facets, 'term', $musts, $filters);
     }
     if (count($filters) > 0) {
         $args['filter']['bool']['should'] = $filters;
     }
     if (count($musts) > 0) {
         $args['query']['bool']['must'] = $musts;
     }
     $args['filter']['bool']['must'][] = array('term' => array('blog_id' => $blog_id));
     $args = Config::apply_filters('searcher_query_pre_facet_filter', $args);
     if (in_array('post_type', $fields)) {
         $args['facets']['post_type']['terms'] = array('field' => 'post_type', 'size' => Config::apply_filters('searcher_query_facet_size', 100));
     }
     // return facets
     foreach (Config::facets() as $facet) {
         $args['facets'][$facet]['terms'] = array('field' => $facet, 'size' => Config::apply_filters('searcher_query_facet_size', 100));
         $args['facets'][$facet]['facet_filter'] = array('bool' => array('must' => array(array('term' => array('blog_id' => $blog_id)))));
         if (count($filters) > 0) {
             $applicable = array();
             foreach ($filters as $filter) {
                 if (isset($filter['term']) && !in_array($facet, array_keys($filter['term']))) {
                     // do not filter on itself when using OR
                     $applicable[] = $filter;
                 }
             }
             if (count($applicable) > 0) {
                 $args['facets'][$facet]['facet_filter']['bool']['should'] = $applicable;
             }
         }
     }
     if (is_array($numeric)) {
         foreach (array_keys($numeric) as $facet) {
             $ranges = Config::ranges($facet);
             if (count($ranges) > 0) {
                 $args['facets'][$facet]['range'][$facet] = array_values($ranges);
                 $args['facets'][$facet]['facet_filter'] = array('bool' => array('must' => array(array('term' => array('blog_id' => $blog_id)))));
             }
         }
     }
     return Config::apply_filters('searcher_query_post_facet_filter', $args);
 }
<?php

namespace elasticsearch;

$fields = array(array('id' => 'fuzzy', 'type' => 'text', 'desc' => 'The number of characters that can be swapped out to match a word. For example; 1 = anoth(a)r~ = anoth(e)r; 2 = (e)noth(a)r~ = (a)noth(e)r; 2 = an()th(u)r~ = an(o)th(e)r. The smaller the number, the better the performance. Leave this blank to disable fuzzy searching. ONLY WORKS FOR VERSIONS > 0.90.1.', 'title' => 'Fuzziness Amount'));
foreach (Config::fields() as $field) {
    $fields[] = array('id' => 'score_field_' . $field, 'type' => 'text', 'validation' => 'numeric', 'desc' => 'A numeric value (if 0, it will have no influence)', 'title' => "Field: {$field}", 'std' => 1);
}
foreach (Config::taxonomies() as $tax) {
    $fields[] = array('id' => 'score_tax_' . $tax, 'type' => 'text', 'validation' => 'numeric', 'desc' => 'A numeric value (if 0, it will have no influence)', 'title' => "Taxonomy: {$tax}", 'std' => 2);
}
foreach (Config::meta_fields() as $field) {
    $fields[] = array('id' => 'score_meta_' . $field, 'type' => 'text', 'validation' => 'numeric', 'desc' => 'A numeric value (if 0, it will have no influence)', 'title' => "Meta: {$field}", 'std' => 3);
}
$sections['scoring'] = array('icon' => NHP_OPTIONS_URL . 'img/glyphicons/glyphicons_079_signal.png', 'title' => 'Result Scoring', 'desc' => 'When executing a search, not all content is created equal. Review each of the items that are indexed and order them by the most relevant/important to least relevant/important.', 'fields' => $fields);
 public function testTaxonomiesDefault()
 {
     register_post_type('post');
     register_taxonomy('tax1', 'post');
     register_taxonomy('tax2', 'post');
     $this->assertEquals(array('tax1', 'tax2'), Config::taxonomies());
 }