当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::setSize方法代码示例

本文整理汇总了PHP中Elastica\Query::setSize方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setSize方法的具体用法?PHP Query::setSize怎么用?PHP Query::setSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Query的用法示例。


在下文中一共展示了Query::setSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCountQuery

 private function getCountQuery($journal)
 {
     $filter = new Term();
     $filter->setTerm('journalUsers.journal.id', $journal->getId());
     $filterQuery = new Query\Filtered();
     $filterQuery->setFilter($filter);
     $query = new Query($filterQuery);
     $query->setSize(0);
     return $query;
 }
开发者ID:necatikartal,项目名称:ojs,代码行数:10,代码来源:UserReportController.php

示例2: indexAction

 /**
  * search page index controller
  *
  * @param Request $request
  * @param int $page
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request, $page = 1)
 {
     /**
      * @var \Ojs\SearchBundle\Manager\SearchManager $searchManager
      */
     $searchManager = $this->get('ojs_search_manager');
     $getRoles = $request->query->get('role_filters');
     $getSubjects = $request->query->get('subject_filters');
     $getJournals = $request->query->get('journal_filters');
     $roleFilters = !empty($getRoles) ? explode(',', $getRoles) : [];
     $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
     $journalFilters = !empty($getJournals) ? explode(',', $getJournals) : [];
     $queryType = $request->query->has('type') ? $request->get('type') : 'basic';
     $query = filter_var($request->get('q'), FILTER_SANITIZE_STRING);
     $section = filter_var($request->get('section'), FILTER_SANITIZE_STRING);
     $searcher = $this->get('fos_elastica.index.search');
     $searchQuery = new Query('_all');
     $boolQuery = new Query\Bool();
     $match = new Query\Match();
     $match->setField('status', 3);
     $boolQuery->addShould($match);
     $match = new Query\Match();
     $match->setField('published', true);
     $boolQuery->addShould($match);
     //set query according to query type
     if ($queryType == 'basic') {
         $fieldQuery = new Query\MultiMatch();
         $fieldQuery->setFields(['_all']);
         $fieldQuery->setQuery($query);
         $boolQuery->addMust($fieldQuery);
     } elseif ($queryType == 'advanced') {
         $parseQuery = $searchManager->parseSearchQuery($query);
         foreach ($parseQuery as $searchTerm) {
             $condition = $searchTerm['condition'];
             $advancedFieldQuery = new Query\MultiMatch();
             $advancedFieldQuery->setFields([$searchTerm['searchField']]);
             $advancedFieldQuery->setQuery($searchTerm['searchText']);
             if ($condition == 'AND') {
                 $boolQuery->addMust($advancedFieldQuery);
             } elseif ($condition == 'OR') {
                 $boolQuery->addShould($advancedFieldQuery);
             } elseif ($condition == 'NOT') {
                 $boolQuery->addMustNot($advancedFieldQuery);
             }
         }
     } elseif ($queryType == 'tag') {
         $matchQuery = new Query\Match();
         $matchQuery->setField('tags', $query);
         $boolQuery->addMust($matchQuery);
     }
     //set aggregations if requested
     if (!empty($roleFilters) || !empty($subjectFilters) || !empty($journalFilters)) {
         foreach ($roleFilters as $role) {
             $match = new Query\Match();
             $match->setField('user.userJournalRoles.role.name', $role);
             $boolQuery->addMust($match);
         }
         foreach ($subjectFilters as $subject) {
             $match = new Query\Match();
             $match->setField('subjects', $subject);
             $boolQuery->addMust($match);
         }
         foreach ($journalFilters as $journal) {
             $match = new Query\Match();
             $match->setField('user.userJournalRoles.journal.title', $journal);
             $boolQuery->addMust($match);
         }
     }
     //set our boolean query
     $searchQuery->setQuery($boolQuery);
     //get all result
     $searchQuery->setSize(1000);
     //get role aggregation
     $roleAgg = new Aggregation\Terms('roles');
     $roleAgg->setField('userJournalRoles.role.name');
     $roleAgg->setOrder('_term', 'asc');
     $roleAgg->setSize(0);
     $searchQuery->addAggregation($roleAgg);
     //get subject aggregation
     $subjectAgg = new Aggregation\Terms('subjects');
     $subjectAgg->setField('subjects');
     $subjectAgg->setOrder('_term', 'asc');
     $subjectAgg->setSize(0);
     $searchQuery->addAggregation($subjectAgg);
     //get journal aggregation
     $journalAgg = new Aggregation\Terms('journals');
     $journalAgg->setField('journal.raw');
     $journalAgg->setOrder('_term', 'asc');
     $journalAgg->setSize(0);
     $searchQuery->addAggregation($journalAgg);
     /**
      * @var ResultSet $resultData
      */
//.........这里部分代码省略.........
开发者ID:hasantayyar,项目名称:ojs,代码行数:101,代码来源:SearchController.php

示例3: addPaginationToQuery

 /**
  * @param \Elastica\Query $query
  * @param \Spryker\Client\Search\Dependency\Plugin\PaginationConfigBuilderInterface $paginationConfig
  * @param array $requestParameters
  *
  * @return void
  */
 protected function addPaginationToQuery(Query $query, PaginationConfigBuilderInterface $paginationConfig, array $requestParameters)
 {
     $currentPage = $paginationConfig->getCurrentPage($requestParameters);
     $itemsPerPage = $paginationConfig->getCurrentItemsPerPage($requestParameters);
     $query->setFrom(($currentPage - 1) * $itemsPerPage);
     $query->setSize($itemsPerPage);
 }
开发者ID:spryker,项目名称:Search,代码行数:14,代码来源:PaginatedQueryExpanderPlugin.php

示例4: getStates

 protected function getStates()
 {
     $results = [];
     $query = new Elastica\Query();
     $query->setSize(0);
     $agg = new Elastica\Aggregation\Nested('states', 'state');
     $st_terms = new Elastica\Aggregation\Terms('abbrev');
     $st_terms->setField('state.abbrev');
     $st_terms->setOrder('_term', 'asc');
     $st_terms->setSize(0);
     $state_terms = new Elastica\Aggregation\Terms('full');
     $state_terms->setField('state.full');
     $st_terms->addAggregation($state_terms);
     $agg->addAggregation($st_terms);
     $query->addAggregation($agg);
     /* @var $elastica_client Elastica\Client */
     $elastica_client = $this->getServiceLocator()->getServiceLocator()->get('elastica-client');
     try {
         /* @var $response \Elastica\Response */
         $response = $elastica_client->request('usgeodb/locality/_search?query_cache=true', Request::GET, $query->toArray());
         $data = $response->getData();
         $aggregations = isset($data['aggregations']['states']['abbrev']['buckets']) ? $data['aggregations']['states']['abbrev']['buckets'] : [];
         foreach ($aggregations as $aggregation) {
             $key = strtoupper($aggregation['key']);
             $value = ucwords($aggregation['full']['buckets'][0]['key']);
             $results[$key] = $value;
         }
     } catch (\Exception $e) {
     }
     return $results;
 }
开发者ID:arstropica,项目名称:zf2-dashboard,代码行数:31,代码来源:LocationFieldset.php

示例5: autosuggest

 public function autosuggest($text)
 {
     $queryString = new QueryString($text);
     $elasticaQuery = new ElasticaQuery($queryString);
     $elasticaQuery->setSize(10);
     $result = $this->elastica->search($elasticaQuery, 'locations');
     return $this->prepareSuggestResult($result);
 }
开发者ID:phpfour,项目名称:ah,代码行数:8,代码来源:Search.php

示例6: setPagination

 /**
  * @param int $offset
  * @param int $size
  *
  * @return SearcherInterface
  */
 public function setPagination($offset, $size)
 {
     if (is_int($offset)) {
         $this->query->setFrom($offset);
     }
     if (is_int($size)) {
         $this->query->setSize($size);
     }
     return $this;
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:16,代码来源:AbstractElasticaSearcher.php

示例7: search

 /**
  * @param $keyword
  * @return \Elastica\ResultSet
  */
 public function search($keyword)
 {
     $query = new Query();
     $query->setSize(1000);
     $fuzzyQuery = new Query\FuzzyLikeThis();
     $fuzzyQuery->setLikeText($keyword);
     $fuzzyQuery->setMinSimilarity(0.7);
     $query->setQuery($fuzzyQuery);
     $results = $this->search->search($query);
     return $results;
 }
开发者ID:hoangnd25,项目名称:IndustryProject,代码行数:15,代码来源:SearchManager.php

示例8: testSuggestShouldNotRemoveOtherParameters

 /**
  * @group unit
  */
 public function testSuggestShouldNotRemoveOtherParameters()
 {
     $query1 = new Query();
     $query2 = new Query();
     $suggest = new Suggest();
     $suggest->setGlobalText('test');
     $query1->setSize(40);
     $query1->setSuggest($suggest);
     $query2->setSuggest($suggest);
     $query2->setSize(40);
     $this->assertEquals($query1->toArray(), $query2->toArray());
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:15,代码来源:QueryTest.php

示例9: testQuerySizeOverride

 public function testQuerySizeOverride()
 {
     $query = new Query();
     $query->setSize(100);
     $index = $this->_createIndex('test_1');
     $index->refresh();
     // Waits for the index to be fully created.
     $type = $index->getType('scanAndScrollTest');
     $search = new Search($this->_getClient());
     $search->addIndex($index)->addType($type);
     $search->setQuery($query);
     $scanAndScroll = new ScanAndScroll($search);
     $scanAndScroll->sizePerShard = 10;
     $scanAndScroll->rewind();
     $this->assertEquals(10, $query->getParam('size'));
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:16,代码来源:ScanAndScrollTest.php

示例10: searchText

 /**
  * @param string $term text to search
  * @return \Status
  */
 public function searchText($term)
 {
     $term = trim($term);
     // No searching for nothing!  That takes forever!
     if (!$term) {
         return null;
     }
     $query = new Query();
     $offset = min($this->offset, static::MAX_OFFSET);
     if ($offset) {
         $query->setFrom($offset);
     }
     if ($this->limit) {
         $query->setSize($this->limit);
     }
     $filter = new Bool();
     // filters
     if ($this->namespaces) {
         $filter->addMust(new Terms('namespace', $this->namespaces));
     }
     if ($this->pageIds) {
         $filter->addMust(new Terms('pageid', $this->pageIds));
     }
     if ($this->moderationStates) {
         $filter->addMust(new Terms('revisions.moderation_state', $this->moderationStates));
     }
     // only apply filters if there are any
     if ($filter->toArray()) {
         $query->setFilter($filter);
     }
     $sortArgs = $this->getSortArgs();
     if (isset($sortArgs[$this->sort]) && $sortArgs[$this->sort]) {
         $query->setSort($sortArgs[$this->sort]);
     }
     // @todo: interwiki stuff? (see \CirrusSearch)
     $searcher = new Searcher($query, false, $this->type);
     return $searcher->searchText($term);
 }
开发者ID:TarLocesilion,项目名称:mediawiki-extensions-Flow,代码行数:42,代码来源:SearchEngine.php

示例11: getQuery

 /**
  * @return false|\Elastica\Query
  * @throws ErrorException
  */
 public function getQuery()
 {
     if ($this->validate() === false) {
         return false;
     }
     $termsAgg = new Terms(self::GROUP_AGGREGATION_NAME);
     $termsAgg->setField($this->group['by']);
     $termsAgg->setSize(self::MAX_SIZE_AGGREGATION_ITEMS);
     $filterBool = new Bool();
     if ($this->condition) {
         $this->addCondition($filterBool);
     }
     $this->addAggregation($termsAgg);
     $queryFiltred = new \Elastica\Query\Filtered();
     $queryFiltred->setFilter($filterBool);
     $queryFiltred->setQuery(new \Elastica\Query\MatchAll());
     $query = new Query();
     // These are not needed only aggregation
     $query->setSize(0);
     $query->setQuery($queryFiltred);
     $query->addAggregation($termsAgg);
     return $query;
 }
开发者ID:anmoroz,项目名称:yii2-analytics,代码行数:27,代码来源:ElasticaQueryBuilder.php

示例12: searchAction

 public function searchAction()
 {
     //WIP, todo: export to repository and use it in Search Playlists
     $elasticaClient = new Client();
     $playListIndex = $elasticaClient->getIndex('playlist');
     $trackType = $playListIndex->getType('track');
     $search = new Search($elasticaClient);
     $search->addIndex($playListIndex)->addType($trackType);
     $query = new Query();
     $query->setSize(5)->setSort(['name' => 'asc'])->setFields(['name', 'ids', 'id', 'composer'])->setExplain(true)->setVersion(true)->setHighlight(['fields' => 'composer']);
     $query->setQuery(new MatchAll());
     //        $query->addAggregation(new \Elastica\Aggregation\Range('name'));
     //        $term = new \Elastica\Suggest\Term('name', 'field');
     //        $term->setText('aaaaa');
     //        $query->setSuggest(new \Elastica\Suggest($term));
     //        $query->setFacets([new \Elastica\Facet\Range('name')]);
     $search->setQuery($query);
     $resultSet = $search->search();
     $numberOfEntries = $search->count();
     $results = $resultSet->getResults();
     $totalResults = $resultSet->getTotalHits();
     return $this->render('PlayWithElasticSearchBundle:Elastica:search.html.twig', ['query' => $query, 'numberOfEntries' => $numberOfEntries, 'resultSet' => $resultSet, 'results' => $results, 'totalResults' => $totalResults]);
 }
开发者ID:slaparra,项目名称:Training-Elastic-Search-Symfony,代码行数:23,代码来源:ElasticaController.php

示例13: search

 /**
  * Powers full-text-like searches including prefix search.
  *
  * @param string $type
  * @param string $for
  * @return Status(mixed) results from the query transformed by the resultsType
  */
 private function search($type, $for)
 {
     if ($this->nonTextQueries) {
         $bool = new \Elastica\Query\Bool();
         if ($this->query !== null) {
             $bool->addMust($this->query);
         }
         foreach ($this->nonTextQueries as $nonTextQuery) {
             $bool->addMust($nonTextQuery);
         }
         $this->query = $bool;
     }
     if ($this->resultsType === null) {
         $this->resultsType = new FullTextResultsType(FullTextResultsType::HIGHLIGHT_ALL);
     }
     // Default null queries now so the rest of the method can assume it is not null.
     if ($this->query === null) {
         $this->query = new \Elastica\Query\MatchAll();
     }
     $query = new Elastica\Query();
     $query->setParam('_source', $this->resultsType->getSourceFiltering());
     $query->setParam('fields', $this->resultsType->getFields());
     $extraIndexes = array();
     $indexType = $this->pickIndexTypeFromNamespaces();
     if ($this->namespaces) {
         $extraIndexes = $this->getAndFilterExtraIndexes();
         if ($this->needNsFilter($extraIndexes, $indexType)) {
             $this->filters[] = new \Elastica\Filter\Terms('namespace', $this->namespaces);
         }
     }
     // Wrap $this->query in a filtered query if there are any filters
     $unifiedFilter = Filters::unify($this->filters, $this->notFilters);
     if ($unifiedFilter !== null) {
         $this->query = new \Elastica\Query\Filtered($this->query, $unifiedFilter);
     }
     // Call installBoosts right after we're done munging the query to include filters
     // so any rescores installBoosts adds to the query are done against filtered results.
     $this->installBoosts();
     $query->setQuery($this->query);
     $highlight = $this->resultsType->getHighlightingConfiguration($this->highlightSource);
     if ($highlight) {
         // Fuzzy queries work _terribly_ with the plain highlighter so just drop any field that is forcing
         // the plain highlighter all together.  Do this here because this works so badly that no
         // ResultsType should be able to use the plain highlighter for these queries.
         if ($this->fuzzyQuery) {
             $highlight['fields'] = array_filter($highlight['fields'], function ($field) {
                 return $field['type'] !== 'plain';
             });
         }
         if (!empty($this->nonTextHighlightQueries)) {
             // We have some phrase_prefix queries, so let's include them in the
             // generated highlight_query.
             $bool = new \Elastica\Query\Bool();
             if ($this->highlightQuery) {
                 $bool->addShould($this->highlightQuery);
             }
             foreach ($this->nonTextHighlightQueries as $nonTextHighlightQuery) {
                 $bool->addShould($nonTextHighlightQuery);
             }
             $this->highlightQuery = $bool;
         }
         if ($this->highlightQuery) {
             $highlight['highlight_query'] = $this->highlightQuery->toArray();
         }
         $query->setHighlight($highlight);
     }
     if ($this->suggest) {
         $query->setParam('suggest', $this->suggest);
         $query->addParam('stats', 'suggest');
     }
     if ($this->offset) {
         $query->setFrom($this->offset);
     }
     if ($this->limit) {
         $query->setSize($this->limit);
     }
     if ($this->sort != 'relevance') {
         // Clear rescores if we aren't using relevance as the search sort because they aren't used.
         $this->rescore = array();
     }
     if ($this->rescore) {
         // rescore_query has to be in array form before we send it to Elasticsearch but it is way easier to work
         // with if we leave it in query for until now
         $modifiedRescore = array();
         foreach ($this->rescore as $rescore) {
             $rescore['query']['rescore_query'] = $rescore['query']['rescore_query']->toArray();
             $modifiedRescore[] = $rescore;
         }
         $query->setParam('rescore', $modifiedRescore);
     }
     $query->addParam('stats', $type);
     switch ($this->sort) {
         case 'relevance':
//.........这里部分代码省略.........
开发者ID:jamesmontalvo3,项目名称:mediawiki-extensions-CirrusSearch,代码行数:101,代码来源:Searcher.php

示例14: paginate

 /**
  * @inheritDoc
  */
 public function paginate()
 {
     $this->query->setSize($this->limit);
     $this->query->setFrom(($this->page - 1) * $this->limit);
     return $this->query;
 }
开发者ID:vardius,项目名称:list-bundle,代码行数:9,代码来源:Paginator.php

示例15: findOneBy

 public function findOneBy(ClassMetadata $class, $field, $value)
 {
     $filter = new Term(array($field => $value));
     $query = new Query(new Filtered(null, $filter));
     $query->setVersion(true);
     $query->setSize(1);
     $results = $this->search($query, array($class));
     if (!$results->count()) {
         throw new NoResultException();
     }
     return $results[0];
 }
开发者ID:akleiber,项目名称:search,代码行数:12,代码来源:Client.php


注:本文中的Elastica\Query::setSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。