Exemplo n.º 1
0
 /**
  * Creates the Index on the elasticsearch server itself, first dropping if it already
  * exists.
  */
 public static function create_index()
 {
     $esclient = PluginSearchElasticsearch::make_client();
     $elasticaIndex = $esclient->getIndex(PluginSearchElasticsearch::get_write_indexname());
     // Create the index, deleting it first if it already exists
     $elasticaIndex->create(array('analysis' => array('analyzer' => array('mahara_analyzer' => array('type' => 'custom', 'tokenizer' => 'pattern', 'filter' => array('standard', 'lowercase', 'stop', 'maharaSnowball'), 'char_filter' => array('maharaHtml'))), 'filter' => array('maharaSnowball' => array('type' => 'snowball', 'language' => 'English')), 'char_filter' => array('maharaHtml' => array('type' => 'html_strip', 'read_ahead' => '1024')))), true);
 }
Exemplo n.º 2
0
$limit = param_integer('limit', 10);
$filter = 'all';
$query = PluginSearchElasticsearch::clean_query($query);
$data = PluginSearchElasticsearch::search_all($query, $limit, $offset, $options, $mainfacetterm, $USER);
$data['query'] = $query;
// License
if (get_config('licensemetadata')) {
    $data['license_on'] = true;
    $license_options = array();
    $licenses = get_records_assoc('artefact_license', null, null, 'displayname');
    foreach ($licenses as $l) {
        $license_options[$l->name] = $l->displayname;
    }
    $data['license_options'] = $license_options;
}
PluginSearchElasticsearch::build_results_html($data);
$searchform = array('name' => 'search', 'renderer' => 'oneline', 'checkdirtychange' => false, 'elements' => array());
$searchform['elements']['query'] = array('type' => 'text', 'defaultvalue' => $query, 'title' => get_string('pagetitle', 'search.elasticsearch'), 'hiddenlabel' => true);
$searchform['elements']['submit'] = array('type' => 'submit', 'value' => get_string('search'));
$searchform['elements']['tagsonly'] = array('type' => 'switchbox', 'value' => isset($options['tagsonly']) && $options['tagsonly'] == true ? true : false, 'title' => get_string('tagsonly', 'search.elasticsearch'));
$searchform = pieform($searchform);
$js = <<<EOF
addLoadEvent(function () {
    var firstpage = false;

    function SearchPager() {
        var self = this;
        paginatorProxy.addObserver(self);
        connect(self, 'pagechanged', function() {
            if (firstpage) {
                firstpage = false;
 /**
  * Get views linked to a particular artefact, applying ACL
  * This is used to display the list of views in an artefact result, because it's faster to retrieve the info
  * from Elastic search that running the SQL query.
  */
 public static function views_by_artefact_acl_filter($views = array())
 {
     global $USER;
     $ret = array();
     $elasticaClient = PluginSearchElasticsearch::make_client();
     $elasticaIndex = $elasticaClient->getIndex(get_config_plugin('search', 'elasticsearch', 'indexname'));
     $elasticaQuery = new \Elastica\Query();
     // check user access to the views
     $elasticaFilterAnd = new \Elastica\Filter\BoolAnd();
     $elasticaFilterType = new \Elastica\Filter\Term(array('_type' => 'view'));
     $elasticaFilterAnd->addFilter($elasticaFilterType);
     $elasticaFilterIds = new \Elastica\Filter\Terms('id', array_keys($views));
     $elasticaFilterAnd->addFilter($elasticaFilterIds);
     // Apply ACL filters
     $elasticaFilterACL = new ElasticsearchFilterAcl($USER);
     $elasticaFilterAnd->addFilter($elasticaFilterACL);
     $elasticaFilteredQuery = new \Elastica\Query\Filtered(null, $elasticaFilterAnd);
     $elasticaQuery->setQuery($elasticaFilteredQuery);
     $elasticaResultSet = $elasticaIndex->search($elasticaQuery);
     $elasticaResults = $elasticaResultSet->getResults();
     foreach ($elasticaResults as $elasticaResult) {
         $data = $elasticaResult->getData();
         $ret[$data['id']] = $views[$data['id']];
     }
     return $ret;
 }
Exemplo n.º 4
0
<?php

/**
 *
 * @package    mahara
 * @subpackage search-elasticsearch
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 * 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";