コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Add post meta values to elasticsearch object, only if they are present.
  *
  * @param WP_Post $post
  * @param Array $document to write to es
  * @return Array $document
  * @internal
  **/
 static function _build_meta_values($post, $document)
 {
     $keys = get_post_custom_keys($post->ID);
     if (is_array($keys)) {
         $meta_fields = array_intersect(Config::meta_fields(), $keys);
         foreach ($meta_fields as $field) {
             $val = get_post_meta($post->ID, $field, true);
             if (isset($val)) {
                 $document[$field] = $val;
             }
         }
     }
     return $document;
 }
コード例 #3
0
<?php

namespace elasticsearch;

$fields = array('numeric' => array('id' => 'numeric', 'type' => 'multi_checkbox', 'title' => 'Numeric Fields', 'desc' => 'Any field marked as "numeric" will enabled support for range faceting.', 'options' => array()), 'not_analyzed' => array('id' => 'not_analyzed', 'type' => 'multi_checkbox', 'title' => 'Non Analyzed Fields', 'options' => array(), 'desc' => 'Any string field marked as "non analyzed" will require search terms to match the entire value instead of any words in the value.'));
foreach (array_merge(Config::fields(), Config::meta_fields()) as $field) {
    if ($field != 'post_date' && $field != 'post_type') {
        $fields['numeric']['options'][$field] = $field;
        $fields['not_analyzed']['options'][$field] = $field;
    }
}
$numeric_option = Config::option('numeric');
if ($numeric_option) {
    foreach (array_keys($numeric_option) as $numeric) {
        $fields[$numeric . '_range'] = array('id' => $numeric . '_range', 'type' => 'text', 'title' => $numeric . ' Range', 'desc' => 'Comma delimited list of ranges for this field using the format of FROM-TO. Currently ranges are always inclusive., ie: "-10,10-50,50-" or "-5,6-,7-,8-,9-"');
    }
}
$sections['field'] = array('icon' => NHP_OPTIONS_URL . 'img/glyphicons/glyphicons_097_vector_path_line.png', 'title' => 'Field Mapping', 'desc' => 'Finer grain control over how data is interpreted inside of ElasticSearch. Any changes made in this tab will require you to clear then re-index your data.', 'fields' => $fields);
コード例 #4
0
 /**
  * @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);
 }
コード例 #5
0
<?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);
コード例 #6
0
 public function testMetaKeysUndefined()
 {
     $this->assertEquals(array(), Config::meta_fields());
 }