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


PHP Query::setPostFilter方法代码示例

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


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

示例1: testIndicesQuery

 /**
  * @group functional
  */
 public function testIndicesQuery()
 {
     $docs = array(new Document(1, array('color' => 'blue')), new Document(2, array('color' => 'green')), new Document(3, array('color' => 'blue')), new Document(4, array('color' => 'yellow')));
     $index1 = $this->_createIndex();
     $index1->addAlias('indices_query');
     $index1->getType('test')->addDocuments($docs);
     $index1->refresh();
     $index2 = $this->_createIndex();
     $index2->addAlias('indices_query');
     $index2->getType('test')->addDocuments($docs);
     $index2->refresh();
     $boolQuery = new Query\BoolQuery();
     $boolQuery->addMustNot(new Term(array('color' => 'blue')));
     $indicesQuery = new Indices($boolQuery, array($index1->getName()));
     $boolQuery = new Query\BoolQuery();
     $boolQuery->addMustNot(new Term(array('color' => 'yellow')));
     $indicesQuery->setNoMatchQuery($boolQuery);
     $query = new Query();
     $query->setPostFilter($indicesQuery);
     // search over the alias
     $index = $this->_getClient()->getIndex('indices_query');
     $results = $index->search($query);
     // ensure that the proper docs have been filtered out for each index
     $this->assertEquals(5, $results->count());
     foreach ($results->getResults() as $result) {
         $data = $result->getData();
         $color = $data['color'];
         if ($result->getIndex() === $index1->getName()) {
             $this->assertNotEquals('blue', $color);
         } else {
             $this->assertNotEquals('yellow', $color);
         }
     }
 }
开发者ID:vinusebastian,项目名称:Elastica,代码行数:37,代码来源:IndicesTest.php

示例2: testGeoPoint

 /**
  * @group functional
  */
 public function testGeoPoint()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('location' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('location', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('location', 30, 40);
     $type->addDocument($doc2);
     $index->refresh();
     // Only one point should be in polygon
     $query = new Query();
     $points = array(array(16, 16), array(16, 20), array(20, 20), array(20, 16), array(16, 16));
     $geoFilter = new GeoPolygon('location', $points);
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $points = array(array(16, 16), array(16, 40), array(40, 40), array(40, 16), array(16, 16));
     $geoFilter = new GeoPolygon('location', $points);
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoFilter);
     $this->assertEquals(2, $type->search($query)->count());
 }
开发者ID:vinusebastian,项目名称:Elastica,代码行数:33,代码来源:GeoPolygonTest.php

示例3: testGeoPoint

 /**
  * @group functional
  */
 public function testGeoPoint()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('point' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('point', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('point', 30, 40);
     $type->addDocument($doc2);
     $index->optimize();
     $index->refresh();
     // Only one point should be in radius
     $geoQuery = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km');
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoQuery);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $geoQuery = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km');
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoQuery);
     $index->refresh();
     $this->assertEquals(2, $type->search($query)->count());
 }
开发者ID:joelwurtz,项目名称:Elastica,代码行数:32,代码来源:GeoDistanceTest.php

示例4: testLookup

 /**
  * @group functional
  */
 public function testLookup()
 {
     $index = $this->_createIndex();
     $type1 = $index->getType('musicians');
     $type2 = $index->getType('bands');
     //index some test data
     $type1->addDocuments(array(new Document(1, array('name' => 'robert', 'lastName' => 'plant')), new Document(2, array('name' => 'jimmy', 'lastName' => 'page')), new Document(3, array('name' => 'john paul', 'lastName' => 'jones')), new Document(4, array('name' => 'john', 'lastName' => 'bonham')), new Document(5, array('name' => 'jimi', 'lastName' => 'hendrix'))));
     $type2->addDocument(new Document('led zeppelin', array('members' => array('plant', 'page', 'jones', 'bonham'))));
     $index->refresh();
     //use the terms lookup feature to query for some data
     $termsFilter = new Terms();
     $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', null);
     $query = new Query();
     $query->setPostFilter($termsFilter);
     $results = $index->search($query);
     $this->assertEquals($results->count(), 4, 'Terms lookup with null index');
     $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', $index);
     $query->setPostFilter($termsFilter);
     $results = $index->search($query);
     $this->assertEquals($results->count(), 4, 'Terms lookup with index as object');
     //Query with index given as string
     $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', $index->getName());
     $query->setPostFilter($termsFilter);
     $results = $index->search($query);
     $this->assertEquals($results->count(), 4, 'Terms lookup with index as string');
     //Query with array of options
     $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', array('index' => $index));
     $query->setPostFilter($termsFilter);
     $results = $index->search($query);
     $this->assertEquals($results->count(), 4, 'Terms lookup with options array');
     $index->delete();
 }
开发者ID:vinusebastian,项目名称:Elastica,代码行数:35,代码来源:TermsTest.php

示例5: testQuery

 /**
  * @group functional
  */
 public function testQuery()
 {
     $query = new Query();
     $match = new Match();
     $match->setField('make', 'ford');
     $query->setQuery($match);
     $filter = new Term();
     $filter->setTerm('color', 'green');
     $query->setPostFilter($filter);
     $results = $this->_getTestIndex()->search($query);
     $this->assertEquals(1, $results->getTotalHits());
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:15,代码来源:PostFilterTest.php

示例6: __construct

 public function __construct(Index $index, Query $query, LoggerInterface $logger = null)
 {
     //Optimise the query by just getting back the ids and types
     $query->setFields(array('_id', '_type'));
     //If we are in live reading mode, only return published documents
     if (\Versioned::get_reading_mode() == \Versioned::DEFAULT_MODE) {
         $publishedFilter = new Query\BoolQuery();
         $publishedFilter->addMust(new Query\Term([Searchable::$published_field => 'true']));
         $query->setPostFilter($publishedFilter);
     }
     $this->index = $index;
     $this->query = $query;
     $this->logger = $logger;
 }
开发者ID:heyday,项目名称:silverstripe-elastica,代码行数:14,代码来源:ResultList.php

示例7: testRandomRead

 /**
  * @depends testAddDocument
  * @dataProvider providerTransport
  */
 public function testRandomRead(array $config, $transport)
 {
     $type = $this->getType($config);
     $type->search('test');
     $times = array();
     for ($i = 0; $i < $this->_max; $i++) {
         $test = rand(1, $this->_max);
         $query = new Query();
         $query->setQuery(new MatchAllQuery());
         $query->setPostFilter(new TermFilter(array('test' => $test)));
         $result = $type->search($query);
         $times[] = $result->getResponse()->getQueryTime();
     }
     self::logResults('random read', $transport, $times);
 }
开发者ID:tkaven,项目名称:Elastica,代码行数:19,代码来源:TransportTest.php

示例8: search

 /**
  * @param array $fullRequest
  */
 protected function search(array $fullRequest)
 {
     $query = new El\Query($fullRequest);
     $usedFilters = $this->addFilters();
     if ($usedFilters !== false) {
         $query->setPostFilter($usedFilters);
     }
     $resultSet = $this->connection->getIndex()->search($query);
     $this->totalHits = $resultSet->getTotalHits();
     if (intval($this->totalHits) <= intval($this->currentPage * $this->perPage)) {
         $this->view->assign('endingAtItem', intval($this->totalHits));
     } else {
         $this->view->assign('endingAtItem', $this->currentPage * $this->perPage);
     }
     $this->view->assignMultiple(['results' => $resultSet->getResults(), 'pagesToLinkTo' => $this->getPages(), 'currentPage' => $this->currentPage, 'prev' => $this->currentPage - 1, 'next' => $this->currentPage < ceil($this->totalHits / $this->perPage) ? $this->currentPage + 1 : 0, 'totalResults' => $this->totalHits, 'startingAtItem' => $this->currentPage * $this->perPage - ($this->perPage - 1), 'aggregations' => $resultSet->getAggregations(), 'context' => $this->context]);
 }
开发者ID:randomresult,项目名称:WMDB.Forger,代码行数:19,代码来源:GerritController.php

示例9: testBoolFilter

 public function testBoolFilter()
 {
     $index = $this->_createIndex('bool_filter_test');
     $type = $index->getType('book');
     //index some test data
     $type->addDocument(new \Elastica\Document(1, array('author' => 'Michael Shermer', 'title' => 'The Believing Brain', 'publisher' => 'Robinson')));
     $type->addDocument(new \Elastica\Document(2, array('author' => 'Jared Diamond', 'title' => 'Guns, Germs and Steel', 'publisher' => 'Vintage')));
     $type->addDocument(new \Elastica\Document(3, array('author' => 'Jared Diamond', 'title' => 'Collapse', 'publisher' => 'Penguin')));
     $type->addDocument(new \Elastica\Document(4, array('author' => 'Richard Dawkins', 'title' => 'The Selfish Gene', 'publisher' => 'OUP Oxford')));
     $type->addDocument(new \Elastica\Document(5, array('author' => 'Anthony Burges', 'title' => 'A Clockwork Orange', 'publisher' => 'Penguin')));
     $index->refresh();
     //use the terms lookup feature to query for some data
     //build query
     //must
     //  should
     //      author = jared
     //      author = richard
     //  must_not
     //      publisher = penguin
     //construct the query
     $query = new Query();
     $mainBoolFilter = new Bool();
     $shouldFilter = new Bool();
     $authorFilter1 = new Term();
     $authorFilter1->setTerm('author', 'jared');
     $authorFilter2 = new Term();
     $authorFilter2->setTerm('author', 'richard');
     $shouldFilter->addShould(array($authorFilter1, $authorFilter2));
     $mustNotFilter = new Bool();
     $publisherFilter = new Term();
     $publisherFilter->setTerm('publisher', 'penguin');
     $mustNotFilter->addMustNot($publisherFilter);
     $mainBoolFilter->addMust(array($shouldFilter, $mustNotFilter));
     $query->setPostFilter($mainBoolFilter);
     //execute the query
     $results = $index->search($query);
     //check the number of results
     $this->assertEquals($results->count(), 2, 'Bool filter with child Bool filters: number of results check');
     //count compare the id's
     $ids = array();
     /** @var \Elastica\Result $result **/
     foreach ($results as $result) {
         $ids[] = $result->getId();
     }
     $this->assertEquals($ids, array("2", "4"), 'Bool filter with child Bool filters: result ID check');
     $index->delete();
 }
开发者ID:tkaven,项目名称:Elastica,代码行数:47,代码来源:BoolTest.php

示例10: testIndicesFilter

 public function testIndicesFilter()
 {
     $filter = new Indices(new BoolNot(new Term(array("color" => "blue"))), array($this->_index1->getName()));
     $filter->setNoMatchFilter(new BoolNot(new Term(array("color" => "yellow"))));
     $query = new Query();
     $query->setPostFilter($filter);
     // search over the alias
     $index = $this->_getClient()->getIndex("indices_filter");
     $results = $index->search($query);
     // ensure that the proper docs have been filtered out for each index
     $this->assertEquals(5, $results->count());
     foreach ($results->getResults() as $result) {
         $data = $result->getData();
         $color = $data["color"];
         if ($result->getIndex() == $this->_index1->getName()) {
             $this->assertNotEquals("blue", $color);
         } else {
             $this->assertNotEquals("yellow", $color);
         }
     }
 }
开发者ID:tkaven,项目名称:Elastica,代码行数:21,代码来源:IndicesTest.php

示例11: findPaginatedByQueryAndCategory

 /**
  * @inheritdoc
  */
 public function findPaginatedByQueryAndCategory(\string $queryString = null, \string $category = null, \int $priceFrom = null, \int $priceTo = null, \bool $availability = null)
 {
     $queryObject = new Query();
     $filter = new BoolAnd();
     if ($queryString) {
         $query = new Match('_all', ['query' => $queryString, 'operator' => 'AND']);
     } else {
         $query = new Query\MatchAll();
     }
     if ($availability !== null) {
         $filter->addFilter(new Term(['availability' => $availability]));
     }
     $range = [];
     if ($priceFrom) {
         $range['gte'] = $priceFrom;
     }
     if ($priceTo) {
         $range['lte'] = $priceTo;
     }
     if ($range) {
         $filter->addFilter(new Range('price', $range));
     }
     if ($category) {
         $term = new Term(['category.id' => $category]);
         $queryObject->setPostFilter($term);
     }
     $terms = new Terms('categories');
     $terms->setField('category.id');
     $terms->setSize(0);
     $queryObject->addAggregation($terms);
     if ($filter->getFilters()) {
         $filtered = new Query\Filtered($query, $filter);
         $queryObject->setQuery($filtered);
     } else {
         $queryObject->setQuery($query);
     }
     $queryObject->setSort(['updated' => 'desc']);
     $queryObject->setMinScore(0.5);
     return $this->findPaginated($queryObject);
 }
开发者ID:igaponov,项目名称:shop,代码行数:43,代码来源:ProductViewRepository.php

示例12: testFilter

 /**
  * @group functional
  */
 public function testFilter()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     $mapping = new Mapping($type, array('pin' => array('type' => 'geo_point', 'geohash' => true, 'geohash_prefix' => true)));
     $type->setMapping($mapping);
     $type->addDocument(new Document(1, array('pin' => '9q8yyzm0zpw8')));
     $type->addDocument(new Document(2, array('pin' => '9mudgb0yued0')));
     $index->refresh();
     $filter = new GeohashCell('pin', array('lat' => 32.828326, 'lon' => -117.255854));
     $query = new Query();
     $query->setPostFilter($filter);
     $results = $type->search($query);
     $this->assertEquals(1, $results->count());
     //test precision parameter
     $filter = new GeohashCell('pin', '9', 1);
     $query = new Query();
     $query->setPostFilter($filter);
     $results = $type->search($query);
     $this->assertEquals(2, $results->count());
     $index->delete();
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:25,代码来源:GeohashCellTest.php

示例13: search

 /**
  * Search for logs
  *
  * @param array $params Search parameters:
  *   - project: Project to find logs for
  *   - query: Elasticsearch simple query string
  *   - items: Number of results to return per page
  *   - page: Page of results to return (0-index)
  * @return ResultSet
  */
 public function search(array $params = [])
 {
     $params = array_merge(['project' => 'production', 'query' => null, 'items' => 20, 'page' => 0, 'date' => null], $params);
     $filters = new BoolQuery();
     if ($params['query'] !== null) {
         $filters->addMust(new SimpleQueryString($params['query'], ['message', 'nick']));
     }
     if ($params['date'] !== null) {
         $filters->addMust(new Range('@timestamp', ['lte' => "{$params['date']}||/d"]));
     }
     $query = new Query($filters);
     $query->setPostFilter(new Term(['project' => $params['project']]));
     $query->setFrom($params['page'] * $params['items'])->setSize($params['items'])->setFields(self::$DEFAULT_FIELDS)->setSort(['@timestamp' => ['order' => 'desc']]);
     return $this->doSearch($query);
 }
开发者ID:bd808,项目名称:SAL,代码行数:25,代码来源:Logs.php

示例14: compileElasticaTaxonQuery

 /**
  * @param null $facets
  * @param $configuration
  * @param $taxon
  * @param null $types
  *
  * @return mixed
  */
 public function compileElasticaTaxonQuery($facets = null, $configuration, $taxon, $types = null)
 {
     $elasticaQuery = new Query();
     $boolFilter = new BoolFilter();
     $this->addAvailableProductsFilters($boolFilter);
     if (!empty($types)) {
         foreach ($types as $type) {
             $typeFilter = new Type($type);
             $boolFilter->addMust($typeFilter);
         }
         $elasticaQuery->setPostFilter($boolFilter);
     }
     if ($channel = $this->channelContext->getChannel()) {
         $channelFilter = new FilterTerms();
         $channelFilter->setTerms('channels', [(string) $channel]);
         $boolFilter->addMust($channelFilter);
         $elasticaQuery->setPostFilter($boolFilter);
     }
     $query = new Filtered();
     $taxonFromRequestFilter = new FilterTerms();
     $taxonFromRequestFilter->setTerms('taxons', [$taxon]);
     $boolFilter->addMust($taxonFromRequestFilter);
     $query->setFilter($boolFilter);
     $elasticaQuery->setQuery($query);
     return $this->compileElasticsearchQuery($elasticaQuery, $facets, $configuration);
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:34,代码来源:ElasticsearchFinder.php

示例15: get

 /**
  * {@inheritdoc}
  */
 public function get(array $data, array $keys, $namespace)
 {
     if (!$this->hasNamespace($namespace)) {
         return array();
     }
     // Build the query
     $query = new Query();
     // Add hash term
     $term = new Term();
     $term->setTerm('hash', $this->getHash($data, $keys));
     $query->setPostFilter($term);
     $esResults = $this->index->getType($namespace)->search($query)->getResults();
     $results = array();
     foreach ($esResults as $esResult) {
         $results[] = $esResult->getData();
     }
     return $results;
 }
开发者ID:Tessi-Tms,项目名称:TmsDataLimitNamespaceBundle,代码行数:21,代码来源:ElasticSearchDataProvider.php


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