Example #1
0
function elasticsearch_search_tags_hook_handler($hook, $type, $return_value, $params)
{
    $limit = $params["limit"] ? $params["limit"] : 10;
    $offset = $params["offset"] ? $params["offset"] : 0;
    $query = $params["{$query}"];
    $results = ESInterface::get()->search($params["query"], SEARCH_TAGS, "object", [], $params["limit"], $params["offset"]);
    return ["count" => $results["count"], "entities" => $results["entities"]];
}
Example #2
0
 public function execute()
 {
     foreach ($this->tasks["update"] as $object) {
         ESInterface::get()->update($object);
     }
     foreach ($this->tasks["delete"] as $object) {
         ESInterface::get()->delete($object);
     }
 }
Example #3
0
function elasticsearch_console_index_reset()
{
    $interface = ESInterface::get();
    if ($interface->resetIndex()) {
        if ($interface->putMapping()) {
            echo "Index and mapping created succesfully.";
        } else {
            echo "Could not create mapping.";
        }
    } else {
        echo "Could not create index.";
    }
}
Example #4
0
function ws_pack_search($query, $offset = 0, $limit = 20)
{
    if (!elgg_is_logged_in()) {
        $ia = elgg_set_ignore_access(true);
    }
    $results = ESInterface::get()->search($query, "all", null, null, (int) $limit, (int) $offset);
    $json = array();
    $json["total"] = $results["count"];
    if ($results["count"] > 0) {
        $json["results"] = ws_pack_export_entities($results["hits"]);
    } else {
        $json["results"] = array();
    }
    if (!elgg_is_logged_in()) {
        elgg_set_ignore_access($ia);
    }
    return $json;
}
Example #5
0
<?php

$q = sanitise_string(get_input("q"));
$limit = max((int) get_input("limit", 5), 1);
$page_owner_guid = (int) get_input("page_owner_guid");
$result = array();
if (!empty($q)) {
    $users = ESInterface::get()->search($q, 'all', 'user', false, $limit, 0, false, false);
    $groups = ESInterface::get()->search($q, 'all', 'group', false, $limit, 0, false, false);
    $users = $users['hits'];
    $groups = $groups['hits'];
    $result = array();
    if ($users) {
        $result[] = array("type" => "placeholder", "content" => "<label>" . elgg_echo("item:user") . "</label>");
        foreach ($users as $user) {
            $result[] = array("type" => "user", "value" => $user->name, "href" => $user->getURL(), "content" => elgg_view("search/autocomplete/user", array("entity" => $user)));
        }
    }
    if ($groups) {
        $result[] = array("type" => "placeholder", "content" => "<label>" . elgg_echo("item:group") . "</label>");
        foreach ($groups as $group) {
            $result[] = array("type" => "group", "value" => $group->name, "href" => $group->getURL(), "content" => elgg_view("search/autocomplete/group", array("entity" => $group)));
        }
    }
}
header("Content-Type: application/json");
echo json_encode(array_values($result));
exit;
Example #6
0
// check that we have an actual query
if (!$query && !(count($profile_filter) > 0 && $entity_type == "user")) {
    $title = sprintf(elgg_echo('search:results'), "\"{$display_query}\"");
    $body = elgg_view_title(elgg_echo('search:search_error'));
    if (!elgg_is_xhr()) {
        $body .= elgg_view_form("elasticsearch/search", array("action" => "search", "method" => "GET", "disable_security" => true), array());
    }
    $body .= elgg_echo('search:no_query');
    if (!elgg_is_xhr()) {
        $layout = elgg_view_layout('one_sidebar', array('content' => $body));
        $body = elgg_view_page($title, $layout);
    }
    echo $body;
    return;
}
$results = ESInterface::get()->search($query, $search_type, $type, $subtype, $limit, $offset, $sort, $order, $container_guid, $profile_fields);
$body = elgg_view_title(elgg_echo('elasticsearch:nr_results', array($results['count'], "\"{$display_query}\"")));
// add search form
if (!elgg_is_xhr()) {
    $body .= elgg_view_form("elasticsearch/search", array("action" => "search", "method" => "GET", "disable_security" => true), array('query' => $query, 'search_type' => $search_type, 'type' => $type, 'subtype' => $subtype, 'container_guid' => $container_guid));
}
$body .= elgg_view('elasticsearch/search/list', array('results' => $results, 'params' => array('limit' => $limit, 'offset' => $offset, 'query' => $query, 'search_type' => $search_type, 'type' => $type, 'subtype' => $subtype, 'container_guid' => $container_guid)));
$data = htmlspecialchars(http_build_query(array('q' => $query, 'search_type' => 'all')));
$url = elgg_get_site_url() . "search?{$data}";
$menu_item = new ElggMenuItem('all', elgg_echo('all'), $url);
elgg_register_menu_item('page', $menu_item);
$types = get_registered_entity_types();
$custom_types = elgg_trigger_plugin_hook('search_types', 'get_types', $params, array());
foreach ($types as $type => $subtypes) {
    // @todo when using index table, can include result counts on each of these.
    if (is_array($subtypes) && count($subtypes)) {
Example #7
0
 static function search($a, $args, $c)
 {
     $searchResult = \ESInterface::get()->search($args['q']);
     $results = array();
     foreach ($searchResult['hits'] as $hit) {
         $results[] = array("guid" => $hit->guid, "title" => $hit->title ? $hit->title : $hit->name, "url" => $hit->getURL());
     }
     return ["total" => $searchResult['count'], "results" => $results];
 }
Example #8
0
function elasticsearch_disable_event($event, $object_type, $object)
{
    return ESInterface::get()->disable($object);
}
Example #9
0
<?php

if (!elgg_is_xhr()) {
    register_error('rijkshuisstijl:xhr_only');
}
$q = get_input('q');
$search_type = 'default';
$return = array();
if ($q) {
    foreach ($CONFIG->search_types as list($type, $subtype)) {
        $results = ESInterface::get()->search($q, $search_type, $type, $subtype, 5);
        if ($subtype) {
            $typeString = $type . ":" . $subtype;
        } else {
            $typeString = $type;
        }
        $return[$typeString] = array();
        foreach ($results['hits'] as $result) {
            if (!in_array($result->getSubtype(), array('answer', 'comment'))) {
                if ($result->title) {
                    $title = $result->title;
                } else {
                    $title = $result->name;
                }
            } else {
                $title = $result->getContainerEntity()->title;
            }
            $return[$typeString][] = array('guid' => $result->guid, 'title' => html_entity_decode($title, ENT_QUOTES), 'time_created' => date('c', $result->time_created), 'url' => $result->getURL());
        }
    }
}