Find models by query

@param string $searchQuery
@param int $regionId
@param int $page
@param int $pageSize
@param string $currency
@return GetMarketModelsResponse

@link https://tech.yandex.ru/market/partner/doc/dg/reference/get-models-docpage/
339243
public function findModels($searchQuery, $regionId, $page = null, $pageSize = null, $currency = null)
    {
        $resource = sprintf('models.%s', self::DECODE_TYPE_DEFAULT);
        $queryParams = $this->filterParams([
            'query' => $searchQuery,
            'regionId' => $regionId,
            'page' => $page,
            'pageSize' => $pageSize,
            'currency' => $currency,
        ]);

        $response = $this->sendRequest('GET', $this->getServiceUrl($resource), ['query' => $queryParams]);
        $decodedResponseBody = $this->getDecodedBody($response->getBody());

        return new GetMarketModelsResponse($decodedResponseBody);
    }
162512
public function getPager($criteria, $page = 1)
    {
        $container = $this->getContainer();

        $paginator = $container->get('knp_paginator');

        $settings = $this->getSettings();

        $limit = $settings['articles_per_page'];

        $parameters = [];

        /** @var ArticlesRepository $repository */
        $repository = $this->getRepository();

        $qb = $repository->createQueryBuilder('p');

        $qb->select('p')->orderBy('p.publicationAt', 'DESC');

        if (!isset($criteria['enabled'])) {
            $criteria['enabled'] = true;
        }

        if (isset($criteria['enabled'])) {
            $currentTime = new \DateTime();

            $qb->andWhere('p.enabled = :enabled');
            $qb->andWhere(
                $qb->expr()->lt('p.publicationAt', ':datetime')
            );

            $parameters['datetime'] = $currentTime;
            $parameters['enabled'] = $criteria['enabled'];
        }

        $qb->setParameters($parameters);

        $pagination = $paginator->paginate(
            $qb,
            $page,
            $limit
        );

        return $pagination;
    }
513732
public function getInformation($market, $currency, $locale, $id)
    {
        $url = implode('/', [$this->url, 'autosuggest', 'v1.0', $market, $currency, $locale]);
        $data = $this->request($url, compact('id'));
        return $data->Places ?? [];
    }
981126
private function getSearchResult(array $filters, $limit, $page, $pageSize, $locale, $webspaceKey)
    {
        $repository = $this->searchManager->getRepository($this->articleDocumentClass);
        $search = $this->createSearch($repository->createSearch(), $filters, $locale);
        if (!$search) {
            return new \ArrayIterator([]);
        }

        $this->addPagination($search, $pageSize, $page, $limit);

        if (array_key_exists('sortBy', $filters) && is_array($filters['sortBy'])) {
            $sortMethod = array_key_exists('sortMethod', $filters) ? $filters['sortMethod'] : 'asc';
            $this->appendSortBy($filters['sortBy'], $sortMethod, $search);
        }

        if ($webspaceKey) {
            $webspaceQuery = new BoolQuery();

            // check for mainWebspace
            $webspaceQuery->add(new TermQuery('main_webspace', $webspaceKey), BoolQuery::SHOULD);

            // check for additionalWebspaces
            $webspaceQuery->add(new TermQuery('additional_webspaces', $webspaceKey), BoolQuery::SHOULD);

            $search->addQuery($webspaceQuery);
        }

        return $repository->findDocuments($search);
    }
471634
public function search($params, $pageSize = 20)
    {
        $query = self::find()->joinWith('author');
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => $pageSize
            ]
        ]);

        $dataProvider->setSort([
            'defaultOrder' => ['id' => SORT_DESC],
        ]);

        // load the search form data and validate
        if (!($this->load($params)))
        {
            return $dataProvider;
        }

        //adjust the query by adding the filters
        $query->andFilterWhere(['id' => $this->id]);
        $query->andFilterWhere(['like', 'username', $this->createdBy]);
        $query->orFilterWhere(['like', 'anonymousUsername', $this->createdBy]);
        $query->andFilterWhere([self::tableName().'.status' => $this->status]);
        $query->andFilterWhere(['like', 'content', $this->content]);

        return $dataProvider;
    }
934165
public function search(AdminInterface $admin, $term, $page = 0, $offset = 20)
    {
        $datagrid = $admin->getDatagrid();

        $found = false;
        foreach ($datagrid->getFilters() as $filter) {
            /** @var $filter FilterInterface */
            if ($filter->getOption('global_search', false)) {
                $filter->setOption('case_sensitive', $this->caseSensitive);
                $filter->setCondition(FilterInterface::CONDITION_OR);
                $datagrid->setValue($filter->getFormName(), null, $term);
                $found = true;
            }
        }

        if (!$found) {
            return false;
        }

        $datagrid->buildPager();

        $pager = $datagrid->getPager();
        $pager->setPage($page);
        $pager->setMaxPerPage($offset);
        $pager->init();

        return $pager;
    }
1284233
public function search(SearchRequest $searchRequest)
    {
        $resultSet = $this->getInitializedSearchResultSet($searchRequest);
        $this->lastResultSet = $resultSet;

        $resultSet = $this->handleSearchHook('beforeSearch', $resultSet);
        if ($this->shouldReturnEmptyResultSetWithoutExecutedSearch($searchRequest)) {
            $resultSet->setHasSearched(false);
            return $resultSet;
        }

        $query = $this->queryBuilder->buildSearchQuery($searchRequest->getRawUserQuery(), (int)$searchRequest->getResultsPerPage(), $searchRequest->getAdditionalFilters());
        $this->initializeRegisteredSearchComponents($query, $searchRequest);
        $resultSet->setUsedQuery($query);

        // performing the actual search, sending the query to the Solr server
        $query = $this->modifyQuery($query, $searchRequest, $this->search);
        $response = $this->doASearch($query, $searchRequest);

        if ((int)$searchRequest->getResultsPerPage() === 0) {
            // when resultPerPage was forced to 0 we also set the numFound to 0 to hide results, e.g.
            // when results for the initial search should not be shown.
            $response->response->numFound = 0;
        }

        $resultSet->setHasSearched(true);
        $resultSet->setResponse($response);

        $this->getParsedSearchResults($resultSet);

        $resultSet->setUsedAdditionalFilters($this->queryBuilder->getAdditionalFilters());

        /** @var $variantsProcessor VariantsProcessor */
        $variantsProcessor = GeneralUtility::makeInstance(
            VariantsProcessor::class,
            /** @scrutinizer ignore-type */ $this->typoScriptConfiguration,
            /** @scrutinizer ignore-type */ $this->searchResultBuilder
        );
        $variantsProcessor->process($resultSet);

        /** @var $searchResultReconstitutionProcessor ResultSetReconstitutionProcessor */
        $searchResultReconstitutionProcessor = GeneralUtility::makeInstance(ResultSetReconstitutionProcessor::class);
        $searchResultReconstitutionProcessor->process($resultSet);

        $resultSet = $this->getAutoCorrection($resultSet);

        return $this->handleSearchHook('afterSearch', $resultSet);
    }
1093496
public function search(SearchQuery $searchQuery, $returnType = BaseSearch::SEARCH_RESULT)
    {
        $response = static::newResponse($returnType);

        /** @var yii\db\ActiveRecord|SearchableEntity $mainEntityClassName */
        $mainEntityClassName = $searchQuery->mainEntityClassName;

        $activeQuery = $mainEntityClassName::find();

        $success = false;

        // combine query
        $e = new SearchEvent(
            $searchQuery,
            $returnType,
            $response,
            [
                'params' => [
                    'activeQuery' => &$activeQuery,
                ],
            ]
        );
        $this->trigger(self::EVENT_BEFORE_PAGINATION, $e);

        // Pagination
        $pages = $searchQuery->getPagination();
        if ($returnType !== BaseSearch::SEARCH_COUNT && $pages !== null) {
            if ($pages->totalCount === 0) {
                $pages->totalCount = (int) $activeQuery->count();
            }
            $searchQuery->limit = $pages->limit;
            $searchQuery->offset = $pages->offset;
        }

        $e = new SearchEvent(
            $searchQuery,
            $returnType,
            $response,
            [
                'params' => [
                    'activeQuery' => &$activeQuery,
                    'pages' => $pages,
                ],
            ]
        );
        $this->trigger(self::EVENT_AFTER_PAGINATION, $e);

        $response->searchQuery = $searchQuery;

        switch ($returnType) {
            case BaseSearch::SEARCH_COUNT:
                /** @var CountResponse $response */
                $response->count = (int) $activeQuery->count();
                $success = true;
                break;
            case BaseSearch::SEARCH_QUERY:
                /** @var QueryResponse $response */
                $response->query = $activeQuery;
                $success = true;
                break;
            case BaseSearch::SEARCH_RESULT_ARRAY:
            case BaseSearch::SEARCH_RESULT:
                /** @var ResultResponse $response */
                // query for debug
                $response->query = $activeQuery;
                if (is_object($pages)) {
                    $response->pages = $pages;
                }
                if ($returnType === BaseSearch::SEARCH_RESULT_ARRAY) {
                    $activeQuery->asArray(true);
                }
                $response->entities = $activeQuery->all();
                $e = new SearchEvent(
                    $searchQuery,
                    $returnType,
                    $response,
                    [
                        'params' => [
                            'activeQuery' => &$activeQuery,
                        ],
                    ]
                );
                $this->trigger(self::EVENT_AFTER_FIND, $e);
                $success = true;
                break;
            case BaseSearch::SEARCH_IDS:
                /** @var IdsResponse $response */
                $activeQuery->select(
                    array_map(
                        function ($item) use ($mainEntityClassName) {
                            return $mainEntityClassName::tableName() . '.' . $item;
                        },
                        $mainEntityClassName::primaryKey()
                    )
                );
                $response->ids = $activeQuery
                    ->distinct(true)
                    ->asArray(true)
                    ->column();
                $response->query = $activeQuery;
                $success = true;
                break;
        }

        return $response->end($success);
    }
448945
public function search(
        $value = null,
        $currency = null,
        $contentCategory = null,
        $contentIds = null,
        $contents = null,
        $searchString = null
    )
    {
        $this->sendEventToOutput(
            self::EVENT_SEARCH,
            $this->prepareProductsToParameters(
                $contentIds,
                null,
                $contentCategory,
                $value,
                $currency,
                $contents,
                $searchString
            )
        );
    }
1361486
public function getPaginated($paged = 15, $orderBy = 'created_at', $sort = 'desc')
    {
        $query = function () use ($paged, $orderBy, $sort) {

            return $this->model
                ->with($this->requiredRelationships)
                ->orderBy($orderBy, $sort)
                ->paginate($paged);
        };

        return $this->doQuery($query);
    }
360817
public function usePageSectionsFromPageIds(array $pageIds = []): QueryBuilder
    {
        $filters = [];

        /** @var $processor PageUidToHierarchy */
        $processor = GeneralUtility::makeInstance(PageUidToHierarchy::class);
        $hierarchies = $processor->process($pageIds);

        foreach ($hierarchies as $hierarchy) {
            $lastLevel = array_pop($hierarchy);
            $filters[] = 'rootline:"' . $lastLevel . '"';
        }

        $pageSectionsFilterString = implode(' OR ', $filters);
        return $this->useFilter($pageSectionsFilterString, 'pageSections');
    }
593737
@Override
	public List<CommerceRegion> findByCommerceCountryId(long commerceCountryId) {
		return findByCommerceCountryId(commerceCountryId, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}
1093834
public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null)
    {
        $sortColumn = isset($filters['sidx']) ? $filters['sidx'] : 'id';
        $order = isset($filters['sord']) ? $filters['sord'] : 'ASC';

        $sortColumn = ucfirst($sortColumn);

        $query = TransUnitQuery::create()
            ->select('Id')
        ;

        $this->addTransUnitFilters($query, $filters);
        $this->addTranslationFilter($query, $locales, $filters);

        $ids = $query
            ->orderBy($sortColumn, $order)
            ->offset($rows * ($page - 1))
            ->limit($rows)
            ->find($this->getConnection())
        ;

        $transUnits = array();

        if (count($ids) > 0) {
            $unitsData = TransUnitQuery::create()
                ->filterById($ids, Criteria::IN)
                ->joinWith('Translation')
                ->useTranslationQuery()
                    ->filterByLocale($locales, Criteria::IN)
                ->endUse()
                ->orderBy($sortColumn, $order)
                ->setFormatter(ModelCriteria::FORMAT_ARRAY)
                ->find($this->getConnection())
            ;

            $transUnits = $this->filterTransUnitData($unitsData);
        }

        return $transUnits;
    }
122895
public function searchPosts($q, $page = 1)
    {
        if (!is_string($q) || empty($q)) {
            throw new IncorrectUsageException('Query must not be empty');
        }

        $this->checkPageNumber($page);

        return $this->adapter->get(sprintf('/search/posts/%s?page=%d', urlencode($q), $page));
    }
844297
public function getList(
        $page = null,
        $pageSize = null,
        array $localeFilter = array(),
        array $countryCodeFilter = array(),
        array $additionalFields = array()
    ) {
        return $this->getInternalList(
            'region/list',
            'Region',
            array(
                'page' => (int)$page,
                'page_size' => (int)$pageSize,
                'locale_filter' => self::getArray($localeFilter),
                'country_code_filter' => self::getArray($countryCodeFilter),
                'fields' => self::getArray($additionalFields),
            )
        );
    }
1275830
protected function getRevisionQuery(
        $siteId,
        $pageName,
        $pageType,
        $published = false
    ) {
        $revisionQueryBuilder = $this->_em->createQueryBuilder();
        $revisionQueryBuilder->select('page.pageId, revisions')
            ->select('PARTIAL page.{pageId}, revisions ')
            ->from(\Rcm\Entity\Page::class, 'page')
            ->join('page.revisions', 'revisions')
            ->where('page.site = :siteId')
            ->andWhere('page.name = :pageName')
            ->andWhere('page.pageType = :pageType')
            ->andWhere('revisions.published = :published')
            ->setParameter('siteId', $siteId)
            ->setParameter('pageName', $pageName)
            ->setParameter('pageType', $pageType)
            ->setParameter('published', $published)
            ->orderBy('revisions.revisionId', 'DESC');

        if ($published) {
            $revisionQueryBuilder->andWhere('revisions != page.publishedRevision');
        }

        return $revisionQueryBuilder->getQuery();
    }
715661
public function get($conditions = [], $requiredField = [], $page = 0)
    {

        $searchParams['index'] = $this->index;
        $searchParams['type'] = $this->type;
        $searchParams['size'] = $this->maxResultsSize;
        $searchParams['from'] = $page * $this->maxResultsSize;
        $searchParams['body']['query']['bool']['must'] = [];
        $searchParams['_source_exclude']= ['PAG*'];

        $searchParams['body']['highlight']['order'] = 'score';
        $searchParams['body']['highlight']['fields'] = ['PAGE_*' => ['number_of_fragments' => 3], 'PAG_*' => ['number_of_fragments' => 3]];
        $searchParams['body']['highlight']['pre_tags'] = ['<strong>'];
        $searchParams['body']['highlight']['post_tags'] = ['</strong>'];

        foreach ($requiredField as $field) {
            $searchParams['body']['query']['bool']['must'][]['exists'] = ['field' => $field];
        }

        $filter = $this->makeFilterCondition($conditions);

        if(!empty($filter))$searchParams['body']['query']['bool']['must'][] = $filter;

        if($this->isModel)return $this->model->hydrateElasticsearchResult($this->client->search($searchParams));
        else return $this->client->search($searchParams);

    }