/**
  * 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;
 }
Exemple #2
0
 function delete_post($post_id)
 {
     if (is_object($post_id)) {
         $post = $post_id;
     } else {
         $post = get_post($post_id);
     }
     if ($post == null || !in_array($post->post_type, Config::types())) {
         return;
     }
     Indexer::delete($post);
 }
 /**
  * Create new ES field mappings for the given fields from the configuration
  * TODO align callback names with Config::names so we can simply call this method with the kind string
  * @param array $config_fields
  * @param string $kind of internal fields: meta|field|taxonomy used to call the right indexer_map filter
  */
 static function _map_values($config_fields, $kind)
 {
     $index = self::_index(false);
     $numeric = Config::option('numeric');
     $notanalyzed = Config::option('not_analyzed');
     foreach ($config_fields as $field) {
         // set default
         $props = array('type' => 'string');
         // detect special field type
         if (isset($numeric[$field])) {
             $props['type'] = 'float';
         } elseif (isset($notanalyzed[$field]) || $kind == 'taxonomy') {
             $props['index'] = 'not_analyzed';
         } elseif ($field == 'post_date') {
             $props['type'] = 'date';
             $props['format'] = 'date_time_no_millis';
         } else {
             $props['index'] = 'analyzed';
         }
         if ($props['type'] == 'string' && $props['index'] == 'analyzed') {
             // provides more accurate searches
             // TODO: assumes plugin users are in english
             $lang = Config::apply_filters('string_language', 'english');
             $props = array('type' => 'multi_field', 'fields' => array($field => $props, $lang => array_merge($props, array('analyzer' => $lang))));
         }
         // generic filter indexer_map_field| indexer_map_meta | indexer_map_taxonomy
         $props = Config::apply_filters('indexer_map_' . $kind, $props, $field);
         // also index taxonomy_name field
         if ($kind == 'taxonomy') {
             $tax_name_props = array('type' => 'string');
             $tax_name_props = Config::apply_filters('indexer_map_taxonomy_name', $tax_name_props, $field);
         }
         foreach (Config::types() as $type) {
             $type = $index->getType($type);
             $mapping = new \Elastica\Type\Mapping($type);
             $mapping->setProperties(array($field => $props));
             $mapping->send();
             // second mapping for taxonomy_name
             if (isset($tax_name_props)) {
                 $mapping = new \Elastica\Type\Mapping($type);
                 $mapping->setProperties(array($field . '_name' => $tax_name_props));
                 $mapping->send();
             }
         }
     }
 }
 /**
  * Reads F.E.S configuration and updates ElasticSearch field mapping information (this can corrupt existing data).
  * @internal
  **/
 static function _map($index = null)
 {
     $index = $index ?: self::_index(true);
     foreach (Config::types() as $postType) {
         $type = $index->getType($postType);
         $properties = array();
         self::_map_values($properties, $type, Config::taxonomies(), 'taxonomy');
         self::_map_values($properties, $type, Config::fields(), 'field');
         self::_map_values($properties, $type, Config::meta_fields(), 'meta');
         $properties = Config::apply_filters('indexer_map', $properties, $postType);
         $mapping = new \Elastica\Type\Mapping($type, $properties);
         $mapping->send();
     }
 }
Exemple #5
0
 /**
  * Reads F.E.S configuration and updates ElasticSearch field mapping information (this can corrupt existing data).
  * @internal
  **/
 static function _map()
 {
     $index = self::_index(false);
     foreach (Config::types() as $type) {
         $type = $index->getType($type);
         $properties = array();
         self::_map_values($properties, $type, Config::taxonomies(), 'taxonomy');
         self::_map_values($properties, $type, Config::fields(), 'field');
         self::_map_values($properties, $type, Config::meta_fields(), 'meta');
         $mapping = new \Elastica\Type\Mapping($type, $properties);
         $mapping->send();
     }
 }
Exemple #6
0
 public function testGetPosts()
 {
     register_post_type('post');
     $this->assertEquals(array('posts_per_page' => 10, 'post_type' => Config::types(), 'paged' => 2, 'post_status' => 'publish'), Indexer::get_posts(2));
 }
 public function testTypesDefined()
 {
     update_option('types', array('post' => 1, 'review' => 1));
     $this->assertEquals(array('post', 'review'), Config::types());
 }