Relevanssi – A Better Search - Version 4.8.1

Version Description

  • Major fix: Changes in WooCommerce 4.4.0 broke the Relevanssi searches. This makes the WooCommerce search work again.
  • Minor fix: Excluding from logs didn't work if user IDs had spaces between them ('user_a, user_b'). Now the extra spaces don't matter.
  • Minor fix: The asynchronous doc count action in the previous version could cause an infinite loop with the Snitch logger plugin. This is prevented now: the async action doesn't run after indexing unless a post is actually indexed.
  • Minor fix: Relevanssi indexing procedure was triggered for autosaved drafts, causing possible problems with the asynchronous doc count action.
  • Minor fix: The relevanssi_index_custom_fields filter hook was not applied when doing phrase matching, thus phrases could not be found when they were in custom fields added with the filter.
Download this release

Release Info

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

Code changes from version 4.8.0 to 4.8.1

lib/admin-ajax.php CHANGED
@@ -15,6 +15,7 @@ add_action( 'wp_ajax_relevanssi_count_missing_posts', 'relevanssi_count_missing_
15
  add_action( 'wp_ajax_relevanssi_list_categories', 'relevanssi_list_categories' );
16
  add_action( 'wp_ajax_relevanssi_admin_search', 'relevanssi_admin_search' );
17
  add_action( 'wp_ajax_relevanssi_update_counts', 'relevanssi_update_counts' );
 
18
 
19
  /**
20
  * Truncates the Relevanssi index.
15
  add_action( 'wp_ajax_relevanssi_list_categories', 'relevanssi_list_categories' );
16
  add_action( 'wp_ajax_relevanssi_admin_search', 'relevanssi_admin_search' );
17
  add_action( 'wp_ajax_relevanssi_update_counts', 'relevanssi_update_counts' );
18
+ add_action( 'wp_ajax_nopriv_relevanssi_update_counts', 'relevanssi_update_counts' );
19
 
20
  /**
21
  * Truncates the Relevanssi index.
lib/common.php CHANGED
@@ -414,8 +414,9 @@ function relevanssi_recognize_phrases( $search_query, $operator = 'AND' ) {
414
  return $all_queries;
415
  }
416
 
 
 
417
  $taxonomies = get_option( 'relevanssi_index_taxonomies_list', array() );
418
- $custom_fields = relevanssi_get_custom_fields();
419
  $excerpts = get_option( 'relevanssi_index_excerpt', 'off' );
420
  $index_pdf_parent = get_option( 'relevanssi_index_pdf_parent' );
421
 
@@ -545,15 +546,21 @@ function relevanssi_generate_phrase_queries( $phrases, $taxonomies, $custom_fiel
545
 
546
  if ( is_array( $custom_fields ) ) {
547
  array_push( $custom_fields, '_relevanssi_pdf_content' );
548
- $custom_fields_escaped = implode(
549
- "','",
550
- array_map(
551
- 'esc_sql',
552
- $custom_fields
553
- )
554
- );
555
 
556
- $keys = "AND m.meta_key IN ('$custom_fields_escaped')";
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  }
558
 
559
  if ( 'visible' === $custom_fields ) {
@@ -2062,6 +2069,8 @@ function relevanssi_remove_page_builder_shortcodes( $content ) {
2062
  '/\[ai1ec.*?\]/im',
2063
  '/\[eme_.*?\]/im',
2064
  '/\[layerslider.*?\]/im',
 
 
2065
  ),
2066
  $context
2067
  );
414
  return $all_queries;
415
  }
416
 
417
+ /* Documented in lib/indexing.php. */
418
+ $custom_fields = apply_filters( 'relevanssi_index_custom_fields', relevanssi_get_custom_fields() );
419
  $taxonomies = get_option( 'relevanssi_index_taxonomies_list', array() );
 
420
  $excerpts = get_option( 'relevanssi_index_excerpt', 'off' );
421
  $index_pdf_parent = get_option( 'relevanssi_index_pdf_parent' );
422
 
546
 
547
  if ( is_array( $custom_fields ) ) {
548
  array_push( $custom_fields, '_relevanssi_pdf_content' );
 
 
 
 
 
 
 
549
 
550
+ if ( strpos( implode( ' ', $custom_fields ), '%' ) ) {
551
+ // ACF repeater fields involved.
552
+ $custom_fields_regexp = str_replace( '%', '.+', implode( '|', $custom_fields ) );
553
+ $keys = "AND m.meta_key REGEXP ('$custom_fields_regexp')";
554
+ } else {
555
+ $custom_fields_escaped = implode(
556
+ "','",
557
+ array_map(
558
+ 'esc_sql',
559
+ $custom_fields
560
+ )
561
+ );
562
+ $keys = "AND m.meta_key IN ('$custom_fields_escaped')";
563
+ }
564
  }
565
 
566
  if ( 'visible' === $custom_fields ) {
2069
  '/\[ai1ec.*?\]/im',
2070
  '/\[eme_.*?\]/im',
2071
  '/\[layerslider.*?\]/im',
2072
+ // Divi garbage.
2073
+ '/@ET-DC@.*?@/im',
2074
  ),
2075
  $context
2076
  );
lib/compatibility/woocommerce.php CHANGED
@@ -12,6 +12,23 @@
12
 
13
  add_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  * Applies the WooCommerce product visibility filter.
17
  *
12
 
13
  add_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );
14
 
15
+ /**
16
+ * This action solves the problems introduced by adjust_posts_count() in
17
+ * WooCommerce version 4.4.0.
18
+ */
19
+ add_action( 'woocommerce_before_shop_loop', 'relevanssi_wc_reset_loop' );
20
+
21
+ /**
22
+ * Resets the WC post loop in search queries.
23
+ *
24
+ * Hooks on to woocommerce_before_shop_loop.
25
+ */
26
+ function relevanssi_wc_reset_loop() {
27
+ global $wp_query;
28
+ if ( $wp_query->is_search ) {
29
+ wc_reset_loop();
30
+ }
31
+ }
32
  /**
33
  * Applies the WooCommerce product visibility filter.
34
  *
lib/excerpts-highlights.php CHANGED
@@ -1208,7 +1208,10 @@ function relevanssi_get_custom_field_content( $post_id ) {
1208
  array_walk_recursive(
1209
  $value,
1210
  function( $val ) use ( &$value_as_string ) {
1211
- $value_as_string .= ' ' . $val;
 
 
 
1212
  }
1213
  );
1214
  $value = $value_as_string;
1208
  array_walk_recursive(
1209
  $value,
1210
  function( $val ) use ( &$value_as_string ) {
1211
+ if ( is_string( $val ) ) {
1212
+ // Sometimes this can be something weird.
1213
+ $value_as_string .= ' ' . $val;
1214
+ }
1215
  }
1216
  );
1217
  $value = $value_as_string;
lib/indexing.php CHANGED
@@ -809,14 +809,18 @@ function relevanssi_publish( $post_id, $bypass_global_post = false ) {
809
  * @param int $post_id The post ID.
810
  *
811
  * @return string|int Returns 'auto-draft' if the post is an auto draft and
812
- * thus skipped, 'removed' if the post is removed or the relevanssi_index_doc()
813
- * return value from relevanssi_publish().
814
  *
815
  * @see relevanssi_publish()
816
  */
817
  function relevanssi_insert_edit( $post_id ) {
818
  global $wpdb;
819
 
 
 
 
 
820
  $post_status = get_post_status( $post_id );
821
  if ( 'auto-draft' === $post_status ) {
822
  return 'auto-draft';
@@ -859,7 +863,9 @@ function relevanssi_insert_edit( $post_id ) {
859
  $bypass_global_post = true;
860
  $return_value = relevanssi_publish( $post_id, $bypass_global_post );
861
 
862
- relevanssi_async_update_doc_count();
 
 
863
  } else {
864
  // The post isn't supposed to be indexed anymore, remove it from index.
865
  relevanssi_remove_doc( $post_id );
809
  * @param int $post_id The post ID.
810
  *
811
  * @return string|int Returns 'auto-draft' if the post is an auto draft and
812
+ * thus skipped, 'revision' for revisions, 'removed' if the post is removed or
813
+ * the relevanssi_index_doc() return value from relevanssi_publish().
814
  *
815
  * @see relevanssi_publish()
816
  */
817
  function relevanssi_insert_edit( $post_id ) {
818
  global $wpdb;
819
 
820
+ if ( 'revision' === relevanssi_get_post_type( $post_id ) ) {
821
+ return 'revision';
822
+ }
823
+
824
  $post_status = get_post_status( $post_id );
825
  if ( 'auto-draft' === $post_status ) {
826
  return 'auto-draft';
863
  $bypass_global_post = true;
864
  $return_value = relevanssi_publish( $post_id, $bypass_global_post );
865
 
866
+ if ( is_int( $return_value ) && $return_value > 0 ) {
867
+ relevanssi_async_update_doc_count();
868
+ }
869
  } else {
870
  // The post isn't supposed to be indexed anymore, remove it from index.
871
  relevanssi_remove_doc( $post_id );
lib/log.php CHANGED
@@ -57,6 +57,7 @@ function relevanssi_update_log( $query, $hits ) {
57
  $user = apply_filters( 'relevanssi_log_get_user', wp_get_current_user() );
58
  if ( 0 !== $user->ID && get_option( 'relevanssi_omit_from_logs' ) ) {
59
  $omit = explode( ',', get_option( 'relevanssi_omit_from_logs' ) );
 
60
  if ( in_array( strval( $user->ID ), $omit, true ) ) {
61
  return;
62
  }
57
  $user = apply_filters( 'relevanssi_log_get_user', wp_get_current_user() );
58
  if ( 0 !== $user->ID && get_option( 'relevanssi_omit_from_logs' ) ) {
59
  $omit = explode( ',', get_option( 'relevanssi_omit_from_logs' ) );
60
+ array_walk( $omit, 'trim' );
61
  if ( in_array( strval( $user->ID ), $omit, true ) ) {
62
  return;
63
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: search, relevance, better search, product search, woocommerce search
5
  Requires at least: 4.9
6
  Tested up to: 5.5
7
  Requires PHP: 7.0
8
- Stable tag: 4.8.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -133,6 +133,13 @@ Each document database is full of useless words. All the little words that appea
133
  * John Calahan for extensive 4.0 beta testing.
134
 
135
  == Changelog ==
 
 
 
 
 
 
 
136
  = 4.8.0 =
137
  * Changed behaviour: Relevanssi now requires PHP 7.
138
  * Changed behaviour: Relevanssi now sorts strings with `strnatcasecmp()` instead of `strcasecmp()`, leading to a more natural results with strings that include numbers.
@@ -168,6 +175,9 @@ Each document database is full of useless words. All the little words that appea
168
  * Minor fix: User Access Manager showed drafts in search results for all users. This is now fixed.
169
 
170
  == Upgrade notice ==
 
 
 
171
  = 4.8.0 =
172
  * Fixes a major bug in comment indexing, if you include comments in the index rebuild the index after updating.
173
 
5
  Requires at least: 4.9
6
  Tested up to: 5.5
7
  Requires PHP: 7.0
8
+ Stable tag: 4.8.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
133
  * John Calahan for extensive 4.0 beta testing.
134
 
135
  == Changelog ==
136
+ = 4.8.1 =
137
+ * Major fix: Changes in WooCommerce 4.4.0 broke the Relevanssi searches. This makes the WooCommerce search work again.
138
+ * Minor fix: Excluding from logs didn't work if user IDs had spaces between them ('user_a, user_b'). Now the extra spaces don't matter.
139
+ * Minor fix: The asynchronous doc count action in the previous version could cause an infinite loop with the Snitch logger plugin. This is prevented now: the async action doesn't run after indexing unless a post is actually indexed.
140
+ * Minor fix: Relevanssi indexing procedure was triggered for autosaved drafts, causing possible problems with the asynchronous doc count action.
141
+ * Minor fix: The `relevanssi_index_custom_fields` filter hook was not applied when doing phrase matching, thus phrases could not be found when they were in custom fields added with the filter.
142
+
143
  = 4.8.0 =
144
  * Changed behaviour: Relevanssi now requires PHP 7.
145
  * Changed behaviour: Relevanssi now sorts strings with `strnatcasecmp()` instead of `strcasecmp()`, leading to a more natural results with strings that include numbers.
175
  * Minor fix: User Access Manager showed drafts in search results for all users. This is now fixed.
176
 
177
  == Upgrade notice ==
178
+ = 4.8.1 =
179
+ * WooCommerce 4.4 compatibility, other minor fixes.
180
+
181
  = 4.8.0 =
182
  * Fixes a major bug in comment indexing, if you include comments in the index rebuild the index after updating.
183
 
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.8.0
17
  * Author: Mikko Saari
18
  * Author URI: http://www.mikkosaari.fi/
19
  * Text Domain: relevanssi
@@ -67,7 +67,7 @@ $relevanssi_variables['database_version'] = 5;
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.8.0';
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.8.1
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.8.1';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';