Relevanssi – A Better Search - Version 4.15.2

Version Description

  • 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.
  • Minor fix: Phrase search couldn't find phrases that include an ampersand if they matched the post title. This works now.
  • Minor fix: Relevanssi now adds spaces after table cell tags to avoid table cell content sticking together in excerpts.
  • Minor fix: The 'Allowable tags in excerpts' function now automatically corrects the entered value to match what Relevanssi expects the value to be.
Download this release

Release Info

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

Code changes from version 4.15.1 to 4.15.2

lib/common.php CHANGED
@@ -1730,6 +1730,9 @@ function relevanssi_replace_synonyms_in_terms( array $terms ) : array {
1730
  function ( $term ) use ( $synonyms ) {
1731
  $new_term = array();
1732
  foreach ( $synonyms as $pair ) {
 
 
 
1733
  list( $key, $value ) = explode( '=', $pair );
1734
  if ( $value === $term ) {
1735
  $new_term[] = $key;
1730
  function ( $term ) use ( $synonyms ) {
1731
  $new_term = array();
1732
  foreach ( $synonyms as $pair ) {
1733
+ if ( empty( $pair ) ) {
1734
+ continue;
1735
+ }
1736
  list( $key, $value ) = explode( '=', $pair );
1737
  if ( $value === $term ) {
1738
  $new_term[] = $key;
lib/didyoumean.php CHANGED
@@ -161,6 +161,22 @@ function relevanssi_simple_generate_suggestion( $query ) {
161
  $suggestion = '';
162
 
163
  foreach ( $tokens as $token => $count ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  $closest = '';
165
  $distance = -1;
166
  foreach ( $data as $row ) {
161
  $suggestion = '';
162
 
163
  foreach ( $tokens as $token => $count ) {
164
+ /**
165
+ * Filters the tokens for Did you mean suggestions.
166
+ *
167
+ * You can use this filter hook to modify the tokens before Relevanssi
168
+ * tries to come up with Did you mean suggestions for them. If you
169
+ * return an empty string, the token will be skipped and no suggestion
170
+ * will be made for the token.
171
+ *
172
+ * @param string $token An individual word from the search query.
173
+ *
174
+ * @return string The token.
175
+ */
176
+ $token = apply_filters( 'relevanssi_didyoumean_token', trim( $token ) );
177
+ if ( ! $token ) {
178
+ continue;
179
+ }
180
  $closest = '';
181
  $distance = -1;
182
  foreach ( $data as $row ) {
lib/excerpts-highlights.php CHANGED
@@ -122,7 +122,11 @@ function relevanssi_do_excerpt( $t_post, $query, $excerpt_length = null, $excerp
122
 
123
  // Add the custom field content.
124
  if ( 'on' === get_option( 'relevanssi_excerpt_custom_fields' ) ) {
125
- $content .= relevanssi_get_custom_field_content( $post->ID );
 
 
 
 
126
  }
127
 
128
  /**
@@ -992,9 +996,11 @@ function relevanssi_extract_locations( $words, $fulltext ) {
992
  * @return int Number of times the words appear in the text.
993
  */
994
  function relevanssi_count_matches( $words, $complete_text ) {
995
- $count = 0;
996
- $lowercase_text = relevanssi_strtolower( $complete_text, 'UTF-8' );
997
- $text = '';
 
 
998
 
999
  $count_words = count( $words );
1000
  for ( $t = 0; $t < $count_words; $t++ ) {
122
 
123
  // Add the custom field content.
124
  if ( 'on' === get_option( 'relevanssi_excerpt_custom_fields' ) ) {
125
+ if ( 'user' === $post->post_type && function_exists( 'relevanssi_get_user_custom_field_content' ) ) {
126
+ $content .= relevanssi_get_user_custom_field_content( $post->ID );
127
+ } else {
128
+ $content .= relevanssi_get_custom_field_content( $post->ID );
129
+ }
130
  }
131
 
132
  /**
996
  * @return int Number of times the words appear in the text.
997
  */
998
  function relevanssi_count_matches( $words, $complete_text ) {
999
+ $count = 0;
1000
+ $text = '';
1001
+
1002
+ // Add the space in case the match is the last word in the text.
1003
+ $lowercase_text = relevanssi_strtolower( $complete_text, 'UTF-8' ) . ' ';
1004
 
1005
  $count_words = count( $words );
1006
  for ( $t = 0; $t < $count_words; $t++ ) {
lib/options.php CHANGED
@@ -80,6 +80,13 @@ function update_relevanssi_options( array $request ) {
80
  update_option( 'relevanssi_show_matches_text', $value );
81
  }
82
  relevanssi_update_intval( $request, 'relevanssi_excerpt_length', true, 10 );
 
 
 
 
 
 
 
83
  }
84
 
85
  relevanssi_process_weights_and_indexing( $request );
@@ -99,7 +106,6 @@ function update_relevanssi_options( array $request ) {
99
  'relevanssi_default_orderby' => true,
100
  'relevanssi_disable_or_fallback' => true,
101
  'relevanssi_exact_match_bonus' => true,
102
- 'relevanssi_excerpt_allowable_tags' => true,
103
  'relevanssi_excerpt_custom_fields' => true,
104
  'relevanssi_excerpt_type' => true,
105
  'relevanssi_excerpts' => true,
80
  update_option( 'relevanssi_show_matches_text', $value );
81
  }
82
  relevanssi_update_intval( $request, 'relevanssi_excerpt_length', true, 10 );
83
+
84
+ if ( isset( $request['relevanssi_excerpt_allowable_tags'] ) ) {
85
+ $value = $request['relevanssi_excerpt_allowable_tags'];
86
+ $value = str_replace( array( ' ', '/' ), '', $value );
87
+ $value = implode( '>', array_unique( explode( '>', $value ) ) );
88
+ update_option( 'relevanssi_excerpt_allowable_tags', $value );
89
+ }
90
  }
91
 
92
  relevanssi_process_weights_and_indexing( $request );
106
  'relevanssi_default_orderby' => true,
107
  'relevanssi_disable_or_fallback' => true,
108
  'relevanssi_exact_match_bonus' => true,
 
109
  'relevanssi_excerpt_custom_fields' => true,
110
  'relevanssi_excerpt_type' => true,
111
  'relevanssi_excerpts' => true,
lib/phrases.php CHANGED
@@ -175,10 +175,11 @@ $custom_fields, string $excerpts ) : array {
175
  $phrase_queries = array();
176
 
177
  foreach ( $phrases as $phrase ) {
178
- $queries = array();
179
- $phrase = $wpdb->esc_like( $phrase );
180
- $phrase = str_replace( array( '‘', '’', "'", '"', '”', '“', '“', '„', '´' ), '_', $phrase );
181
- $phrase = htmlspecialchars( $phrase );
 
182
 
183
  /**
184
  * Filters each phrase before it's passed through esc_sql() and used in
@@ -198,7 +199,7 @@ $custom_fields, string $excerpts ) : array {
198
 
199
  $query = "(SELECT ID FROM $wpdb->posts
200
  WHERE (post_content LIKE '%$phrase%'
201
- OR post_title LIKE '%$phrase%' $excerpt)
202
  AND post_status IN ($status))";
203
 
204
  $queries[] = array(
175
  $phrase_queries = array();
176
 
177
  foreach ( $phrases as $phrase ) {
178
+ $queries = array();
179
+ $phrase = $wpdb->esc_like( $phrase );
180
+ $phrase = str_replace( array( '‘', '’', "'", '"', '”', '“', '“', '„', '´' ), '_', $phrase );
181
+ $title_phrase = $phrase;
182
+ $phrase = htmlspecialchars( $phrase );
183
 
184
  /**
185
  * Filters each phrase before it's passed through esc_sql() and used in
199
 
200
  $query = "(SELECT ID FROM $wpdb->posts
201
  WHERE (post_content LIKE '%$phrase%'
202
+ OR post_title LIKE '%$title_phrase%' $excerpt)
203
  AND post_status IN ($status))";
204
 
205
  $queries[] = array(
lib/search-query-restrictions.php CHANGED
@@ -579,7 +579,14 @@ function relevanssi_process_post_status( $post_status ) {
579
  }
580
 
581
  if ( $escaped_post_status ) {
 
582
  if ( $wp_query->is_admin || $relevanssi_admin_test ) {
 
 
 
 
 
 
583
  $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
584
  WHERE posts.post_status IN ($escaped_post_status))))";
585
  } else {
579
  }
580
 
581
  if ( $escaped_post_status ) {
582
+ $block_non_post_results = false;
583
  if ( $wp_query->is_admin || $relevanssi_admin_test ) {
584
+ $block_non_post_results = true;
585
+ }
586
+ if ( $wp_query->is_admin && isset( $wp_query->query_vars['action'] ) && 'relevanssi_live_search' === $wp_query->query_vars['action'] ) {
587
+ $block_non_post_results = false;
588
+ }
589
+ if ( $block_non_post_results ) {
590
  $query_restrictions .= " AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM $wpdb->posts AS posts
591
  WHERE posts.post_status IN ($escaped_post_status))))";
592
  } else {
lib/utils.php CHANGED
@@ -1075,6 +1075,7 @@ function relevanssi_strip_tags( $content ) {
1075
  '/(<\/?hr.*?>)/',
1076
  '/(<\/?li.*?>)/',
1077
  '/(<img.*?>)/',
 
1078
  );
1079
 
1080
  $content = preg_replace( $space_tags, '$1 ', $content );
1075
  '/(<\/?hr.*?>)/',
1076
  '/(<\/?li.*?>)/',
1077
  '/(<img.*?>)/',
1078
+ '/(<\/td>)/',
1079
  );
1080
 
1081
  $content = preg_replace( $space_tags, '$1 ', $content );
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.9
7
  Requires PHP: 7.0
8
- Stable tag: 4.15.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -128,6 +128,12 @@ 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.15.1 =
132
  * Changed behaviour: Relevanssi now ignores WordPress metadata custom fields that aren't interesting for Relevanssi indexing.
133
  * 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.
@@ -146,6 +152,9 @@ Each document database is full of useless words. All the little words that appea
146
  * 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.
147
 
148
  == Upgrade notice ==
 
 
 
149
  = 4.15.1 =
150
  * Fixes warnings, improves permalink functions and relevanssi_hits_filter.
151
 
5
  Requires at least: 4.9
6
  Tested up to: 5.9
7
  Requires PHP: 7.0
8
+ Stable tag: 4.15.2
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.15.2 =
132
+ * 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.
133
+ * Minor fix: Phrase search couldn't find phrases that include an ampersand if they matched the post title. This works now.
134
+ * Minor fix: Relevanssi now adds spaces after table cell tags to avoid table cell content sticking together in excerpts.
135
+ * Minor fix: The 'Allowable tags in excerpts' function now automatically corrects the entered value to match what Relevanssi expects the value to be.
136
+
137
  = 4.15.1 =
138
  * Changed behaviour: Relevanssi now ignores WordPress metadata custom fields that aren't interesting for Relevanssi indexing.
139
  * 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.
152
  * 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.
153
 
154
  == Upgrade notice ==
155
+ = 4.15.2 =
156
+ * New filter hook for Did you mean words, small bug fixes for excerpts and phrases.
157
+
158
  = 4.15.1 =
159
  * Fixes warnings, improves permalink functions and relevanssi_hits_filter.
160
 
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.15.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.15.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.15.2
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.15.2';
71
 
72
  require_once 'lib/admin-ajax.php';
73
  require_once 'lib/common.php';