PluginProbe
ElasticPress / 4.7.1
ElasticPress v4.7.1
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / includes / classes / SearchAlgorithm / Version_350.php

Version_350.php in ElasticPress 4.7.1, at includes/classes/SearchAlgorithm/Version_350.php

112 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * EP version 3.5.0 search algorithm
4 *
5 * @since 4.3.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\SearchAlgorithm;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 // @codeCoverageIgnoreStart
13 exit; // Exit if accessed directly.
14 // @codeCoverageIgnoreEnd
15 }
16
17 /**
18 * EP version 3.5.0 search algorithm class.
19 */
20 class Version_350 extends \ElasticPress\SearchAlgorithm {
21 /**
22 * Search algorithm slug.
23 *
24 * @return string
25 */
26 public function get_slug() : string {
27 return '3.5';
28 }
29
30 /**
31 * Search algorithm name.
32 *
33 * @return string
34 */
35 public function get_name() : string {
36 return esc_html__( 'Version 3.5', 'elasticpress' );
37 }
38
39 /**
40 * Search algorithm description.
41 *
42 * @return string
43 */
44 public function get_description() : string {
45 return esc_html__( 'Search for the existence of all words in the search first, then return results based on how closely those words appear.', 'elasticpress' );
46 }
47
48 /**
49 * Return the Elasticsearch `query` clause.
50 *
51 * @param string $indexable_slug Indexable slug
52 * @param string $search_term Search term(s)
53 * @param array $search_fields Search fields
54 * @param array $query_vars Query vars
55 * @return array ES `query`
56 */
57 protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ) : array {
58 $query = [
59 'bool' => [
60 'should' => [
61 [
62 'multi_match' => [
63 'query' => $search_term,
64 'type' => 'phrase',
65 'fields' => $search_fields,
66 /** This filter is documented in /includes/classes/SearchAlgorithm/Basic.php */
67 'boost' => apply_filters( "ep_{$indexable_slug}_match_phrase_boost", 3, $search_fields, $query_vars ),
68 ],
69 ],
70 [
71 'multi_match' => [
72 'query' => $search_term,
73 'fields' => $search_fields,
74 'type' => 'phrase',
75 'slop' => 5,
76 ],
77 ],
78 ],
79 ],
80 ];
81
82 $query = $this->apply_legacy_filters( $query, $indexable_slug, $search_fields, $query_vars );
83
84 return $query;
85 }
86
87 /**
88 * Apply legacy filters.
89 *
90 * @param array $query ES `query`
91 * @param string $indexable_slug Indexable slug
92 * @param array $search_fields Search term(s)
93 * @param array $query_vars Query vars
94 * @return array ES `query`
95 */
96 protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ) : array {
97 if ( 'post' !== $indexable_slug ) {
98 return $query;
99 }
100
101 /** This filter is documented in /includes/classes/SearchAlgorithm/Basic.php */
102 $query['bool']['should'][0]['multi_match']['boost'] = apply_filters_deprecated(
103 'ep_match_phrase_boost',
104 [ $query['bool']['should'][0]['multi_match']['boost'], $search_fields, $query_vars ],
105 '4.3.0',
106 'ep_post_match_phrase_boost'
107 );
108
109 return $query;
110 }
111 }
112