本文整理汇总了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;
}
示例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
*/
//.........这里部分代码省略.........
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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'));
}
示例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);
}
示例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;
}
示例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]);
}
示例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':
//.........这里部分代码省略.........
示例14: paginate
/**
* @inheritDoc
*/
public function paginate()
{
$this->query->setSize($this->limit);
$this->query->setFrom(($this->page - 1) * $this->limit);
return $this->query;
}
示例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];
}