Search in the set indices, types.

@param mixed     $query
@param int|array $options OPTIONAL Limit or associative array of options (option=>value)

@throws \Elastica\Exception\InvalidException

@return \Elastica\ResultSet
331947
public function search($query = '', $options = null)
    {
        $this->setOptionsAndQuery($options, $query);

        $query = $this->getQuery();
        $path = $this->getPath();

        $params = $this->getOptions();

        // Send scroll_id via raw HTTP body to handle cases of very large (> 4kb) ids.
        if ('_search/scroll' == $path) {
            $data = [self::OPTION_SCROLL_ID => $params[self::OPTION_SCROLL_ID]];
            unset($params[self::OPTION_SCROLL_ID]);
        } else {
            $data = $query->toArray();
        }

        $response = $this->getClient()->request(
            $path,
            Request::GET,
            $data,
            $params
        );

        return $this->_builder->buildResultSet($response, $query);
    }
1265143
public function select($query, $params = [], $type = null) {

		$type = $type === null ? $this -> getEntityNamespace($this -> getTable()) : $type;

		if(null === $this -> getAdapter()) {
			return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
		}
		
		return new ResultSet($this -> getAdapter() -> query($query, $params) -> toArray(), $type, $this -> getAdapter());
	}
83089
public function _search($query, $parameters = [])
    {
        /** @var \AlgoliaSearch\Laravel\ModelHelper $modelHelper */
        $modelHelper = App::make('\AlgoliaSearch\Laravel\ModelHelper');

        $index = null;

        if (isset($parameters['index'])) {
            $index = $modelHelper->getIndices($this, $parameters['index'])[0];
            unset($parameters['index']);
        } else {
            $index = $modelHelper->getIndices($this)[0];
        }

        $result = $index->search($query, $parameters);

        return $result;
    }
736211
public function read($query, array $options = []) {
		$query = !is_object($query) ? new Query() : $query;
		$query->method() ?: $query->method("get");
		$query->path() ?: $query->path("/{:source}");

		$params = [$query, $options];

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			list($query, $options) = $params;
			return $this->send($query, $options);
		});
	}
879490
public function delete($query, array $options = []) {
		$this->_checkConnection();

		$defaults = [
			'justOne' => false,
			'w' => $this->_config['w'],
			'wTimeoutMS' => $this->_config['wTimeoutMS'],
			'fsync' => false
		];
		$options = array_intersect_key($options + $defaults, $defaults);
		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$prefix = $this->_config['gridPrefix'];

			$query = $params['query'];
			$options = $params['options'];
			$args = $query->export($this, ['keys' => ['source', 'conditions']]);
			$source = $args['source'];
			$conditions = $args['conditions'];

			if ($source === "{$prefix}.files") {
				$result = $this->_deleteFile($conditions);
			} else {
				$result = $this->connection->{$args['source']}->remove($conditions, $options);
				$result = $this->_ok($result);
			}
			if ($result && $query->entity()) {
				$query->entity()->sync(null, [], ['dematerialize' => true]);
			}
			return $result;
		});
	}
534593
public function queryTableGenerator($query, $options = [])
    {
        $statement = $this->_runQuery($query, $options);
        while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
            yield $row;
        }
    }
1203855
public function search($query, array $options = [])
    {
        // Max number of records to fetch. Set to 0 to fetch all.
        $limit = array_key_exists('limit', $options) ? $options['limit'] : 0;

        // Set to true to do a phrase search
        $phrase = array_key_exists('phrase', $options) ? $options['phrase'] : false;

        // Set to true to expand all query results to full records.
        // Please note that this will make queries significantly slower!
        $expand = array_key_exists('expand', $options) ? $options['expand'] : false;

        // Number of records to fetch each batch. Usually no need to change this.
        $batchSize = array_key_exists('batchSize', $options) ? $options['batchSize'] : 10;

        if ($limit != 0 && $limit < $batchSize) {
            $batchSize = $limit;
        }

        // The API will throw a 400 response if you include properly encoded spaces,
        // but underscores work as a substitute.
        $query = explode(' AND ', $query);
        $query = $phrase ? str_replace(' ', '_', $query) : str_replace(' ', ',', $query);
        $query = implode(' AND ', $query);

        $offset = 0;
        while (true) {
            $response = $this->client->getJSON('/users', ['q' => $query, 'limit' => $batchSize, 'offset' => $offset]);

            // The API sometimes returns total_record_count: -1, with no further error message.
            // Seems to indicate that the query was not understood.
            // See: https://github.com/scriptotek/php-alma-client/issues/8
            if ($response->total_record_count == -1) {
                throw new InvalidQuery($query);
            }

            if ($response->total_record_count == 0) {
                break;
            }

            if (!isset($response->user) || empty($response->user)) {
                // We cannot trust the value in 'total_record_count', so if there are no more records,
                // we have to assume the result set is depleted.
                // See: https://github.com/scriptotek/php-alma-client/issues/7
                break;
            }

            foreach ($response->user as $data) {
                $offset++;
                // Contacts without a primary identifier will have the primary_id
                // field populated with something weird like "no primary id (123456789023)".
                // We ignore those.
                // See: https://github.com/scriptotek/php-alma-client/issues/6
                if (strpos($data->primary_id, 'no primary id') === 0) {
                    continue;
                }
                $user = User::make($this->client, $data->primary_id)
                    ->init($data);
                if ($expand) {
                    $user->init();
                }
                yield $user;
            }
            if ($offset >= $response->total_record_count) {
                break;
            }
            if ($limit != 0 && $offset >= $limit) {
                break;
            }
        }
    }
145272
public function queryTable($query, $options = array())
    {
        return $this->queryArray($query, $options,
            function(\PDOStatement $statement) { return $statement->fetchAll(\PDO::FETCH_ASSOC); }
        );
    }
1189720
public function query($query=null, $params = [])
    {
        $result = false;
        $result_key = [];
        
        if ($query && static::isSql($query)) {
            $sql = $query;
        } else {
            $result_key = $this->getQuery()->set($query)->get('result_key');
            
            $queryType = $this->getQuery()->type();
            
            // limit select count
            if ((!$queryType || $queryType === 'select') 
                && !isset($this->getQuery()['count']) 
                && !isset($this->getQuery()['limit'])
                && !isset($this->getQuery()['pagesize'])) 
            {
                $this->getQuery()->set('limit', 1000);
            }
            
            // update must set where
            if (($queryType === 'update' || $queryType === 'delete') && !$this->getQuery()->get('where')) {
                Ioc::logger('db')->error('query no set where: ' . json_encode($this->getQuery()->all()));
                return false;
            }
            
            $sql = $this->parse();
        }
        
        if ($params) {
            $this->bindParams($params);
        }
        
        $this->lastSql = $this->formatSql($sql);
        
        // sql log
        Ioc::logger('db')->debug($sql);
        
        try {
            $this->getAdapter()->prepare($sql);
            if (!empty($this->binds)) {
                $this->getAdapter()->bindParams($this->binds);
            }
            $bool = $this->getAdapter()->execute();
            
            if (!$bool) {
                throw new Exception($this->getAdapter()->getErrorMessage());
            }
        } catch (Exception $e) {
            
            $this->getAdapter()->rollback();
            throw new Exception('Excute sql error: ' . $e->getMessage() . ', sql:' . $sql);
        }
        
        $rawStatement = explode(" ", $sql);
        $statement = strtolower(trim($rawStatement[0]));
        
        if ($statement === 'show') {
            $result = $this->getAdapter()->fetchAll($fetchmode);
        } elseif ($statement === 'select') {
            $rkeys = $result_key ? StringHelper::toArray($result_key, ',\s') : null;
            
            while($rs = $this->getAdapter()->fetch()) {
                // 如果指定返回结果集的key，则按key重组数据
                if ($rkeys) {
                    if (count($rkeys) == 1) {
                        $rk1 = trim($rkeys[0]);
                        if (isset($rs[$rk1])) {
                            $result[$rs[$rk1]] = $rs;
                        } else {
                            $result[] = $rs;
                        }
                    } elseif (count($rkeys) == 2) {
                        $rk1 = trim($rkeys[0]);
                        $rk2 = trim($rkeys[1]);
                        if (!empty($rk2)) {
                            $result[$rs[$rk1]][$rs[$rk2]] = $rs;
                        } else {
                            $result[$rs[$rk1]][] = $rs;
                        }
                    }
                } else {
                    $result[] = $rs;
                }
            }
        } elseif ($statement === 'update' || $statement === 'delete') {
            $result = $this->getAdapter()->numberOfRows();
        } elseif ($statement === 'insert') {
            $result = $this->getAdapter()->lastId();
        } else {
            return null;
        }
        
        return $result;
    }
1193907
public function findSlugForFilterData(Query $query, array $options)
    {
        if (!isset($options['request']) || get_class($options['request']) !== ServerRequest::class) {
            user_error('The request query option must exist and must be of type Cake\Http\ServerRequest.');
        }

        if (!isset($options['filterData'])) {
            user_error('No filterData option provided.');
        }

        /** @var ServerRequest $request */
        $request = $options['request'];
        $filterData = $options['filterData'];

        return $query
            ->select($this->getAlias() . '.slug')
            ->where([
                $this->getAlias() . '.controller' => $request->getParam('controller'),
                $this->getAlias() . '.action' => $request->getParam('action'),
                $this->getAlias() . '.filter_data' => $this->_encodeFilterData($filterData)
            ])
            ->where($this->_pluginCondition($request));
    }
675346
public function queryAssoc($query, $options = array())
    {
        $statement = $this->_runQuery($query, $options);
        return $statement->fetch(\PDO::FETCH_ASSOC);
    }
919329
public function findFilterDataBySlug(Query $query, array $options)
    {
        if (!isset($options['request']) || get_class($options['request']) !== ServerRequest::class) {
            user_error('The request query option must exist and must be of type Cake\Http\ServerRequest.');
        }

        $encryptedFilterData = $this->_findEncryptedFilterData($query, $options['request'])->first();

        if ($encryptedFilterData) {
            $encryptedFilterData = $encryptedFilterData->toArray();
            return $this->_decodeFilterData($encryptedFilterData['filter_data']);
        }

        return [];
    }
803472
protected function whereBatchId($query, EntryQueryOptions $options)
    {
        $query->when($options->batchId, function ($query, $batchId) {
            return $query->where('batch_id', $batchId);
        });

        return $this;
    }
871172
public function queryValue($query, $options = array())
    {
        $statement = $this->_runQuery($query, $options);
        return $statement->fetch(\PDO::FETCH_COLUMN);
    }
373644
public function create($query, array $options = []) {
		$this->_checkConnection();

		$defaults = [
			'w' => $this->_config['w'],
			'wTimeoutMS' => $this->_config['wTimeoutMS'],
			'fsync' => false
		];
		$options += $defaults;

		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$exporter = $this->_classes['exporter'];
			$prefix = $this->_config['gridPrefix'];

			$query   = $params['query'];
			$options = $params['options'];

			$args    = $query->export($this, ['keys' => ['source', 'data']]);
			$data    = $exporter::get('create', $args['data']);
			$source  = $args['source'];

			if ($source === "{$prefix}.files" && isset($data['create']['file'])) {
				$result = ['ok' => true];
				$data['create']['_id'] = $this->_saveFile($data['create']);
			} else {
				$result = $this->connection->{$source}->insert($data['create'], $options);
				$result = $this->_ok($result);
			}

			if ($result === true || isset($result['ok']) && (boolean) $result['ok'] === true) {
				if ($query->entity()) {
					$query->entity()->sync($data['create']['_id']);
				}
				return true;
			}
			return false;
		});
	}
610216
public function search($objectType, $query = [])
    {
        $results = [];
        if ($this->isSearchable($objectType)) {
            foreach ($this->get($objectType) as $line) {
                foreach ($query as $field => $needle) {
                    if (isset($line[$field])) {
                        if (stripos($line[$field], $needle) !== false) {
                            $results[] = $line;
                        }
                    }
                }
            }
        }

        return new Iterator($results);
    }
1115438
private function fetchOptions($parameters, &$query): array
    {
        $allowed = array_keys($this->options);

        $result = [];
        foreach ($parameters as $key => $parameter) {
            if (is_numeric($key) && isset($allowed[$key])) {
                // this segment fetched keys from given parameters either by name or by position
                $key = $allowed[$key];
            } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) {
                // all additional parameters given in array form can be glued to query string
                $query[$key] = $parameter;
                continue;
            }

            //String must be normalized here
            if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) {
                $result[$key] = $this->slugify->slugify($parameter);
                continue;
            }

            $result[$key] = (string)$parameter;
        }

        return $result;
    }