/** * Test to make custom field a facet. * @group 37 */ function test_custom_field_facet() { // Set 'my_field' as a custom field facet. $this->__change_option('s4wp_facet_on_custom_fields', array('my_field')); $this->__change_option('s4wp_index_custom_fields', array('my_field')); $this->__setup_custom_fields(); $this->__facet_query(); $facets = SolrPower_WP_Query::get_instance()->facets; $this->assertNotEmpty($facets); $this->assertArrayHasKey('my_field_str', $facets); $this->assertArrayNotHasKey('other_field_str', $facets); $data = $facets['my_field_str']->getValues(); $this->assertArrayHasKey('my_value', $data); $this->assertArrayHasKey('my_value2', $data); $this->assertArrayHasKey('my_value3', $data); }
if ('post_date' == $key || 'post_modified' == $key) { continue; } if ('post_id' == $key) { $post->ID = $value; continue; } $post->{$key} = $value; } $post->solr = true; $posts[] = $post; } $this->found_posts[spl_object_hash($query)] = $posts; global $wpdb; return "SELECT * FROM {$wpdb->posts} WHERE 1=0"; } function found_posts_query($sql, $query) { return ''; } function the_posts($posts, &$query) { if (!isset($this->found_posts[spl_object_hash($query)])) { return $posts; } $new_posts = $this->found_posts[spl_object_hash($query)]; return $new_posts; } } SolrPower_WP_Query::get_instance();
/** * Fetches and displays returned facets. */ function fetch_facets() { $solr_options = solr_options(); if (!$solr_options['s4wp_output_facets']) { return; } $facets = SolrPower_WP_Query::get_instance()->facets; foreach ($facets as $facet_name => $data) { if (false === $this->show_facet($facet_name)) { continue; } /** * Filter facet HTML * * Filter the HTML output of a facet. * * @param string $facet_name the facet name. * * @param object $data the Solarium facet data object. */ $html = apply_filters('solr_facet_items', false, $facet_name, $data); if ($html) { echo $html; continue; } /** * Filter facet title * * Filter the facet title displayed in the widget. * * @param boolean|string the custom facet title, defaults to false. * * @param string $facet_name the facet name. * */ $facet_nice_name = apply_filters('solr_facet_title', false, $facet_name); if (false === $facet_nice_name) { $replace = array('/\\_taxonomy/', '/\\_str/', '/\\_/'); $facet_nice_name = ucwords(preg_replace($replace, ' ', $facet_name)); } $values = $data->getValues(); if (0 === count($values)) { continue; } echo '<h2>' . esc_html($facet_nice_name) . '</h2>'; echo '<ul>'; foreach ($values as $name => $count) { $nice_name = str_replace('^^', '', $name); $checked = ''; if (isset($this->facets[$facet_name]) && in_array(htmlspecialchars_decode($name), $this->facets[$facet_name])) { $checked = checked(true, true, false); } echo '<li>'; echo '<input type="checkbox" name="facet[' . esc_attr($facet_name) . '][]" value="' . esc_attr($name) . '" ' . $checked . '> '; echo esc_html($nice_name); echo ' (' . esc_html($count) . ')'; echo '</li>'; } echo '</ul>'; echo '<a href="' . $this->reset_url($facet_name) . '">Reset</a>'; } }