Skip to content

Commit 94345a8

Browse files
authored
All: Add Relevanssi plugin, remove broken search algorithm
Fixes #359 Closes #361 Closes #408
1 parent 9e97d27 commit 94345a8

34 files changed

+17479
-42
lines changed

mu-plugins/_loader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
}
1515
unset( $live_domain, $subdomain, $domain_specific_file, $type_specific_file );
1616

17+
require_once WPMU_PLUGIN_DIR . '/relevanssi/relevanssi.php';
1718
require 'disable-emojis/disable-emojis.php';

mu-plugins/api-sites/search-weights.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

mu-plugins/relevanssi-install.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Runs installation of Relevanssi plugin for current blog if it was not already installed.
4+
*/
5+
6+
if (!get_current_blog_id() || get_option('jquery_relevanssi_installed', false)) {
7+
return;
8+
}
9+
relevanssi_install();
10+
11+
update_option( 'relevanssi_implicit_operator', 'AND' );
12+
update_option( 'relevanssi_index_post_types', array( 'post', 'page' ) );
13+
update_option( 'relevanssi_min_word_length', 2 );
14+
// Search terms highlighting may be buggy (try to search "wrap html" and see a page crash). Disabling it.
15+
update_option( 'relevanssi_excerpts', 'off' );
16+
17+
// Will output success message. We don't want it to display.
18+
ob_start();
19+
relevanssi_build_index();
20+
ob_end_clean();
21+
22+
update_option('jquery_relevanssi_installed', true);

mu-plugins/relevanssi/lib/cache.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
function relevanssi_purge_excerpt_cache($post) {
4+
global $wpdb, $relevanssi_variables;
5+
6+
$wpdb->query("DELETE FROM " . $relevanssi_variables['relevanssi_excerpt_cache'] . " WHERE post = $post");
7+
}
8+
9+
function relevanssi_fetch_excerpt($post, $query) {
10+
global $wpdb, $relevanssi_variables;
11+
12+
$query = mysql_real_escape_string($query);
13+
$excerpt = $wpdb->get_var("SELECT excerpt FROM " . $relevanssi_variables['relevanssi_excerpt_cache'] . " WHERE post = $post AND query = '$query'");
14+
15+
if (!$excerpt) return null;
16+
17+
return $excerpt;
18+
}
19+
20+
function relevanssi_store_excerpt($post, $query, $excerpt) {
21+
global $wpdb, $relevanssi_variables;
22+
23+
$query = mysql_real_escape_string($query);
24+
$excerpt = mysql_real_escape_string($excerpt);
25+
26+
$wpdb->query("INSERT INTO " . $relevanssi_variables['relevanssi_excerpt_cache'] . " (post, query, excerpt)
27+
VALUES ($post, '$query', '$excerpt')
28+
ON DUPLICATE KEY UPDATE excerpt = '$excerpt'");
29+
}
30+
31+
function relevanssi_fetch_hits($param) {
32+
global $wpdb, $relevanssi_variables;
33+
34+
$time = get_option('relevanssi_cache_seconds', 172800);
35+
36+
$hits = $wpdb->get_var("SELECT hits FROM " . $relevanssi_variables['relevanssi_cache'] . " WHERE param = '$param' AND UNIX_TIMESTAMP() - UNIX_TIMESTAMP(tstamp) < $time");
37+
38+
if ($hits) {
39+
return unserialize($hits);
40+
}
41+
else {
42+
return null;
43+
}
44+
}
45+
46+
function relevanssi_store_hits($param, $data) {
47+
global $wpdb, $relevanssi_variables;
48+
49+
$param = mysql_real_escape_string($param);
50+
$data = mysql_real_escape_string($data);
51+
$wpdb->query("INSERT INTO " . $relevanssi_variables['relevanssi_cache'] . " (param, hits)
52+
VALUES ('$param', '$data')
53+
ON DUPLICATE KEY UPDATE hits = '$data'");
54+
}
55+
56+
function relevanssi_truncate_cache($all = false) {
57+
global $wpdb, $relevanssi_variables;
58+
$relevanssi_excerpt_cache = $relevanssi_variables['relevanssi_excerpt_cache'];
59+
$relevanssi_cache = $relevanssi_variables['relevanssi_cache'];
60+
61+
if ($all) {
62+
$query = "TRUNCATE TABLE $relevanssi_excerpt_cache";
63+
$wpdb->query($query);
64+
65+
$query = "TRUNCATE TABLE $relevanssi_cache";
66+
}
67+
else {
68+
$time = get_option('relevanssi_cache_seconds', 172800);
69+
$query = "DELETE FROM $relevanssi_cache
70+
WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(tstamp) > $time";
71+
// purge all expired cache data
72+
}
73+
$wpdb->query($query);
74+
}
75+
76+
77+
?>

0 commit comments

Comments
 (0)