/**
  * Hook to return a search for content with a give tag (or tags)
  *
  * @param string $hook        the name of the hook
  * @param string $type        the type of the hook
  * @param string $returnvalue current return value
  * @param array  $params      supplied params
  *
  * @return void
  */
 public static function searchTags($hook, $type, $returnvalue, $params)
 {
     if (!empty($returnvalue)) {
         return;
     }
     $client = self::getClientForHooks($params);
     if (!$client) {
         return;
     }
     $type_subtype_pairs = elasticsearch_get_registered_entity_types_for_search();
     if (empty($type_subtype_pairs)) {
         return;
     }
     $types = [];
     foreach ($type_subtype_pairs as $type => $subtypes) {
         if (empty($subtypes)) {
             $types[] = $type;
             continue;
         }
         foreach ($subtypes as $subtype) {
             $types[] = "{$type}.{$subtype}";
         }
     }
     $client->search_params->setType($types);
     $tag_query = [];
     $tag_query['bool']['must']['term']['tags'] = strtolower($params['query']);
     $client->search_params->setQuery($tag_query);
     $client = elgg_trigger_plugin_hook('search_params', 'elasticsearch', ['search_params' => $params], $client);
     if ($params['count'] == true) {
         $result = $client->search_params->count();
     } else {
         $result = $client->search_params->execute();
     }
     return self::transformSearchResults($result, $params);
 }
Beispiel #2
0
 /**
  * Find entities in Elgg which aren't in Elasticsearch but should be
  *
  * @return void
  */
 protected static function checkElggIndex()
 {
     $client = elasticsearch_get_client();
     if (empty($client)) {
         return;
     }
     // this could take a while
     set_time_limit(0);
     // ignore access
     $ia = elgg_set_ignore_access(true);
     // find unindexed GUIDs
     $guids = [];
     $unindexed = [];
     $batch = new \ElggBatch('elgg_get_entities_from_private_settings', ['type_subtype_pairs' => elasticsearch_get_registered_entity_types_for_search(), 'limit' => false, 'private_setting_name_value_pairs' => ['name' => ELASTICSEARCH_INDEXED_NAME, 'value' => 0, 'operand' => '>']]);
     /* @var $entity \ElggEntity */
     foreach ($batch as $entity) {
         $guids[] = $entity->getGUID();
         if (count($guids) < 250) {
             continue;
         }
         $unindexed = array_merge($unindexed, self::findUnindexedGUIDs($guids));
         $guids = [];
     }
     if (!empty($guids)) {
         $unindexed = array_merge($unindexed, self::findUnindexedGUIDs($guids));
     }
     if (empty($unindexed)) {
         // restore access
         elgg_set_ignore_access($ia);
         return;
     }
     // reindex entities
     $reindex = new \ElggBatch('elgg_get_entities', ['guids' => $unindexed, 'limit' => false]);
     /* @var $entity \ElggEntity */
     foreach ($reindex as $entity) {
         // mark for reindex
         $entity->setPrivateSetting(ELASTICSEARCH_INDEXED_NAME, 0);
     }
     // restore access
     elgg_set_ignore_access($ia);
 }