Skip to content

All: Add Relevanssi plugin, remove broken search algorithm #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mu-plugins/_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
}
unset( $live_domain, $subdomain, $domain_specific_file, $type_specific_file );

require_once WPMU_PLUGIN_DIR . '/relevanssi/relevanssi.php';
require 'disable-emojis/disable-emojis.php';
42 changes: 0 additions & 42 deletions mu-plugins/api-sites/search-weights.php

This file was deleted.

22 changes: 22 additions & 0 deletions mu-plugins/relevanssi-install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Runs installation of Relevanssi plugin for current blog if it was not already installed.
*/

if (!get_current_blog_id() || get_option('jquery_relevanssi_installed', false)) {
return;
}
relevanssi_install();

update_option( 'relevanssi_implicit_operator', 'AND' );
update_option( 'relevanssi_index_post_types', array( 'post', 'page' ) );
update_option( 'relevanssi_min_word_length', 2 );
// Search terms highlighting may be buggy (try to search "wrap html" and see a page crash). Disabling it.
update_option( 'relevanssi_excerpts', 'off' );

// Will output success message. We don't want it to display.
ob_start();
relevanssi_build_index();
ob_end_clean();

update_option('jquery_relevanssi_installed', true);
77 changes: 77 additions & 0 deletions mu-plugins/relevanssi/lib/cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

function relevanssi_purge_excerpt_cache($post) {
global $wpdb, $relevanssi_variables;

$wpdb->query("DELETE FROM " . $relevanssi_variables['relevanssi_excerpt_cache'] . " WHERE post = $post");
}

function relevanssi_fetch_excerpt($post, $query) {
global $wpdb, $relevanssi_variables;

$query = mysql_real_escape_string($query);
$excerpt = $wpdb->get_var("SELECT excerpt FROM " . $relevanssi_variables['relevanssi_excerpt_cache'] . " WHERE post = $post AND query = '$query'");

if (!$excerpt) return null;

return $excerpt;
}

function relevanssi_store_excerpt($post, $query, $excerpt) {
global $wpdb, $relevanssi_variables;

$query = mysql_real_escape_string($query);
$excerpt = mysql_real_escape_string($excerpt);

$wpdb->query("INSERT INTO " . $relevanssi_variables['relevanssi_excerpt_cache'] . " (post, query, excerpt)
VALUES ($post, '$query', '$excerpt')
ON DUPLICATE KEY UPDATE excerpt = '$excerpt'");
}

function relevanssi_fetch_hits($param) {
global $wpdb, $relevanssi_variables;

$time = get_option('relevanssi_cache_seconds', 172800);

$hits = $wpdb->get_var("SELECT hits FROM " . $relevanssi_variables['relevanssi_cache'] . " WHERE param = '$param' AND UNIX_TIMESTAMP() - UNIX_TIMESTAMP(tstamp) < $time");

if ($hits) {
return unserialize($hits);
}
else {
return null;
}
}

function relevanssi_store_hits($param, $data) {
global $wpdb, $relevanssi_variables;

$param = mysql_real_escape_string($param);
$data = mysql_real_escape_string($data);
$wpdb->query("INSERT INTO " . $relevanssi_variables['relevanssi_cache'] . " (param, hits)
VALUES ('$param', '$data')
ON DUPLICATE KEY UPDATE hits = '$data'");
}

function relevanssi_truncate_cache($all = false) {
global $wpdb, $relevanssi_variables;
$relevanssi_excerpt_cache = $relevanssi_variables['relevanssi_excerpt_cache'];
$relevanssi_cache = $relevanssi_variables['relevanssi_cache'];

if ($all) {
$query = "TRUNCATE TABLE $relevanssi_excerpt_cache";
$wpdb->query($query);

$query = "TRUNCATE TABLE $relevanssi_cache";
}
else {
$time = get_option('relevanssi_cache_seconds', 172800);
$query = "DELETE FROM $relevanssi_cache
WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(tstamp) > $time";
// purge all expired cache data
}
$wpdb->query($query);
}


?>
Loading