Relevanssi – A Better Search - Version 2.20.0

Version Description

Download this release

Release Info

Developer msaari
Plugin Icon 128x128 Relevanssi – A Better Search
Version 2.20.0
Comparing to
See all releases

Code changes from version 4.17.1 to 2.20.0

changelog.txt CHANGED
@@ -1,3 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 4.14.7 =
2
  * User interface: The synonym settings page now alerts if the synonyms aren't active because of the AND search.
3
 
1
+ = 4.15.2 =
2
+ * New feature: New filter hook `relevanssi_didyoumean_token` lets you filter Did you mean words before correction. You can use this filter hook to exclude words from being corrected.
3
+ * Minor fix: Phrase search couldn't find phrases that include an ampersand if they matched the post title. This works now.
4
+ * Minor fix: Relevanssi now adds spaces after table cell tags to avoid table cell content sticking together in excerpts.
5
+ * Minor fix: The 'Allowable tags in excerpts' function now automatically corrects the entered value to match what Relevanssi expects the value to be.
6
+
7
+ = 4.15.1 =
8
+ * Changed behaviour: Relevanssi now ignores WordPress metadata custom fields that aren't interesting for Relevanssi indexing.
9
+ * Changed behaviour: Both `relevanssi_get_permalink()` and `relevanssi_the_permalink()` now can take post ID or a post object as a parameter and can thus be used outside the Loop.
10
+ * Changed behaviour: The `relevanssi_hits_filter` hook now gets the WP_Query object as the second parameter.
11
+ * Minor fix: Avoid error messages for missing `mysqlcolumn_matches` array key.
12
+
13
+ = 4.15.0 =
14
+ * New feature: The action hook `relevanssi_init` runs at the end of the `relevanssi_init()` function.
15
+ * New feature: New filter hook `relevanssi_author_query_filter` filters the post author MySQL query.
16
+ * New feature: New filter hook `relevanssi_by_date_query_filter` filters the by_date MySQL query.
17
+ * New feature: New filter hook `relevanssi_date_query_filter` filters the date query MySQL query.
18
+ * New feature: New filter hook `relevanssi_parent_query_filter` filters the post parent MySQL query.
19
+ * New feature: New filter hook `relevanssi_post_query_filter` filters the post__in and post__not_in MySQL query.
20
+ * New feature: New filter hook `relevanssi_post_status_query_filter` filters the post_status MySQL query.
21
+ * New feature: New filter hook `relevanssi_post_type_query_filter` filters the post_type MySQL query.
22
+ * Minor fix: The Bricks compatibility was improved, Relevanssi now notices changes to Bricks posts more often. Relevanssi also only reads the text from the `_bricks_page_content_2` custom field.
23
+
24
  = 4.14.7 =
25
  * User interface: The synonym settings page now alerts if the synonyms aren't active because of the AND search.
26
 
lib/common.php CHANGED
@@ -984,7 +984,7 @@ function relevanssi_add_highlight( $permalink, $link_post = null ) {
984
  if ( isset( $highlight_docs ) && 'off' !== $highlight_docs && ! empty( $query ) ) {
985
  if ( ! relevanssi_is_front_page_id( $link_post->ID ?? null ) ) {
986
  global $wp_query;
987
- if ( isset( $wp_query->query_vars['sentence'] ) && '"' !== substr( $query, 0, 6 ) ) {
988
  $query = relevanssi_add_quotes( $query );
989
  }
990
  $query = str_replace( '"', '"', $query );
@@ -1067,7 +1067,7 @@ function relevanssi_permalink( $link, $link_post = null ) {
1067
  $link = relevanssi_add_highlight( $link, $link_post );
1068
  }
1069
 
1070
- if ( $add_highlight_and_tracking && function_exists( 'relevanssi_add_tracking' ) ) {
1071
  $link = relevanssi_add_tracking( $link, $link_post );
1072
  }
1073
 
984
  if ( isset( $highlight_docs ) && 'off' !== $highlight_docs && ! empty( $query ) ) {
985
  if ( ! relevanssi_is_front_page_id( $link_post->ID ?? null ) ) {
986
  global $wp_query;
987
+ if ( ! empty( $wp_query->query_vars['sentence'] ) && '"' !== substr( $query, 0, 6 ) ) {
988
  $query = relevanssi_add_quotes( $query );
989
  }
990
  $query = str_replace( '"', '"', $query );
1067
  $link = relevanssi_add_highlight( $link, $link_post );
1068
  }
1069
 
1070
+ if ( $add_highlight_and_tracking && function_exists( 'relevanssi_add_tracking' ) && property_exists( $link_post, 'relevance_score' ) ) {
1071
  $link = relevanssi_add_tracking( $link, $link_post );
1072
  }
1073
 
lib/compatibility/acf.php CHANGED
@@ -10,7 +10,9 @@
10
  * @see https://www.relevanssi.com/
11
  */
12
 
 
13
  add_filter( 'relevanssi_search_ok', 'relevanssi_acf_relationship_fields' );
 
14
 
15
  /**
16
  * Disables Relevanssi in the ACF Relationship field post search.
@@ -110,3 +112,50 @@ function relevanssi_index_acf( &$insert_data, $post_id, $field_name, $field_valu
110
 
111
  return $n;
112
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  * @see https://www.relevanssi.com/
11
  */
12
 
13
+ add_action( 'acf/render_field_settings', 'relevanssi_acf_exclude_setting' );
14
  add_filter( 'relevanssi_search_ok', 'relevanssi_acf_relationship_fields' );
15
+ add_filter( 'relevanssi_index_custom_fields', 'relevanssi_acf_exclude_fields' );
16
 
17
  /**
18
  * Disables Relevanssi in the ACF Relationship field post search.
112
 
113
  return $n;
114
  }
115
+
116
+ /**
117
+ * Adds a Relevanssi exclude setting to ACF fields.
118
+ *
119
+ * @param array $field The field object array.
120
+ */
121
+ function relevanssi_acf_exclude_setting( $field ) {
122
+ if ( ! function_exists( 'acf_render_field_setting' ) ) {
123
+ return;
124
+ }
125
+ acf_render_field_setting(
126
+ $field,
127
+ array(
128
+ 'label' => __( 'Exclude from Relevanssi index', 'relevanssi' ),
129
+ 'instructions' => __( 'If this setting is enabled, Relevanssi will not index the value of this field for posts.', 'relevanssi' ),
130
+ 'name' => 'relevanssi_exclude',
131
+ 'type' => 'true_false',
132
+ 'ui' => 1,
133
+ ),
134
+ true
135
+ );
136
+ }
137
+
138
+ /**
139
+ * Excludes ACF fields based on the exclude setting.
140
+ *
141
+ * Hooks on to relevanssi_index_custom_fields.
142
+ *
143
+ * @param array $fields The list of custom fields to index.
144
+ *
145
+ * @return array Filtered list of custom fields.
146
+ */
147
+ function relevanssi_acf_exclude_fields( $fields ) {
148
+ $included_fields = array();
149
+ foreach ( $fields as $field ) {
150
+ $field_object = get_field_object( $field );
151
+ if ( ! $field_object || ! is_array( $field_object ) ) {
152
+ $included_fields[] = $field;
153
+ } else {
154
+ if ( isset( $field_object['relevanssi_exclude'] ) && 1 === $field_object['relevanssi_exclude'] ) {
155
+ continue;
156
+ }
157
+ $included_fields[] = $field;
158
+ }
159
+ }
160
+ return $included_fields;
161
+ }
lib/compatibility/gutenberg.php CHANGED
@@ -10,6 +10,8 @@
10
  * @see https://www.relevanssi.com/
11
  */
12
 
 
 
13
  /**
14
  * Registers rest_after_insert_{post_type} actions for all indexed post types.
15
  *
@@ -37,8 +39,6 @@ function relevanssi_register_gutenberg_actions() {
37
  );
38
  }
39
 
40
- add_filter( 'relevanssi_post_content', 'relevanssi_gutenberg_block_rendering', 10, 2 );
41
-
42
  /**
43
  * Renders Gutenberg blocks.
44
  *
10
  * @see https://www.relevanssi.com/
11
  */
12
 
13
+ add_filter( 'relevanssi_post_content', 'relevanssi_gutenberg_block_rendering', 10, 2 );
14
+
15
  /**
16
  * Registers rest_after_insert_{post_type} actions for all indexed post types.
17
  *
39
  );
40
  }
41
 
 
 
42
  /**
43
  * Renders Gutenberg blocks.
44
  *
lib/excerpts-highlights.php CHANGED
@@ -1566,7 +1566,7 @@ function relevanssi_add_excerpt( &$post, $query ) {
1566
  */
1567
  function relevanssi_entity_decode( $content, $flags = ENT_QUOTES, $charset = 'UTF-8' ) {
1568
  $content = html_entity_decode( $content, $flags, $charset );
1569
- if ( preg_match_all( '/data-.+?="(.*?)"/sm', $content, $matches ) ) {
1570
  $source = array();
1571
  $replace = array();
1572
  foreach ( $matches[1] as $match ) {
1566
  */
1567
  function relevanssi_entity_decode( $content, $flags = ENT_QUOTES, $charset = 'UTF-8' ) {
1568
  $content = html_entity_decode( $content, $flags, $charset );
1569
+ if ( preg_match_all( '/data-[\w-]+?="([^"]*?)"/sm', $content, $matches ) ) {
1570
  $source = array();
1571
  $replace = array();
1572
  foreach ( $matches[1] as $match ) {
lib/log.php CHANGED
@@ -322,3 +322,45 @@ function relevanssi_is_ok_to_log( $user = null ) : bool {
322
 
323
  return true;
324
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
 
323
  return true;
324
  }
325
+
326
+ /**
327
+ * Deletes a query from log.
328
+ *
329
+ * @param string $query The query to delete.
330
+ */
331
+ function relevanssi_delete_query_from_log( string $query ) {
332
+ global $wpdb, $relevanssi_variables;
333
+
334
+ $deleted = $wpdb->query(
335
+ $wpdb->prepare(
336
+ "DELETE FROM {$relevanssi_variables['log_table']} WHERE query = %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared
337
+ $query
338
+ )
339
+ );
340
+
341
+ if ( $deleted ) {
342
+ printf(
343
+ "<div id='message' class='updated fade'><p>%s</p></div>",
344
+ sprintf(
345
+ // Translators: %s is the stopword.
346
+ esc_html__(
347
+ "The query '%s' deleted from the log.",
348
+ 'relevanssi'
349
+ ),
350
+ esc_html( stripslashes( $query ) )
351
+ )
352
+ );
353
+ } else {
354
+ printf(
355
+ "<div id='message' class='updated fade'><p>%s</p></div>",
356
+ sprintf(
357
+ // Translators: %s is the stopword.
358
+ esc_html__(
359
+ "Couldn't remove the query '%s' from the log.",
360
+ 'relevanssi'
361
+ ),
362
+ esc_html( stripslashes( $query ) )
363
+ )
364
+ );
365
+ }
366
+ }
lib/search.php CHANGED
@@ -149,9 +149,10 @@ function relevanssi_search( $args ) {
149
  }
150
 
151
  if ( function_exists( 'relevanssi_process_terms' ) ) {
152
- $process_terms_results = relevanssi_process_terms( $terms['terms'], $q );
153
- $query_restrictions .= $process_terms_results['query_restrictions'];
154
- $terms['terms'] = $process_terms_results['terms'];
 
155
  }
156
 
157
  $no_terms = false;
@@ -921,7 +922,7 @@ function relevanssi_compile_search_args( $query, $q ) {
921
  // Tax query is empty, let's get rid of it.
922
  $query->tax_query = null;
923
  }
924
- if ( isset( $query->query_vars['tax_query'] ) ) {
925
  // This is user-created tax_query array as described in WP Codex.
926
  foreach ( $query->query_vars['tax_query'] as $type => $item ) {
927
  if ( is_string( $type ) && 'relation' === $type ) {
149
  }
150
 
151
  if ( function_exists( 'relevanssi_process_terms' ) ) {
152
+ $process_terms_results = relevanssi_process_terms( $terms['terms'], $terms['original_terms'], $q );
153
+ $query_restrictions .= $process_terms_results['query_restrictions'];
154
+ $terms['terms'] = $process_terms_results['terms'];
155
+ $terms['original_terms'] = $process_terms_results['original_terms'];
156
  }
157
 
158
  $no_terms = false;
922
  // Tax query is empty, let's get rid of it.
923
  $query->tax_query = null;
924
  }
925
+ if ( ! empty( $query->query_vars['tax_query'] ) ) {
926
  // This is user-created tax_query array as described in WP Codex.
927
  foreach ( $query->query_vars['tax_query'] as $type => $item ) {
928
  if ( is_string( $type ) && 'relation' === $type ) {
lib/tabs/debugging-tab.php CHANGED
@@ -125,6 +125,26 @@ function relevanssi_debugging_tab() {
125
 
126
  <?php echo $db_post_view; // phpcs:ignore WordPress.Security.EscapeOutput ?>
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  <?php do_action( 'relevanssi_debugging_tab' ); ?>
129
 
130
  <?php
125
 
126
  <?php echo $db_post_view; // phpcs:ignore WordPress.Security.EscapeOutput ?>
127
 
128
+ <h2><?php esc_html_e( 'Debugging information', 'relevanssi' ); ?></h2>
129
+
130
+ <?php
131
+ global $wpdb;
132
+ $max_allowed_packet = $wpdb->get_var( 'SELECT @@global.max_allowed_packet' );
133
+ $max_allowed_packet = round( $max_allowed_packet / 1024 / 1024, 2 );
134
+ echo '<p>max_allowed_packet: ' . $max_allowed_packet . 'M</p>'; // phpcs:ignore WordPress.Security.EscapeOutput
135
+
136
+ $indexing_query = relevanssi_generate_indexing_query(
137
+ relevanssi_valid_status_array(),
138
+ false,
139
+ relevanssi_post_type_restriction(),
140
+ 0
141
+ );
142
+ ?>
143
+ <p><?php esc_html_e( 'Indexing query', 'relevanssi' ); ?>:</p>
144
+ <?php
145
+ echo '<code>' . $indexing_query . '</code>'; // phpcs:ignore WordPress.Security.EscapeOutput
146
+ ?>
147
+
148
  <?php do_action( 'relevanssi_debugging_tab' ); ?>
149
 
150
  <?php
lib/tabs/overview-tab.php CHANGED
@@ -33,6 +33,9 @@ function relevanssi_overview_tab() {
33
  if ( function_exists( 'relevanssi_form_do_not_call_home' ) ) {
34
  relevanssi_form_do_not_call_home();
35
  }
 
 
 
36
  ?>
37
  <tr>
38
  <th scope="row"><?php esc_html_e( 'Getting started', 'relevanssi' ); ?></th>
33
  if ( function_exists( 'relevanssi_form_do_not_call_home' ) ) {
34
  relevanssi_form_do_not_call_home();
35
  }
36
+ if ( function_exists( 'relevanssi_form_update_translations' ) ) {
37
+ relevanssi_form_update_translations();
38
+ }
39
  ?>
40
  <tr>
41
  <th scope="row"><?php esc_html_e( 'Getting started', 'relevanssi' ); ?></th>
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: msaari
3
  Donate link: https://www.relevanssi.com/buy-premium/
4
  Tags: search, relevance, better search, product search, woocommerce search
5
  Requires at least: 4.9
6
- Tested up to: 6.0
7
  Requires PHP: 7.0
8
- Stable tag: 4.17.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -128,6 +128,14 @@ Each document database is full of useless words. All the little words that appea
128
  * John Calahan for extensive 4.0 beta testing.
129
 
130
  == Changelog ==
 
 
 
 
 
 
 
 
131
  = 4.17.1 =
132
  * Minor fix: WooCommerce layered navigation compatibility caused enough problems that I've disabled it by default. You can enable it with `add_filter( 'woocommerce_get_filtered_term_product_counts_query', 'relevanssi_filtered_term_product_counts_query' );`.
133
  * Minor fix: Data attribute handling for in-document highlighting is now better.
@@ -164,35 +172,12 @@ Each document database is full of useless words. All the little words that appea
164
  * Minor fix: Phrases weren't used in some cases where a multiple-word phrase looked like a single-word phrase.
165
  * Minor fix: Prevents fatal errors from `relevanssi_strip_all_tags()`.
166
 
167
- = 4.15.2 =
168
- * New feature: New filter hook `relevanssi_didyoumean_token` lets you filter Did you mean words before correction. You can use this filter hook to exclude words from being corrected.
169
- * Minor fix: Phrase search couldn't find phrases that include an ampersand if they matched the post title. This works now.
170
- * Minor fix: Relevanssi now adds spaces after table cell tags to avoid table cell content sticking together in excerpts.
171
- * Minor fix: The 'Allowable tags in excerpts' function now automatically corrects the entered value to match what Relevanssi expects the value to be.
172
-
173
- = 4.15.1 =
174
- * Changed behaviour: Relevanssi now ignores WordPress metadata custom fields that aren't interesting for Relevanssi indexing.
175
- * Changed behaviour: Both `relevanssi_get_permalink()` and `relevanssi_the_permalink()` now can take post ID or a post object as a parameter and can thus be used outside the Loop.
176
- * Changed behaviour: The `relevanssi_hits_filter` hook now gets the WP_Query object as the second parameter.
177
- * Minor fix: Avoid error messages for missing `mysqlcolumn_matches` array key.
178
-
179
- = 4.15.0 =
180
- * New feature: The action hook `relevanssi_init` runs at the end of the `relevanssi_init()` function.
181
- * New feature: New filter hook `relevanssi_author_query_filter` filters the post author MySQL query.
182
- * New feature: New filter hook `relevanssi_by_date_query_filter` filters the by_date MySQL query.
183
- * New feature: New filter hook `relevanssi_date_query_filter` filters the date query MySQL query.
184
- * New feature: New filter hook `relevanssi_parent_query_filter` filters the post parent MySQL query.
185
- * New feature: New filter hook `relevanssi_post_query_filter` filters the post__in and post__not_in MySQL query.
186
- * New feature: New filter hook `relevanssi_post_status_query_filter` filters the post_status MySQL query.
187
- * New feature: New filter hook `relevanssi_post_type_query_filter` filters the post_type MySQL query.
188
- * Minor fix: The Bricks compatibility was improved, Relevanssi now notices changes to Bricks posts more often. Relevanssi also only reads the text from the `_bricks_page_content_2` custom field.
189
-
190
  == Upgrade notice ==
 
 
 
191
  = 4.17.1 =
192
  * Disables the WooCommerce layered navigation support by default.
193
 
194
  = 4.17.0 =
195
- * Large number of bug fixes and general improvements.
196
-
197
- = 4.16.0 =
198
- * Indexing update; please reindex after the upgrade! Oxygen 4 compatibility.
3
  Donate link: https://www.relevanssi.com/buy-premium/
4
  Tags: search, relevance, better search, product search, woocommerce search
5
  Requires at least: 4.9
6
+ Tested up to: 6.1
7
  Requires PHP: 7.0
8
+ Stable tag: 4.18.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
128
  * John Calahan for extensive 4.0 beta testing.
129
 
130
  == Changelog ==
131
+ = 4.18.0 =
132
+ * New feature: Relevanssi now shows the MySQL `max_allowed_packet` size on the debug tab.
133
+ * New feature: Relevanssi now shows the indexing query on the debug tab.
134
+ * New feature: ACF field settings now include a 'Exclude from Relevanssi index' setting. You can use that to exclude ACF fields from the Relevanssi index.
135
+ * Minor fix: Relevanssi was adding extra quotes around search terms in the `highlight` parameter.
136
+ * Minor fix: Yet another update to data attributes in highlighting. Thanks to Faeddur.
137
+ * Minor fix: Taxonomy query handling was improved. This should help in particular Polylang users who've had problems with Relevanssi ignoring Polylang language restrictions.
138
+
139
  = 4.17.1 =
140
  * Minor fix: WooCommerce layered navigation compatibility caused enough problems that I've disabled it by default. You can enable it with `add_filter( 'woocommerce_get_filtered_term_product_counts_query', 'relevanssi_filtered_term_product_counts_query' );`.
141
  * Minor fix: Data attribute handling for in-document highlighting is now better.
172
  * Minor fix: Phrases weren't used in some cases where a multiple-word phrase looked like a single-word phrase.
173
  * Minor fix: Prevents fatal errors from `relevanssi_strip_all_tags()`.
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  == Upgrade notice ==
176
+ = 4.18.0 =
177
+ * Debugging features, improved ACF support and bug fixes.
178
+
179
  = 4.17.1 =
180
  * Disables the WooCommerce layered navigation support by default.
181
 
182
  = 4.17.0 =
183
+ * Large number of bug fixes and general improvements.
 
 
 
relevanssi.php CHANGED
@@ -13,7 +13,7 @@
13
  * Plugin Name: Relevanssi
14
  * Plugin URI: https://www.relevanssi.com/
15
  * Description: This plugin replaces WordPress search with a relevance-sorting search.
16
- * Version: 4.17.1
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
@@ -67,7 +67,7 @@ $relevanssi_variables['database_version'] = 6;
67
  $relevanssi_variables['file'] = __FILE__;
68
  $relevanssi_variables['plugin_dir'] = plugin_dir_path( __FILE__ );
69
  $relevanssi_variables['plugin_basename'] = plugin_basename( __FILE__ );
70
- $relevanssi_variables['plugin_version'] = '4.17.1';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';
13
  * Plugin Name: Relevanssi
14
  * Plugin URI: https://www.relevanssi.com/
15
  * Description: This plugin replaces WordPress search with a relevance-sorting search.
16
+ * Version: 4.18.0
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
67
  $relevanssi_variables['file'] = __FILE__;
68
  $relevanssi_variables['plugin_dir'] = plugin_dir_path( __FILE__ );
69
  $relevanssi_variables['plugin_basename'] = plugin_basename( __FILE__ );
70
+ $relevanssi_variables['plugin_version'] = '4.18.0';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';