@see https://www.mediawiki.org/wiki/API:Search

@param string $query
@param int|null $namespace
@return void
969245
protected function setGeneratorSearch($query, $namespace = null)
    {
        $this->logger->debug('Base:setGeneratorSearch');
        $this->setParam('generator', 'search');
        $this->setParam('gsrlimit', $this->getLimit());
        $this->setParam('gsrsearch', $query);
        if ($namespace) {
            $this->setParam('gsrnamespace', $namespace);
        }
    }
117234
public function searchTv($query, array $parameters = [], array $headers = [])
    {
        return $this->get('search/tv', array_merge($parameters, [
            'query' => $query
        ], $headers));
    }
1332839
public function execute($query, $params = []) : object
    {
        self::$queries[] = $query;
        self::$params[]  = $params;
        self::$numQueries++;

        if ($this->options['verbose']) {
            echo "<p>Num query = "
                . self::$numQueries
                . "</p><p>Query = </p><pre>"
                . htmlentities($query)
                . "</pre>"
                . (empty($params)
                    ? null
                    : "<p>Params:</p><pre>" . htmlentities(print_r($params, 1)) . "</pre>"
                );
        }

        return parent::execute($query, $params);
    }
172298
public function visit($query, $node, string $context)
    {
        if ($node instanceof $this->node) {
            $child0 = $node->getChildByIndex(0);
            $child1 = $node->getChildByIndex(1);

            if ($context === Nodes\OrNode::class) {
                $query->orWhere($this->parseNode($query, $child0), $this->operator, $this->parseNode($query, $child1));
            }

            if ($context === Nodes\AndNode::class) {
                $query->where($this->parseNode($query, $child0), $this->operator, $this->parseNode($query, $child1));
            }
        }
    }
795241
public function HasNamespace($namespace, $header="")
    {
        if($header)
        {
            if(isset($this->headers[$header]->namespaces[$namespace]))
            {
                return $this->headers[$header]->namespaces[$namespace];
            }
        }
        else
        {
            foreach($this->headers as $header_object)
            {
                if(isset($header_object->namespaces[$namespace]))
                {
                    return $header_object->namespaces[$namespace];
                }
            }
        }
        
        return null;
    }
1065504
public function searchMulti($query, KeywordSearchQuery $parameters, array $headers = [])
    {
        $data       = $this->getApi()->searchMulti($query, $this->getParameters($parameters), $headers);
        $collection = new ResultCollection();

        if (null === $data) {
            return $collection;
        }

        if (array_key_exists('page', $data)) {
            $collection->setPage($data['page']);
        }

        if (array_key_exists('total_pages', $data)) {
            $collection->setTotalPages($data['total_pages']);
        }

        if (array_key_exists('total_results', $data)) {
            $collection->setTotalResults($data['total_results']);
        }

        if (array_key_exists('results', $data)) {
            foreach ($data['results'] as $item) {
                if ($item) {
                    $collection->add(null, $this->processSearchMultiItem($item));
                }
            }
        }

        return $collection;
    }
121470
public static function delete(string $name, string $namespace = '*'): void
    {
        self::initialize();
        if (isset($_SESSION[$namespace][$name])) {
            unset($_SESSION[$namespace][$name]);
            if (count($_SESSION[$namespace]) === 0) {
                unset($_SESSION[$namespace]);
            }
        }
    }
1010876
public function deleteFrom($namespace, $key)
    {
        if (isset($_SESSION[$namespace])) {
            $oldNamespace = $this->namespace;
            $this->setNamespace($namespace);
            $this->delete($key);
            $this->setNamespace($oldNamespace);
        }
    }
1324783
public function searchKeyword($query, array $parameters = [], array $headers = [])
    {
        return $this->get('search/keyword', array_merge($parameters, [
            'query' => $query
        ], $headers));
    }
381487
protected function executeQuery($query)
    {
        $query   = null !== $this->getLocale() ? sprintf('%s&language=%s', $query, $this->getLocale()) : $query;
        $content = $this->getAdapter()->get($query)->getBody();

        if (!$data = json_decode($content, true)) {
            throw new NoResult(sprintf('Could not execute query: %s', $query));
        }

        if (!isset($data['Response']) && 'InvalidCredentials' === $data['subtype']) {
            throw new InvalidCredentials(sprintf('Invalid credentials: %s', $data['details']));
        } elseif (!isset($data['Response'])) {
            throw new NoResult(
                sprintf('Error type `%s` returned from api `%s`', $data['subtype'], $data['Details'])
            );
        }

        if (empty($data['Response']['View'])) {
            throw new NoResult(sprintf('Could not find results for given query: %s', $query));
        }

        $locations = $data['Response']['View'][0]['Result'];

        $results = array();
        foreach ($locations as $location) {
            $location       = $location['Location'];
            $coordinates    = isset($location['NavigationPosition'][0]) ? $location['NavigationPosition'][0] : $location['DisplayPosition'];
            $bounds         = $location['MapView'];
            $address        = $location['Address'];
            $additionalData = $location['Address']['AdditionalData'];

            $results[] = array_merge($this->getDefaults(), array(
                'latitude'     => $coordinates['Latitude']  ?: null,
                'longitude'    => $coordinates['Longitude'] ?: null,
                'bounds'       => array(
                    'south' => $bounds['BottomRight']['Latitude']  ?: null,
                    'west'  => $bounds['TopLeft']['Longitude']     ?: null,
                    'north' => $bounds['TopLeft']['Latitude']      ?: null,
                    'east'  => $bounds['BottomRight']['Longitude'] ?: null,
                ),
                'streetNumber' => isset($address['HouseNumber']) ? $address['HouseNumber'] : null,
                'streetName'   => isset($address['Street'])      ? $address['Street']      : null,
                'city'         => isset($address['City'])        ? $address['City']        : null,
                'cityDistrict' => isset($address['District'])    ? $address['District']    : null,
                'zipcode'      => isset($address['PostalCode'])  ? $address['PostalCode']  : null,
                'county'       => isset($address['County'])      ? $address['County']      : null,
                'regionCode'   => isset($address['State'])       ? $address['State']       : null,
                'countryCode'  => isset($address['Country'])     ? $address['Country']     : null,
                'region'       => $this->findByKey('StateName', $additionalData),
                'country'      => $this->findByKey('CountryName', $additionalData),
                'countyCode'   => null,
            ));
        }

        return $results;
    }
515996
public function search($query)
  {
    $content = $query->getBridgeJson($this->clientKey);

    return $this->query($this->bridgeUrl, $content, self::RESULTS_CLASS);
  }
669275
public function visit($query, NodeContract $node, string $context)
    {
        if ($node instanceof Nodes\KeyNode) {
            $key = $node->getValue();

            $keys = explode('.', $key);

            if (count($keys) === 1) {
                $keys = [$this->getBaseTable(), $keys[0]];
            }

            $key = implode('.', $keys);

            $node->setValue($key);

            if ($this->getKeys()[0] === '*') {
                return;
            }

            if (!in_array($key, $this->getKeys())) {
                throw new QuerySyntaxException();
            }
        }

        foreach ($node->getChildren() as $child) {
            $this->visit($query, $child, $context);
        }
    }
526530
public static function getAllElementsByXpath($node, $xpath_query, $namespaces = array())
    {
        if(is_a($node, 'DOMDocument'))
        {
            $xpath = new DOMXPath($node);
        }
        elseif(is_a($node, 'DOMNode'))
        {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        else
        {
            return null;
        }

        foreach($namespaces as $prefix => $namespaceURI)
        {
            $xpath->registerNamespace($prefix, $namespaceURI);
        }

        $node_list = $xpath->query($xpath_query, $node);

        return $node_list;
    }
823444
protected function _where($query)
    {
        $link = null;
        $type_check = true;

        if ($query instanceof AnConfig) {
            $type_check = false;
            $query = $query->query;
        }

        $description = $query->getRepository()->getDescription();
        $clauses = array();
        if ($description->getInheritanceColumn() && $type_check) {
            $resource = $description->getInheritanceColumn()->resource->getAlias();
            //the table type column name
            $type_column_name = $resource.'.'.$description->getInheritanceColumn()->name;

            $scopes = AnConfig::unbox($query->instance_of);
            if (empty($scopes)) {
                $scopes = array($description);
            } else {
                if (!is_array($scopes)) {
                    $scopes = array($scopes);
                }
            }

            foreach ($scopes as $index => $scope) {
                $inheritance_type = $this->_inheritanceTree($scope);
                if (!empty($inheritance_type) && $inheritance_type != '%') {
                    $operator = substr($inheritance_type, -1) == '%' ? 'LIKE' : '=';
                    $scopes[$index] = $type_column_name.' '.$operator.' \''.$inheritance_type.'\'';
                } else {
                    unset($scopes[$index]);
                }
            }
            if (!empty($scopes)) {
                $clauses[] = '('.implode(' OR ', $scopes).')';
            }
        }

        if (!empty($query->where)) {
            $clause = '';
            foreach ($query->where as $where) {
                $clause .= $this->_buildWhere($query, $where);
            }
            if (!empty($clause)) {
                $clauses[] = '('.$clause.')';
            }
        }

        foreach ($query->link as $link) {
            $clauses = array_merge($clauses, $this->_where($link));
        }

        return $clauses;
    }
1185777
public function recommendedFor($query)
    {
        $requestOptions = [
            'scope' => 'pins',
            'query' => $query,
        ];

        $result = $this->get(UrlBuilder::RESOURCE_SEARCH, $requestOptions);

        return empty($result) ? [] : $this->getKeywordsFromRequest($result);
    }
887464
public function searchPersons($query, array $parameters = [], array $headers = [])
    {
        return $this->get('search/person', array_merge($parameters, [
            'query' => $query
        ], $headers));
    }
1308894
protected function selectQuerySource(&$query)
    {
        foreach ($query['trace'] as $i => &$trace) {
            $isSource = true;
            foreach ($this->getNamespacesCutoff() as $namespace) {
                $namespace = trim($namespace, '/\\').'\\';
                if (isset($trace['class']) && strpos($trace['class'], $namespace) !== false) {
                    $isSource = false;
                }
            }
            if ($isSource) {
                $query['trace'][$i - 1]['query_source'] = true;
                break;
            }
        }
    }