Commit 08b469c8 authored by Mikael Mrozik's avatar Mikael Mrozik Committed by Gerrit Code Review

Elasticsearch search plugin Bug #680710

- rebasing change

Change-Id: I4c262c0a22b75a3f9de6d43569765f65ee32c555
parent e1d79ece
......@@ -756,6 +756,7 @@ function siteoptions_submit(Pieform $form, $values) {
$values['allowpublicprofiles'] = 1;
}
$oldsearchplugin = get_config('searchplugin');
$oldlanguage = get_config('lang');
$oldtheme = get_config('theme');
foreach ($fields as $field) {
......@@ -768,6 +769,16 @@ function siteoptions_submit(Pieform $form, $values) {
ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
}
// If they've changed the search plugin, give the new plugin a chance to initialize.
if ($oldsearchplugin != $values['searchplugin']) {
// Call the old search plugin's sitewide cleanup method
safe_require('search', $oldsearchplgin);
call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide');
// Call the new search plugin's sitewide initialize method
safe_require('search', $values['searchplugin']);
call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide');
}
// submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
siteoptions_fail($form, 'sessionlifetime');
......
......@@ -332,3 +332,14 @@ $cfg->cleanurlusereditable = true;
// Turn on caching of HTTP requests
// $cfg->nocache = true;
// Settings used by the "elasticsearch" search plugin.
// See the helpfiles on the plugin's configuration page for details.
// @$cfg->plugin->search->elasticsearch->host = '127.0.0.1';
// @$cfg->plugin->search->elasticsearch->port = 9200;
// @$cfg->plugin->search->elasticsearch->username = '';
// @$cfg->plugin->search->elasticsearch->password = '';
// @$cfg->plugin->search->elasticsearch->indexname = 'mahara';
// @$cfg->plugin->search->elasticsearch->bypassindexname = null;
// @$cfg->plugin->search->elasticsearch->analyzer = 'mahara_analyzer';
// @$cfg->plugin->search->elasticsearch->types = 'usr,interaction_instance,interaction_forum_post,group,view,artefact';
<?php
// loading all dependencies
require 'Dwoo_Template_Mahara.php';
require 'Dwoo_Template_Mahara_Artefact.php';
require 'Dwoo_Template_Mahara_Blocktype.php';
require 'Dwoo_Template_Mahara_Export.php';
require 'Dwoo_Template_Mahara_Interaction.php';
/**
* implements some of the Smarty interface to support old code
* using Smarty and sets up the Dwoo object to work with Mahara
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Mahara extends Dwoo {
/**
* stores the data in the dwoo object, smarty style
*
* @var array
*/
protected $_data;
/**
* stores the templates directories
*
* @var array
*/
protected $includePath;
/**
* stores the template delimiters since some code relies on that
*/
public $left_delimiter = '{';
public $right_delimiter = '}';
public function __construct() {
global $THEME;
// make sure cache/compile paths exist
check_dir_exists(get_config('dataroot') . 'dwoo/compile/' . $THEME->basename);
check_dir_exists(get_config('dataroot') . 'dwoo/cache/' . $THEME->basename);
// set paths
$this->template_dir = $THEME->templatedirs;
$compileDir = get_config('dataroot') . 'dwoo/compile/' . $THEME->basename;
$cacheDir = get_config('dataroot') . 'dwoo/cache/' . $THEME->basename;
parent::__construct($compileDir, $cacheDir);
// add plugins dir to the loader
$this->getLoader()->addDirectory(get_config('libroot') . 'dwoo/mahara/plugins/');
// adds mahara resources and compiler factory
$this->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
$this->addResource('artefact', 'Dwoo_Template_Mahara_Artefact', array($this, 'compilerFactory'));
$this->addResource('blocktype', 'Dwoo_Template_Mahara_Blocktype', array($this, 'compilerFactory'));
$this->addResource('export', 'Dwoo_Template_Mahara_Export', array($this, 'compilerFactory'));
$this->addResource('interaction', 'Dwoo_Template_Mahara_Interaction', array($this, 'compilerFactory'));
// set base data
$theme_list = array();
$themepaths = themepaths();
foreach ($themepaths['mahara'] as $themepath) {
$theme_list[$themepath] = $THEME->get_url($themepath);
}
$this->_data = array(
'THEME' => $THEME,
'WWWROOT' => get_config('wwwroot'),
'THEMELIST' => json_encode($theme_list),
);
}
/**
* implements smarty api to assign data
*/
public function assign($key, $value) {
$this->_data[$key] = $value;
}
/**
* implements smarty api to assign data
*/
public function assign_by_ref($key, &$value) {
$this->_data[$key] =& $value;
}
/**
* implements smarty api to read data
*/
public function get_template_vars($name = null) {
if (!$name) {
return $this->_data;
} elseif (isset($this->_data[$name])) {
return $this->_data[$name];
}
}
/**
* implements smarty api to render and display a template
*/
public function display($file) {
echo $this->fetch($file);
}
/**
* implements smarty api to render and return a template's ouptut
*/
public function fetch($file) {
$class = 'Dwoo_Template_File';
if (strpos($file, ':') !== false) {
$name = explode(':', $file, 2);
$class = 'Dwoo_Template_Mahara_'.$name[0];
$file = $name[1];
}
return $this->get(new $class($file, null, null, null, $this->template_dir), $this->_data);
}
/**
* returns a compiler object when one is required
*
* @return Dwoo_Compiler
*/
public function compilerFactory() {
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
$compiler->setAutoEscape(true);
return $compiler;
}
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2013 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage dwoo
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2013 Catalyst IT Ltd http://catalyst.net.nz
*
*/
// loading all dependencies
require 'Dwoo_Template_Mahara.php';
require 'Dwoo_Template_Mahara_Artefact.php';
require 'Dwoo_Template_Mahara_Blocktype.php';
require 'Dwoo_Template_Mahara_Export.php';
require 'Dwoo_Template_Mahara_Interaction.php';
require 'Dwoo_Template_Mahara_Search.php';
/**
* implements some of the Smarty interface to support old code
* using Smarty and sets up the Dwoo object to work with Mahara
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Dwoo_Mahara extends Dwoo {
/**
* stores the data in the dwoo object, smarty style
*
* @var array
*/
protected $_data;
/**
* stores the templates directories
*
* @var array
*/
protected $includePath;
/**
* stores the template delimiters since some code relies on that
*/
public $left_delimiter = '{';
public $right_delimiter = '}';
public function __construct() {
global $THEME;
// make sure cache/compile paths exist
check_dir_exists(get_config('dataroot') . 'dwoo/compile/' . $THEME->basename);
check_dir_exists(get_config('dataroot') . 'dwoo/cache/' . $THEME->basename);
// set paths
$this->template_dir = $THEME->templatedirs;
$compileDir = get_config('dataroot') . 'dwoo/compile/' . $THEME->basename;
$cacheDir = get_config('dataroot') . 'dwoo/cache/' . $THEME->basename;
parent::__construct($compileDir, $cacheDir);
// add plugins dir to the loader
$this->getLoader()->addDirectory(get_config('libroot') . 'dwoo/mahara/plugins/');
// adds mahara resources and compiler factory
$this->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
$this->addResource('artefact', 'Dwoo_Template_Mahara_Artefact', array($this, 'compilerFactory'));
$this->addResource('blocktype', 'Dwoo_Template_Mahara_Blocktype', array($this, 'compilerFactory'));
$this->addResource('export', 'Dwoo_Template_Mahara_Export', array($this, 'compilerFactory'));
$this->addResource('interaction', 'Dwoo_Template_Mahara_Interaction', array($this, 'compilerFactory'));
$this->addResource('search', 'Dwoo_Template_Mahara_Search', array($this, 'compilerFactory'));
// set base data
$theme_list = array();
$themepaths = themepaths();
foreach ($themepaths['mahara'] as $themepath) {
$theme_list[$themepath] = $THEME->get_url($themepath);
}
$this->_data = array(
'THEME' => $THEME,
'WWWROOT' => get_config('wwwroot'),
'THEMELIST' => json_encode($theme_list),
);
}
/**
* implements smarty api to assign data
*/
public function assign($key, $value) {
$this->_data[$key] = $value;
}
/**
* implements smarty api to assign data
*/
public function assign_by_ref($key, &$value) {
$this->_data[$key] =& $value;
}
/**
* implements smarty api to read data
*/
public function get_template_vars($name = null) {
if (!$name) {
return $this->_data;
}
else if (isset($this->_data[$name])) {
return $this->_data[$name];
}
}
/**
* implements smarty api to render and display a template
*/
public function display($file) {
echo $this->fetch($file);
}
/**
* implements smarty api to render and return a template's ouptut
*/
public function fetch($file) {
$class = 'Dwoo_Template_File';
if (strpos($file, ':') !== false) {
$name = explode(':', $file, 2);
$class = 'Dwoo_Template_Mahara_'.$name[0];
$file = $name[1];
}
return $this->get(new $class($file, null, null, null, $this->template_dir), $this->_data);
}
/**
* returns a compiler object when one is required
*
* @return Dwoo_Compiler
*/
public function compilerFactory() {
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
$compiler->setAutoEscape(true);
return $compiler;
}
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2013 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage dwoo
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2013 Catalyst IT Ltd http://catalyst.net.nz
*
*/
/**
* Dwoo compiler for the Search plugin type. The only added functionality is the ability
* to search for dwoo templates under a Search plugin by prepending the path with "search:"
*/
class Dwoo_Template_Mahara_Search extends Dwoo_Template_Mahara
{
protected function resolveFileName(array $name, array $includePath) {
global $THEME;
$plugin_name = $name[0];
$plugin_path = $name[1];
$basedir = get_config('docroot') . 'search/' . $plugin_name . '/theme/';
foreach ($THEME->inheritance as $theme) {
$filename = $basedir . $theme . '/' . $plugin_path;
if (is_readable($filename)) {
array_unshift($includePath, $basedir . $theme . '/');
return array($plugin_path, $includePath);
}
}
throw new MaharaException('Search template could not be found : '.implode(':', $name));
}
}
\ No newline at end of file
......@@ -77,9 +77,22 @@ function search_user($query_string, $limit, $offset = 0, $data = array()) {
return $results;
}
/*
* The elastic search plug-in is for now only used in the "Universal Search" page.
* Search is performed using the internal plug-in in all other case.
* This might change in the future.
*/
function search_all($query_string, $limit, $offset = 0, $data = array(), $type = null) {
if (record_exists('search_installed', 'name', 'elasticsearch', 'active', 1)) {
safe_require('search', 'elasticsearch');
$plugin = 'elasticsearch';
$results = call_static_method(generate_class_name('search', $plugin), 'search_all', $query_string, $limit, $offset, $data, $type);
return $results;
}
}
/*
/*
* Institutional admin queries:
*
* These are only used to populate user lists on the Institution
......@@ -109,7 +122,7 @@ function get_institutional_admin_search_results($search, $limit) {
function institutional_admin_user_search($query, $institution, $limit) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(generate_class_name('search', $plugin), 'institutional_admin_search_user',
return call_static_method(generate_class_name('search', $plugin), 'institutional_admin_search_user',
$query, $institution, $limit);
}
......@@ -297,7 +310,7 @@ function get_admin_user_search_results($search, $offset, $limit) {
'type' => 'equals',
'string' => $search->institution);
}
$results = call_static_method(
generate_class_name('search', $plugin), 'admin_search_user',
$queries, $constraints, $offset, $limit, $search->sortby, $search->sortdir
......@@ -502,9 +515,10 @@ function build_admin_user_search_results($search, $offset, $limit) {
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null, $friendof=null, $sortoptionidx=null) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
$searchclass = generate_class_name('search', $plugin);
$constraints = array();
if ($plugin == 'internal') {
if (call_static_method($searchclass, 'can_process_raw_group_search_user_queries')) {
// Pass the raw query string through to group_search_user; parsing of the
// query depends on the plugin configuration.
$queries = $query;
......@@ -541,7 +555,8 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
}
$results = call_static_method(
generate_class_name('search', $plugin), 'group_search_user',
$searchclass,
'group_search_user',
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $sortoptionidx
);
......@@ -649,11 +664,16 @@ function get_search_plugins() {
if ($searchplugins = plugins_installed('search')) {
foreach ($searchplugins as $plugin) {
safe_require_plugin('search', $plugin->name, 'lib.php');
if (!call_static_method(generate_class_name('search', $plugin->name), 'is_available_for_site_setting')) {
continue;
}
$searchpluginoptions[$plugin->name] = $plugin->name;
$config_path = get_config('docroot') . 'search/' . $plugin->name . '/version.php';
if (is_readable($config_path)) {
$config = new StdClass;
$config = new stdClass();
require_once($config_path);
if (isset($config->name)) {
$searchpluginoptions[$plugin->name] = $config->name;
......
......@@ -2704,30 +2704,15 @@ function hsc ($text) {
}
/**
* Builds the pieform for the user search, normally found in the header of most
* themes
*/
function user_search_form() {
require_once('pieforms/pieform.php');
return pieform(array(
'name' => 'usf',
'action' => get_config('wwwroot') . 'user/find.php',
'renderer' => 'oneline',
'autofocus' => false,
'validate' => false,
'presubmitcallback' => '',
'elements' => array(
'query' => array(
'type' => 'text',
'defaultvalue' => get_string('searchusers'),
'class' => 'emptyonfocus',
),
'submit' => array(
'type' => 'submit',
'value' => get_string('go'),
)
)
));
* Builds the pieform for the search field in the page header
*/
function header_search_form() {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(
generate_class_name('search', $plugin),
'header_search_form'
);
}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage search-elasticsearch
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2013 Catalyst IT Ltd http://catalyst.net.nz
*
* A standalone script to run the elasticsearch cron job, primarily for testing purposes.
*/
define('INTERNAL', 1);
define('PUBLIC', 1);
define('CRON', 1);
define('TITLE', '');
require(dirname(dirname(dirname(__FILE__))).'/init.php');
require_once(get_config('docroot') . 'artefact/lib.php');
require_once(get_config('docroot') . 'import/lib.php');
require_once(get_config('docroot') . 'export/lib.php');
require_once(get_config('docroot') . 'lib/activity.php');
require_once(get_config('docroot') . 'lib/file.php');
require_once(get_config('docroot') . 'search/lib.php');
require_once(get_config('docroot') . 'search/elasticsearch/lib.php');
raise_memory_limit('256M');
echo "BEGIN\n";
PluginSearchElasticsearch::cron();
echo "END\n";
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20130306" COMMENT="XMLDB file for Mahara's elastic search plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="search_elasticsearch_queue">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="" />
<FIELD NAME="artefacttype" TYPE="char" LENGTH="255" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="search_elasticsearch_queuepk" TYPE="primary" FIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
academicgoal|Resume|Text
academicskill|Resume|Text
address|Profile|Text
aimscreenname|Profile|Text
archive|Resume|Text
audio|Audio|Media
blog|Journal|Text
blogaddress|Profile|Text
blogpost|Journalentry|Text
book|Resume|Text
businessnumber|Profile|Text
careergoal|Resume|Text
certification|Resume|Text
city|Profile|Text
comment|Comment|Text
contactinformation|Profile|Text
country|Profile|Text
coverletter|Resume|Text
cpd|Pld|Text
educationhistory|Resume|Text
email|Profile|Text
employmenthistory|Resume|Text
faxnumber|Profile|Text
file|Document|Media
firstname|Profile|Text
folder|Folder|Media
homenumber|Profile|Text
html|Document|Media
icqnumber|Profile|Text
image|Image|Media
industry|Profile|Text
interest|Resume|Text
introduction|Profile|Text
jabberusername|Profile|Text
lastname|Profile|Text
membership|Resume|Text
mobilenumber|Profile|Text
msnnumber|Profile|Text
occupation|Profile|Text
officialwebsite|Profile|Text
personalgoal|Resume|Text
personalinformation|Resume|Text
personalskill|Resume|Text
personalwebsite|Profile|Text
plan|Plan|Text
preferredname|Profile|Text
profileicon|Image|Media
skypeusername|Profile|Text
studentid|Profile|Text
task|Plan|Text
town|Profile|Text
video|Video|Media
workskill|Resume|Text
yahoochat|Profile|Text
\ No newline at end of file
jQuery(document).ready(function() {
jQuery(document).on("change", "#universalsearchresult select", function() {
var selectid = new String(jQuery(this).attr('id'));
var tmp = selectid.split('-');
var link = jQuery("#"+selectid+"-url").val() + '&' + tmp[2] + '=' + jQuery("#"+selectid).val();
window.location.href = link;
});
});
\ No newline at end of file
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
//require_once(get_config('docroot') . 'lib/Elastica/lib/Elastica/Client.php');
define('INTERNAL', 1);
define('MENUITEM',