Queries google for the specified search query

@param string $query
@param int $start
@param int $max
@param bool $filter
@param bool $restrict
@param bool $safe
@param string $lr
@param string $ie
@param string $oe
@throws Exception
356834
function DoSearch($query, $start=0, $max=10, $filter=false, $restrict="", $safe=false, $lr="", $ie="", $oe="")
	{
		$result = null;
		$continue = true;
		$counter = 0;
		
		while ($continue)
		{
			$counter++;
			try
			{
				$result = $this->_googleSoap($query, $start, $max, $filter, $restrict, $safe, $lr, $ie, $oe);
				$continue = false;
			}
			catch (exception $ex)
			{
				$this->FailedRequests++;
				
				if (preg_match("/Daily limit/i", $ex->getMessage()) || preg_match("/Invalid/i", $ex->getMessage())) 
				{
					throw $ex;
				}

				if ($counter > 2)
				{
					throw new Exception("Tried to contact Google API $counter times without success:" . $ex->getMessage());
				}

			}

		}
		
		return $result;

	}
1217026
public function search($query, $lang = 'en', $limit = 10) 
    {    
        $client = new Client(); 

        $response = $client->get(self::API_ENDPOINT, [
            'query' => [
                'action' => 'wbsearchentities',
                'format' => 'json',
                'strictlanguage' => true,
                'language' => $lang,
                'uselang' => $lang,
                'search' => $query,
                'limit' => $limit,
                'props' => ''
            ]
        ]);

        $results = json_decode($response->getBody(), true);

        $data = isset($results['search']) ? $results['search'] : [];

        $collection = collect($data);

        $output = $collection->map(function($item) use ($lang) {
            return new SearchResult($item, $lang, 'api');
        });

        return $output;
    }
898304
public function selectOne( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_row( $query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return $result;
	}
849566
private function prepareQueryFiler($query)
    {
        $result = [];
        foreach ($query as $key => $value) {
            if (is_array($value)) {
                $result[$key] = $this->prepareQueryFiler($value);
            } elseif (is_string($value) && preg_match('#^(MongoDB\\\\BSON\\\\[A-Za-z]+)\\((.*)\\)$#s', $value, $matches)) {
                $class = $matches[1];
                $objectValue = $matches[1];

                try {
                    $result[$key] = new $class($objectValue);
                } catch (\Exception $e) {
                    $result[$key] = $value;
                }
            } else {
                $result[$key] = $value;
            }
        }
        return $result;
    }
5277
protected function executeQuery($query)
        {
            $res = @odbc_exec($this->_lnk, $query);
            if(!$res) {
                $error = odbc_errormsg($this->_lnk);
                $this->log('Query failed: '.$error);
                throw new Exception('Executing query failed ' . $error, self::QUERY_FAILED);
            }
            return $res;
        }
463350
public function formExtendQuery($query)
    {
        if (!$this->user->isSuperUser()) {
            $query->where('is_superuser', false);
        }

        // Ensure soft-deleted records can still be managed
        $query->withTrashed();
    }
379862
public function defineSearch($query, $type)
    {
        $query = Util::escapeTerm($query);

        $elasticaQueryString = new Match();
        $elasticaQueryString
            ->setFieldMinimumShouldMatch('content', '80%')
            ->setFieldQuery('content', $query);

        if ($this->useMatchQueryForTitle) {
            $elasticaQueryTitle = new Match();
            $elasticaQueryTitle
              ->setFieldQuery('title', $query)
              ->setFieldMinimumShouldMatch('title', '80%')
              ->setFieldBoost(2);
        } else {
            $elasticaQueryTitle = new QueryString();
            $elasticaQueryTitle
              ->setDefaultField('title')
              ->setQuery($query);
        }

        $elasticaQueryBool = new BoolQuery();
        $elasticaQueryBool
            ->addShould($elasticaQueryTitle)
            ->addShould($elasticaQueryString)
            ->setMinimumShouldMatch(1);

        $this->applySecurityFilter($elasticaQueryBool);

        if (!is_null($type)) {
            $elasticaQueryType = new Term();
            $elasticaQueryType->setTerm('type', $type);
            $elasticaQueryBool->addMust($elasticaQueryType);
        }

        $rootNode = $this->domainConfiguration->getRootNode();
        if (!is_null($rootNode)) {
            $elasticaQueryRoot = new Term();
            $elasticaQueryRoot->setTerm('root_id', $rootNode->getId());
            $elasticaQueryBool->addMust($elasticaQueryRoot);
        }

        $rescore = new \Elastica\Rescore\Query();
        $rescore->setRescoreQuery($this->getPageBoosts());

        $this->query->setQuery($elasticaQueryBool);
        $this->query->setRescore($rescore);
        $this->query->setHighlight(
            array(
                'pre_tags' => array('<strong>'),
                'post_tags' => array('</strong>'),
                'fields' => array(
                    'content' => array(
                        'fragment_size' => 150,
                        'number_of_fragments' => 3,
                    ),
                ),
            )
        );
    }
17359
public void search(String query) {
        final Query newQuery = searcher.getQuery().setQuery(query);
        searcher.setQuery(newQuery).search();
    }
105659
public function execute( $query ) {
		if ( $query instanceof QueryBuilder ) {
			$query = $query->getSPARQL();
		}

		if ( !is_string( $query ) ) {
			throw new InvalidArgumentException( '$query has to be a string or an instance of QueryBuilder' );
		}

		$result = $this->getResult( $query );
		
		// TODO also support ask queries (with key 'boolean')
		//      https://www.w3.org/TR/rdf-sparql-json-res/
		return $result['results'];
	}
984751
public function executeQuery($query, $limit = 10)
    {
        $query = trim($query);

        if (strtoupper(substr($query, 0, 6)) !== "SELECT") {
            throw new SqlException(
                $this->translator->trans("Invalid SQL query. It must start with SELECT", [], IndexEngine::MESSAGE_DOMAIN)
            );
        }

        if (substr($query, -1) !== ";") {
            $query .= ";";
        }

        if (substr_count($query, ";") > 2) {
            throw new SqlException(
                $this->translator->trans("Invalid SQL query. It must only contain one query", [], IndexEngine::MESSAGE_DOMAIN)
            );
        }

        try {
            $stmt = $this->con->query($query);
            $stmt->execute();

            $data = $stmt->fetchAll(\PDO::FETCH_NAMED);

            if (count($data) > $limit) {
                $data = array_slice($data, 0, $limit);
            }

            return $data;
        } catch (\PDOException $e) {
            throw new SqlException(
                $this->translator->trans(
                    "Invalid SQL query: %exception",
                    ["%exception" => $e->getMessage()],
                    IndexEngine::MESSAGE_DOMAIN
                )
            );
        }
    }
329238
public function search($query)
    {
        if ($this->hasSearch()) {

            $search = $this->search;

            // If it's a anonymous function
            if (!is_string($search) && is_callable($search)) {
                call_user_func($search, $this, $query);
            }
        }

        return $this;
    }
649902
public function validateQuery($query)
    {
        if (!is_string($query) && !method_exists($query, '__toString')) {
            throw new InvalidArgumentException(
                'Query must be a string'
            );
        }

        if (strpos($query, '#') !== false) {
            throw new InvalidArgumentException(
                'Query must not contain a URI fragment'
            );
        }
    }
931142
public function getResults($query)
    {
        $searchResults = [];

        if ($query == '') {
            return $searchResults;
        }

        if ($this->searchEngineId == '') {
            throw new \Exception('You must specify a searchEngineId');
        }

        $client = new Client();
        $result = $client->get('http://www.google.com/cse', ['query' => ['cx' => $this->searchEngineId,
                'client' => 'google-csbe',
                'num' => 20,
                'output' => 'xml_no_dtd',
                'q' => $query,
            ],
        ]);

        if ($result->getStatusCode() != 200) {
            throw new Exception('Resultcode was not ok: '.$result->getStatusCode());
        }

        $xml = simplexml_load_string($result->getBody());

        if ($xml->ERROR) {
            throw new Exception('XML indicated service error: '.$xml->ERROR);
        }

        if ($xml->RES->R) {
            $i = 0;
            foreach ($xml->RES->R as $item) {
                $searchResults[$i]['name'] = (string) $item->T;
                $searchResults[$i]['url'] = (string) $item->U;
                $searchResults[$i]['snippet'] = (string) $item->S;
                $searchResults[$i]['image'] = $this->getPageMapProperty($item, 'cse_image', 'src');

                $searchResults[$i]['product']['name'] = $this->getPageMapProperty($item, 'product', 'name');
                $searchResults[$i]['product']['brand'] = $this->getPageMapProperty($item, 'product', 'brand');
                $searchResults[$i]['product']['price'] = $this->getPageMapProperty($item, 'product', 'price');
                $searchResults[$i]['product']['image'] = $this->getPageMapProperty($item, 'product', 'image');
                $searchResults[$i]['product']['identifier'] = $this->getPageMapProperty($item, 'product', 'identifier');

                $searchResults[$i]['offer']['price'] = $this->getPageMapProperty($item, 'offer', 'price');
                $searchResults[$i]['offer']['pricecurrency'] = $this->getPageMapProperty($item, 'offer', 'pricecurrency');

                ++$i;
            }
        }

        return $searchResults;
    }
919274
public function query($query, array $binds = array())
    {
        //Argument 1 must be a string or null
        Argument::i()->test(1, 'string', self::QUERY);
        
        $request = new \stdClass();
        
        $request->query = $query;
        $request->binds = $binds;
        
        //event trigger
        $this->trigger('sql-query-before', $request);
        
        $connection = $this->getConnection();
        $query      = (string) $request->query;
        $stmt       = $connection->prepare($query);
        
        //bind some more values
        foreach ($request->binds as $key => $value) {
            $stmt->bindValue($key, $value);
        }
        
        //PDO Execute
        if (!$stmt->execute()) {
            $error = $stmt->errorInfo();
            
            //unpack binds for the report
            foreach ($binds as $key => $value) {
                $query = str_replace($key, "'$value'", $query);
            }
            
            //throw Exception
            Exception::i()
                ->setMessage(Exception::QUERY_ERROR)
                ->addVariable($query)
                ->addVariable($error[2])
                ->trigger();
        }
        
        $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        
        if($this->queryCache) {
            //log query
            $this->queries[] = array(
                'query'     => $query,
                'binds'     => $binds,
                'results'   => $results);
        }

        //clear binds
        $this->binds = array();
        
        //event trigger
        $this->trigger('sql-query-after', $query, $binds, $results);
        
        return $results;
    }
535770
private static function logQuery(string $query): void
  {
    $query = trim($query);

    if (strpos($query, "\n")!==false)
    {
      // Query is a multi line query.
      self::$io->logVeryVerbose('Executing query:');
      self::$io->logVeryVerbose('<sql>%s</sql>', $query);
    }
    else
    {
      // Query is a single line query.
      self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
    }
  }
385206
public function buildQuery($query)
    {
        $q = $this->request->getQuery();

        foreach ($query as $key => $value)
        {
            $q[$key] = $value;
        }
    }
455165
public function exec($query, $args = array(), $removeCache = null)
    {
        if ($this->connection) {
            if ($this->getCache() && $removeCache) {
                $this->getCache()->remove($removeCache);
            }
            return $this->connection->select($query, $args, false);
        }
        throw new \Exception('Database connection is not open!');
    }