Relevanssi – A Better Search - Version 3.6.0

Version Description

  • Changed a bit how Relevanssi attaches itself to queries. Instead of the global $wp_query, Relevanssi now uses the query passed as the parameter to the_posts filter hook. This should improve compatibility in some cases, but may cause problems in some fringe cases. If you're doing something unusual with Relevanssi, try this out before deploying to public use.
  • Some meta queries caused major problems with the Relevanssi weighting algorithm. This has now been fixed.
  • Error notices caused by trying to use a non-existing taxonomy term have been removed.
Download this release

Release Info

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

Code changes from version 3.5.12 to 3.6.0

Files changed (4) hide show
  1. lib/init.php +1 -1
  2. lib/search.php +29 -25
  3. readme.txt +10 -1
  4. relevanssi.php +1 -1
lib/init.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  add_action('admin_menu', 'relevanssi_menu');
4
- add_filter('the_posts', 'relevanssi_query');
5
  add_action('delete_post', 'relevanssi_delete');
6
  add_action('comment_post', 'relevanssi_comment_index'); //added by OdditY
7
  add_action('edit_comment', 'relevanssi_comment_edit'); //added by OdditY
1
  <?php
2
 
3
  add_action('admin_menu', 'relevanssi_menu');
4
+ add_filter('the_posts', 'relevanssi_query', 99, 2);
5
  add_action('delete_post', 'relevanssi_delete');
6
  add_action('comment_post', 'relevanssi_comment_index'); //added by OdditY
7
  add_action('edit_comment', 'relevanssi_comment_edit'); //added by OdditY
lib/search.php CHANGED
@@ -5,35 +5,32 @@ function relevanssi_query($posts, $query = false) {
5
  ($admin_search == 'on') ? $admin_search = true : $admin_search = false;
6
 
7
  global $relevanssi_active;
8
- global $wp_query;
9
 
10
- if (!$wp_query) return $posts;
11
 
12
  $search_ok = true; // we will search!
13
- if (!is_search()) {
 
 
 
14
  $search_ok = false; // no, we can't
15
  }
16
 
17
  // Uses $wp_query->is_admin instead of is_admin() to help with Ajax queries that
18
  // use 'admin_ajax' hook (which sets is_admin() to true whether it's an admin search
19
  // or not.
20
- if (is_search() && $wp_query->is_admin) {
21
  $search_ok = false; // but if this is an admin search, reconsider
22
  if ($admin_search) $search_ok = true; // yes, we can search!
23
  }
24
 
25
- if ($wp_query->is_admin && empty($wp_query->query_vars['s'])) {
26
- $search_ok = false;
27
- }
28
-
29
- // Required so that the admin dashboard page search works.
30
- if ($wp_query->is_admin && $wp_query->query_vars['post_type'] == 'page') {
31
  $search_ok = false;
32
  }
33
 
34
  // Disable search in media library search
35
  if ($search_ok) {
36
- if ($wp_query->query_vars['post_type'] == 'attachment' && $wp_query->query_vars['post_status'] == 'inherit,private') {
37
  $search_ok = false;
38
  }
39
  }
@@ -45,13 +42,14 @@ function relevanssi_query($posts, $query = false) {
45
  }
46
 
47
  if ($search_ok) {
48
- $wp_query = apply_filters('relevanssi_modify_wp_query', $wp_query);
49
- $posts = relevanssi_do_query($wp_query);
50
  }
51
-
52
  return $posts;
53
  }
54
 
 
55
  // This is my own magic working.
56
  function relevanssi_search($args) {
57
  global $wpdb, $relevanssi_variables;
@@ -503,7 +501,7 @@ function relevanssi_search($args) {
503
  !empty($post_type_weights['post_tag']) ? $tag = $post_type_weights['post_tag'] : $tag = $relevanssi_variables['post_type_weight_defaults']['post_tag'];
504
  !empty($post_type_weights['category']) ? $cat = $post_type_weights['category'] : $cat = $relevanssi_variables['post_type_weight_defaults']['category'];
505
 
506
- $query = "SELECT relevanssi.*, relevanssi.title * $title_boost +
507
  relevanssi.content + relevanssi.comment * $comment_boost +
508
  relevanssi.tag * $tag + relevanssi.link * $link_boost +
509
  relevanssi.author + relevanssi.category * $cat + relevanssi.excerpt +
@@ -1316,22 +1314,26 @@ function relevanssi_process_tax_query_row($row, $is_sub_row, $global_relation, $
1316
  $numeric_slugs[] = "'$t_slug'";
1317
  }
1318
  else {
1319
- $t_slug = sanitize_title($t_slug);
1320
- $term_id[] = $term->term_id;
1321
- $slugs[] = "'$t_slug'";
 
 
1322
  }
1323
  }
1324
  if (!empty($slugs)) $slug_in = implode(',', $slugs);
1325
  }
1326
  else {
1327
- $term = get_term_by('slug', $slug, $row['taxonomy']);
1328
  if (!$term && is_numeric($slug)) {
1329
  $numeric_slugs[] = $slug;
1330
  }
1331
  else {
1332
- $slug = sanitize_title($slug);
1333
- $term_id = $term->term_id;
1334
- $slug_in = "'$slug'";
 
 
1335
  }
1336
  }
1337
  if (!empty($slug_in)) {
@@ -1358,9 +1360,11 @@ function relevanssi_process_tax_query_row($row, $is_sub_row, $global_relation, $
1358
  $numeric_names[] = "'$t_name'";
1359
  }
1360
  else {
1361
- $t_name = sanitize_title($t_name);
1362
- $term_id[] = $term->term_id;
1363
- $names[] = "'$t_name'";
 
 
1364
  }
1365
  }
1366
  if (!empty($names)) $name_in = implode(',', $names);
5
  ($admin_search == 'on') ? $admin_search = true : $admin_search = false;
6
 
7
  global $relevanssi_active;
 
8
 
9
+ if (!$query) return $posts;
10
 
11
  $search_ok = true; // we will search!
12
+ if (!$query->is_search()) {
13
+ $search_ok = false; // no, we can't
14
+ }
15
+ if (!$query->is_main_query()) {
16
  $search_ok = false; // no, we can't
17
  }
18
 
19
  // Uses $wp_query->is_admin instead of is_admin() to help with Ajax queries that
20
  // use 'admin_ajax' hook (which sets is_admin() to true whether it's an admin search
21
  // or not.
22
+ if ($query->is_search() && $query->is_admin) {
23
  $search_ok = false; // but if this is an admin search, reconsider
24
  if ($admin_search) $search_ok = true; // yes, we can search!
25
  }
26
 
27
+ if ($query->is_admin && empty($query->query_vars['s'])) {
 
 
 
 
 
28
  $search_ok = false;
29
  }
30
 
31
  // Disable search in media library search
32
  if ($search_ok) {
33
+ if ($query->query_vars['post_type'] == 'attachment' && $query->query_vars['post_status'] == 'inherit,private') {
34
  $search_ok = false;
35
  }
36
  }
42
  }
43
 
44
  if ($search_ok) {
45
+ $query = apply_filters('relevanssi_modify_wp_query', $query);
46
+ $posts = relevanssi_do_query($query);
47
  }
48
+
49
  return $posts;
50
  }
51
 
52
+
53
  // This is my own magic working.
54
  function relevanssi_search($args) {
55
  global $wpdb, $relevanssi_variables;
501
  !empty($post_type_weights['post_tag']) ? $tag = $post_type_weights['post_tag'] : $tag = $relevanssi_variables['post_type_weight_defaults']['post_tag'];
502
  !empty($post_type_weights['category']) ? $cat = $post_type_weights['category'] : $cat = $relevanssi_variables['post_type_weight_defaults']['category'];
503
 
504
+ $query = "SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * $title_boost +
505
  relevanssi.content + relevanssi.comment * $comment_boost +
506
  relevanssi.tag * $tag + relevanssi.link * $link_boost +
507
  relevanssi.author + relevanssi.category * $cat + relevanssi.excerpt +
1314
  $numeric_slugs[] = "'$t_slug'";
1315
  }
1316
  else {
1317
+ if (isset($term->term_id)) {
1318
+ $t_slug = sanitize_title($t_slug);
1319
+ $term_id[] = $term->term_id;
1320
+ $slugs[] = "'$t_slug'";
1321
+ }
1322
  }
1323
  }
1324
  if (!empty($slugs)) $slug_in = implode(',', $slugs);
1325
  }
1326
  else {
1327
+ $term = get_term_by('slug', $slug, $row['taxonomy'], OBJECT);
1328
  if (!$term && is_numeric($slug)) {
1329
  $numeric_slugs[] = $slug;
1330
  }
1331
  else {
1332
+ if (isset($term->term_id)) {
1333
+ $slug = sanitize_title($slug);
1334
+ $term_id = $term->term_id;
1335
+ $slug_in = "'$slug'";
1336
+ }
1337
  }
1338
  }
1339
  if (!empty($slug_in)) {
1360
  $numeric_names[] = "'$t_name'";
1361
  }
1362
  else {
1363
+ if (isset($term->term_id)) {
1364
+ $t_name = sanitize_title($t_name);
1365
+ $term_id[] = $term->term_id;
1366
+ $names[] = "'$t_name'";
1367
+ }
1368
  }
1369
  }
1370
  if (!empty($names)) $name_in = implode(',', $names);
readme.txt CHANGED
@@ -4,7 +4,8 @@ Donate link: https://www.relevanssi.com/buy-premium/
4
  Tags: search, relevance, better search
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
- Stable tag: 3.5.12
 
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -268,6 +269,11 @@ Each document database is full of useless words. All the little words that appea
268
 
269
  == Changelog ==
270
 
 
 
 
 
 
271
  = 3.5.12 =
272
  * Post type exclusion didn't work as expected.
273
  * Relevanssi couldn't handle nested tax queries (such as those generated by WooCommerce product visibility filtering) properly.
@@ -1067,6 +1073,9 @@ Each document database is full of useless words. All the little words that appea
1067
 
1068
  == Upgrade notice ==
1069
 
 
 
 
1070
  = 3.5.11 =
1071
  * Improvements in excerpts, new filters.
1072
 
4
  Tags: search, relevance, better search
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
+ Requires PHP: 5.6
8
+ Stable tag: 3.6.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
269
 
270
  == Changelog ==
271
 
272
+ = 3.6.0 =
273
+ * Changed a bit how Relevanssi attaches itself to queries. Instead of the global $wp_query, Relevanssi now uses the query passed as the parameter to `the_posts` filter hook. This should improve compatibility in some cases, but may cause problems in some fringe cases. If you're doing something unusual with Relevanssi, try this out before deploying to public use.
274
+ * Some meta queries caused major problems with the Relevanssi weighting algorithm. This has now been fixed.
275
+ * Error notices caused by trying to use a non-existing taxonomy term have been removed.
276
+
277
  = 3.5.12 =
278
  * Post type exclusion didn't work as expected.
279
  * Relevanssi couldn't handle nested tax queries (such as those generated by WooCommerce product visibility filtering) properly.
1073
 
1074
  == Upgrade notice ==
1075
 
1076
+ = 3.6.0 =
1077
+ * A big change in how Relevanssi works with queries. This should reduce compatibility issues, but may cause unexpected results.
1078
+
1079
  = 3.5.11 =
1080
  * Improvements in excerpts, new filters.
1081
 
relevanssi.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Relevanssi
4
  Plugin URI: http://www.relevanssi.com/
5
  Description: This plugin replaces WordPress search with a relevance-sorting search.
6
- Version: 3.5.12
7
  Author: Mikko Saari
8
  Author URI: http://www.mikkosaari.fi/
9
  */
3
  Plugin Name: Relevanssi
4
  Plugin URI: http://www.relevanssi.com/
5
  Description: This plugin replaces WordPress search with a relevance-sorting search.
6
+ Version: 3.6.0
7
  Author: Mikko Saari
8
  Author URI: http://www.mikkosaari.fi/
9
  */