Skip to content

Commit

Permalink
PLANET-6652: Extract search filters (#1691)
Browse files Browse the repository at this point in the history
* PLANET-6552: Extract search filters

- Extract search filters to their own classes
- Use consistent taxonomy
- Remove tags in search template
- Add p4_action type to search filters and template
- Remove act pages filter and various exceptions
- Reduce label definition code
  • Loading branch information
lithrel authored Jun 14, 2022
1 parent 69b0ccd commit 1f17a38
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 271 deletions.
50 changes: 12 additions & 38 deletions src/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,13 @@ public function set_filters_args( &$args ) {
case 'cat':
case 'tag':
case 'ptype':
case 'atype':
break;
case 'ctype':
switch ( $filter['id'] ) {
case 0:
case 1:
break;
case 2:
// Workaround for making 'post_parent__not_in' to work with ES.
add_filter(
'ep_formatted_args',
function ( $formatted_args ) use ( $args ) {
// Make sure it is not an Action page.
if ( ! empty( $args['post_parent__not_in'] ) ) {
$formatted_args['post_filter']['bool']['must_not'][] = [
'terms' => [
'post_parent' => array_values( (array) $args['post_parent__not_in'] ),
],
];
}
return $formatted_args;
},
10,
1
);
break;
case 3:
case 4:
Expand All @@ -72,6 +55,7 @@ function ( $formatted_args ) use ( $args ) {
);
break;
case 5:
case 6:
break;
default:
throw new UnexpectedValueException( 'Unexpected content type!' );
Expand Down Expand Up @@ -174,21 +158,6 @@ public function set_results_weight( $formatted_args ) {
],
);

$act_page = planet4_get_option( 'act_page', null );
if ( $act_page ) {
array_push(
$formatted_args['query']['function_score']['functions'],
[
'filter' => [
'term' => [
'post_parent' => esc_sql( $act_page ),
],
],
'weight' => self::DEFAULT_ACTION_WEIGHT,
],
);
}

// Specify how the computed scores are combined.
$formatted_args['query']['function_score']['score_mode'] = 'sum';

Expand All @@ -212,31 +181,36 @@ public function add_aggregations( $formatted_args ) {
'with_post_filter' => [
'filter' => $formatted_args['post_filter'],
'aggs' => [
'post_type' => [
'post_type' => [
'terms' => [
'field' => 'post_type.raw',
],
],
'post_parent' => [
'post_parent' => [
'terms' => [
'field' => 'post_parent',
],
],
'categories' => [
'categories' => [
'terms' => [
'field' => 'terms.category.term_id',
],
],
'tags' => [
'tags' => [
'terms' => [
'field' => 'terms.post_tag.term_id',
],
],
'p4-page-type' => [
'p4-page-type' => [
'terms' => [
'field' => 'terms.p4-page-type.term_id',
],
],
ActionPage::TAXONOMY => [
'terms' => [
'field' => 'terms.' . ActionPage::TAXONOMY . '.term_id',
],
],
],
],
];
Expand Down
Loading

0 comments on commit 1f17a38

Please sign in to comment.