Commit 790fa377 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1503885: Allowing collections to be indexed / searched

This was an oversight from initial implementation


Change-Id: I7cd5b21209349bd61e78d14cef8ad698197ddbc6
Signed-off-by: Robert Lyon's avatarRobert Lyon <>
parent 596defc1
......@@ -496,7 +496,7 @@ $cfg->cleanurlusereditable = true;
// $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';
// $cfg->plugin_search_elasticsearch_types = 'usr,interaction_instance,interaction_forum_post,group,view,artefact,block_instance,collection';
* @global int $cfg->plugin_search_elasticsearch_requestlimit How many items to send per elasticsearch bulk request
* The main side effect of raising this, is that it increases the size of the POST request you send to your
......@@ -55,5 +55,21 @@ function xmldb_search_elasticsearch_upgrade($oldversion=0) {
if ($oldversion < 2015100800) {
log_debug('Adding ability to search by collection in elasticsearch');
// The code for this existed since the beginning but 'collection' was not
// added to the $cfg->plugin_search_elasticsearch_types
// We don't want to run the re-indexing now as that will take ages for large sites
// It should be run from the Extensions -> Elasticsearch -> Configuration page
if ($types = get_field('search_config', 'value', 'plugin', 'elasticsearch', 'field', 'types')) {
$types = explode(',', $types);
if (!in_array('collection', $types)) {
$types[] = 'collection';
$types = implode(',', $types);
update_record('search_config', array('value' => $types), array('plugin' => 'elasticsearch', 'field' => 'types'));
log_warn(get_string('newindextype', 'search.elasticsearch', 'collection'), true, false);
return true;
......@@ -50,6 +50,7 @@ $string['indexnamedescription'] = 'Name of the Elasticsearch index. Default is m
$string['license'] = 'License';
$string['Media'] = 'Media';
$string['newindextype'] = 'A new index type "%s" has been added to your elasticsearch settings. For this to take effect you will need to reindex your site';
$string['none'] = 'none';
$string['noticeenabled'] = 'The Elasticsearch plugin is currently active. To deactivate it, deselect it in the <a href="%s">site options search settings</a>.';
$string['noticenotactive'] = 'The ElasticSearch Server is unreachable on host: %s and port %s. Please make sure it is running.';
$string['noticenotenabled'] = 'The Elasticsearch plugin is not currently enabled. To activate it, select it in the <a href="%s">site options in the search settings</a>.';
......@@ -495,7 +495,7 @@ class PluginSearchElasticsearch extends PluginSearch {
set_config_plugin('search', 'elasticsearch', 'port', '9200');
set_config_plugin('search', 'elasticsearch', 'indexname', 'mahara');
set_config_plugin('search', 'elasticsearch', 'analyzer', 'mahara_analyzer');
set_config_plugin('search', 'elasticsearch', 'types', 'usr,interaction_instance,interaction_forum_post,group,view,artefact,block_instance');
set_config_plugin('search', 'elasticsearch', 'types', 'usr,interaction_instance,interaction_forum_post,group,view,artefact,block_instance,collection');
set_config_plugin('search', 'elasticsearch', 'cronlimit', '50000');
$elasticsearchartefacttypesmap = file_get_contents(__DIR__ . '/elasticsearchartefacttypesmap.txt');
......@@ -154,7 +154,7 @@ class ElasticsearchType_collection extends ElasticsearchType
public static function getRecordDataById($type, $id){
$sql = 'SELECT,, c.ctime, c.description, cv.view AS viewid, c.owner
FROM {collectio}n c
FROM {collection} c
LEFT OUTER JOIN {collection_view} cv ON cv.collection =
WHERE id = ? ORDER BY cv.displayorder asc LIMIT 1;';
......@@ -13,5 +13,5 @@ defined('INTERNAL') || die();
$config = new stdClass();
$config->name = 'elasticsearch';
$config->version = 2015072700;
$config->release = '1.0.3';
$config->version = 2015100800;
$config->release = '1.0.4';
......@@ -7,18 +7,26 @@
<h3 class="title">
<span class="icon icon-folder-open left"></span>
{if $record->viewid}
<a href="{$WWWROOT}view/view.php?id={$record->viewid}">
<span class="artefacttype">({str tag=collection section=search.elasticsearch})</span>
{if $record->createdbyname}
<div class="createdby">{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url}">`$record->createdbyname|safe`</a>'}</div>
<div class="createdby">{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url`">`$record->createdbyname|safe`</a>'}</div>
<div class="detail">{$record->description|str_shorten_html:140:true|safe}</div>
<div class="tags"><strong>{str tag=pages section=search.elasticsearch}:</strong>
{foreach from=$record->views key=id item=view name=foo}
<a href="{$WWWROOT}view/view.php?id={$id}">{$view}</a>{if !$}, {/if}
{if $record->views}
{foreach from=$record->views key=id item=view name=foo}
<a href="{$WWWROOT}view/view.php?id={$id}">{$view}</a>{if !$}, {/if}
{str tag=none section=search.elasticsearch}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment