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


PHP Query::setFilter方法代码示例

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


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

示例1: testGeoPoint

 public function testGeoPoint()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $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->setFilter($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->setFilter($geoFilter);
     $this->assertEquals(2, $type->search($query)->count());
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:32,代码来源:GeoPolygonTest.php

示例2: testGeoPoint

 public function testGeoPoint()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $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
     $query = new Query();
     $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km');
     $query = new Query(new MatchAll());
     $query->setFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km');
     $query = new Query(new MatchAll());
     $query->setFilter($geoFilter);
     $index->refresh();
     $this->assertEquals(2, $type->search($query)->count());
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:32,代码来源:GeoDistanceTest.php

示例3: testSetFilterWithLegacyFilterDeprecated

 /**
  * @group unit
  */
 public function testSetFilterWithLegacyFilterDeprecated()
 {
     $this->hideDeprecated();
     $existsFilter = new Exists('test');
     $this->showDeprecated();
     $query = new Query();
     $errorsCollector = $this->startCollectErrors();
     $query->setFilter($existsFilter);
     $this->finishCollectErrors();
     $errorsCollector->assertOnlyDeprecatedErrors(array('Deprecated: Elastica\\Query::setFilter() passing filter as AbstractFilter is deprecated. Pass instance of AbstractQuery instead.', 'Deprecated: Elastica\\Query::setFilter() is deprecated and will be removed in further Elastica releases. Use Elastica\\Query::setPostFilter() instead.', 'Deprecated: Elastica\\Query::setPostFilter() passing filter as AbstractFilter is deprecated. Pass instance of AbstractQuery instead.'));
 }
开发者ID:vinusebastian,项目名称:Elastica,代码行数:14,代码来源:QueryTest.php

示例4: 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->setFilter(new TermFilter(array('test' => $test)));
         $result = $type->search($query);
         $times[] = $result->getResponse()->getQueryTime();
     }
     self::logResults('random read', $transport, $times);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:19,代码来源:TransportTest.php

示例5: 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->setFilter($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:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:47,代码来源:BoolTest.php

示例6: 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->setFilter($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:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:21,代码来源:IndicesTest.php

示例7: 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

示例8: findOneBy

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

示例9: searchChildren

 /**
  * Search children.
  *
  * @param string $type Post type
  * @param int $parent Parent ID to get all children
  * @param string $order Order way
  * @return array $search Combine of all results, total and aggregations
  *
  * @since 3.0.0
  */
 public function searchChildren($type, $parent, $order = 'desc')
 {
     //Check page
     if (is_search()) {
         return;
     }
     //Return array
     $return = array('parent' => $parent, 'total' => 0, 'results' => array());
     //Check request
     if (empty($parent)) {
         return $return;
     }
     //Get query vars
     $results = array();
     $types = array();
     //Get Elasticsearch datas
     $index = $this->getIndex();
     //Check index
     if (null === $index || empty($index)) {
         return $return;
     }
     //Create the actual search object with some data.
     $es_query = new Query();
     //Define term
     $es_term = new Term();
     $es_term->setTerm($type . '.parent', $parent);
     //Filter 'And'
     $es_filter = new Bool();
     $es_filter->addMust($es_term);
     //Add filter to the search object
     $es_query->setFilter($es_filter);
     //Add sort
     $es_query->setSort(array($type . '.date' => array('order' => $order)));
     //Search!
     $es_resultset = $index->search($es_query);
     //Retrieve data
     $es_results = $es_resultset->getResults();
     //Check results
     if (null == $es_results || empty($es_results)) {
         return $return;
     }
     //Iterate to retrieve all IDs
     foreach ($es_results as $res) {
         $typ = $res->getType();
         //Save type
         $types[$typ] = $typ;
         //Save datas
         $results[$typ][] = array('id' => $res->getId(), 'score' => $res->getScore(), 'source' => $res->getSource());
     }
     //Get total
     $total = $es_resultset->getTotalHits();
     //Return everything
     $return = array('parent' => $parent, 'total' => $total, 'results' => $results);
     return $return;
 }
开发者ID:crewstyle,项目名称:TeaThemeOptions,代码行数:65,代码来源:Elastica.php

示例10: testMoreLikeThisApi

 public function testMoreLikeThisApi()
 {
     $client = new Client(array('persistent' => false));
     $index = $client->getIndex('elastica_test');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $type = new Type($index, 'mlt_test');
     $type->addDocument(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')));
     $type->addDocument(new Document(2, array('visible' => true, 'name' => 'bruce wayne')));
     $type->addDocument(new Document(3, array('visible' => false, 'name' => 'bruce wayne')));
     $type->addDocument(new Document(4, array('visible' => true, 'name' => 'batman')));
     $type->addDocument(new Document(5, array('visible' => false, 'name' => 'batman')));
     $type->addDocument(new Document(6, array('visible' => true, 'name' => 'superman')));
     $type->addDocument(new Document(7, array('visible' => true, 'name' => 'spiderman')));
     $index->refresh();
     $document = $type->getDocument(1);
     // Return all similar
     $resultSet = $type->moreLikeThis($document, array('min_term_freq' => '1', 'min_doc_freq' => '1'));
     $this->assertEquals(4, $resultSet->count());
     // Return just the visible similar
     $query = new Query();
     $filterTerm = new Term();
     $filterTerm->setTerm('visible', true);
     $query->setFilter($filterTerm);
     $resultSet = $type->moreLikeThis($document, array('min_term_freq' => '1', 'min_doc_freq' => '1'), $query);
     $this->assertEquals(2, $resultSet->count());
 }
开发者ID:kskod,项目名称:Elastica,代码行数:26,代码来源:TypeTest.php

示例11: Addons

 public function Addons()
 {
     $list = Addon::get();
     $search = $this->request->getVar('search');
     $type = $this->request->getVar('type');
     $compat = $this->request->getVar('compatibility');
     $tags = $this->request->getVar('tags');
     $sort = $this->request->getVar('sort');
     $view = $this->request->getVar('view');
     if (!$view) {
         $view = 'list';
     }
     if (!in_array($sort, array('name', 'downloads', 'newest'))) {
         $sort = null;
     }
     // Proxy out a search to elastic if any parameters are set.
     if ($search || $type || $compat || $tags) {
         $filter = new BoolAnd();
         $query = new Query();
         $query->setSize(count($list));
         if ($search) {
             $match = new Match();
             $match->setField('_all', $search);
             $query->setQuery($match);
         }
         if ($type) {
             $filter->addFilter(new Term(array('type' => $type)));
         }
         if ($compat) {
             $filter->addFilter(new Terms('compatible', (array) $compat));
         }
         if ($tags) {
             $filter->addFilter(new Terms('tag', (array) $tags));
         }
         if ($type || $compat || $tags) {
             $query->setFilter($filter);
         }
         $list = new ResultList($this->elastica->getIndex(), $query);
         if ($sort) {
             $ids = $list->column('ID');
             if ($ids) {
                 $list = Addon::get()->byIDs($ids);
             } else {
                 $list = new ArrayList();
             }
         }
     } else {
         if (!$sort) {
             $sort = 'downloads';
         }
     }
     switch ($sort) {
         case 'name':
             $list = $list->sort('Name');
             break;
         case 'newest':
             $list = $list->sort('Released', 'DESC');
             break;
         case 'downloads':
             $list = $list->sort('Downloads', 'DESC');
             break;
     }
     $list = new PaginatedList($list, $this->request);
     $list->setPageLength(16);
     return $list;
 }
开发者ID:newleeland,项目名称:addons.silverstripe.org,代码行数:66,代码来源:AddonsController.php


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