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


PHP Elastica\Query类代码示例

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


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

示例1: indexAction

 public function indexAction(Request $request, $page = 1)
 {
     $getTypes = $request->query->get('type_filters');
     $getSubjects = $request->query->get('subject_filters');
     $getPublishers = $request->query->get('publisher_filters');
     $typeFilters = !empty($getTypes) ? explode(',', $getTypes) : [];
     $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
     $publisherFilters = !empty($getPublishers) ? explode(',', $getPublishers) : [];
     $journalSearcher = $this->get('fos_elastica.index.search.journal');
     $boolQuery = new Query\Bool();
     $match = new Query\Match();
     $match->setField('status', 1);
     $boolQuery->addMust($match);
     $match = new Query\Match();
     $match->setField('published', true);
     $boolQuery->addMust($match);
     if (!empty($typeFilters) || !empty($subjectFilters) || !empty($publisherFilters)) {
         foreach ($typeFilters as $type) {
             $match = new Query\Match();
             $match->setField('publisher.publisher_type.name', $type);
             $boolQuery->addMust($match);
         }
         foreach ($subjectFilters as $subject) {
             $match = new Query\Match();
             $match->setField('subjects.subject', $subject);
             $boolQuery->addMust($match);
         }
         foreach ($publisherFilters as $publisher) {
             $match = new Query\Match();
             $match->setField('publisher.name', $publisher);
             $boolQuery->addMust($match);
         }
     }
     $journalQuery = new Query($boolQuery);
     $typeAgg = new Aggregation\Terms('types');
     $typeAgg->setField('publisher.publisher_type.name');
     $typeAgg->setOrder('_term', 'asc');
     $typeAgg->setSize(0);
     $journalQuery->addAggregation($typeAgg);
     $subjectAgg = new Aggregation\Terms('subjects');
     $subjectAgg->setField('subjects.subject');
     $subjectAgg->setOrder('_term', 'asc');
     $subjectAgg->setSize(0);
     $journalQuery->addAggregation($subjectAgg);
     $publisherAgg = new Aggregation\Terms('publishers');
     $publisherAgg->setField('publisher.name');
     $publisherAgg->setOrder('_term', 'asc');
     $publisherAgg->setSize(0);
     $journalQuery->addAggregation($publisherAgg);
     $adapter = new ElasticaAdapter($journalSearcher, $journalQuery);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(21);
     $pagerfanta->setCurrentPage($page);
     $journals = $pagerfanta->getCurrentPageResults();
     $types = $adapter->getResultSet()->getAggregation('types')['buckets'];
     $subjects = $adapter->getResultSet()->getAggregation('subjects')['buckets'];
     $publishers = $adapter->getResultSet()->getAggregation('publishers')['buckets'];
     $data = ['types' => $types, 'subjects' => $subjects, 'publishers' => $publishers, 'type_filters' => $typeFilters, 'subject_filters' => $subjectFilters, 'publisher_filters' => $publisherFilters, 'journals' => $journals, 'pagerfanta' => $pagerfanta, 'page' => 'explore'];
     return $this->render('OjsSiteBundle:Explore:index.html.twig', $data);
 }
开发者ID:hasantayyar,项目名称:ojs,代码行数:60,代码来源:ExploreController.php

示例2: testTest

 public function testTest()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('helloworld');
     $mapping = new Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss')));
     $type->setMapping($mapping);
     $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
     $type->addDocument($doc);
     $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
     $type->addDocument($doc);
     $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
     $type->addDocument($doc);
     $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
     $type->addDocument($doc);
     $facet = new DateHistogram('dateHist1');
     $facet->setInterval("day");
     $facet->setField("dtmPosted");
     $query = new Query();
     $query->addFacet($facet);
     $query->setQuery(new MatchAll());
     $index->refresh();
     $response = $type->search($query);
     $facets = $response->getFacets();
     $this->assertEquals(4, $response->getTotalHits());
     $this->assertEquals(2, count($facets['dateHist1']['entries']));
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:28,代码来源:DateHistogramTest.php

示例3: applyQueries

 /**
  * @inheritDoc
  */
 public function applyQueries($query, $alias = null, string $column = null, string $sort = null, array $ids = [], array $order = [])
 {
     if (!$query instanceof Filtered) {
         throw new \InvalidArgumentException('Expected argument of type "Elastica\\Query\\Filtered", ' . get_class($query) . ' given');
     }
     if (!empty($ids)) {
         /** @var BoolFilter $filter */
         $filter = $query->getFilter();
         $idsFilter = new Terms();
         $idsFilter->setTerms('id', $ids);
         $filter->addMust($idsFilter);
         $query->setFilter($filter);
     }
     $newQuery = new Query();
     $newQuery->setQuery($query);
     $query = $newQuery;
     unset($newQuery);
     if ($column !== null && $sort !== null) {
         $query->addSort([$column => ['order' => strtolower($sort)]]);
     }
     unset($sort);
     if (!empty($order)) {
         foreach ($order as $sort => $o) {
             if ($column !== $sort) {
                 $query->addSort([$sort => ['order' => strtolower($o)]]);
             }
         }
     }
     return $query;
 }
开发者ID:vardius,项目名称:list-bundle,代码行数:33,代码来源:DataProvider.php

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

示例5: testFactor

 /**
  * @group functional
  */
 public function testFactor()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('helloworld');
     $mapping = new Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'long', 'store' => 'no')));
     $type->setMapping($mapping);
     $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => 1308865980));
     $type->addDocument($doc);
     $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => 1308822780));
     $type->addDocument($doc);
     $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => 1310115180));
     $type->addDocument($doc);
     $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => 1310089980));
     $type->addDocument($doc);
     $facet = new DateHistogram('dateHist1');
     $facet->setInterval('day');
     $facet->setField('dtmPosted');
     $facet->setFactor(1000);
     $query = new Query();
     $query->addFacet($facet);
     $query->setQuery(new MatchAll());
     $index->refresh();
     $response = $type->search($query);
     $facets = $response->getFacets();
     $this->assertEquals(4, $response->getTotalHits());
     $this->assertEquals(2, count($facets['dateHist1']['entries']));
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:32,代码来源:DateHistogramTest.php

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

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

示例8: testReverseNestedAggregation

 /**
  * @group functional
  */
 public function testReverseNestedAggregation()
 {
     $agg = new Nested('comments', 'comments');
     $names = new Terms('name');
     $names->setField('comments.name');
     $tags = new Terms('tags');
     $tags->setField('tags');
     $reverseNested = new ReverseNested('main');
     $reverseNested->addAggregation($tags);
     $names->addAggregation($reverseNested);
     $agg->addAggregation($names);
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('comments');
     $this->assertArrayHasKey('name', $results);
     $nameResults = $results['name'];
     $this->assertCount(3, $nameResults['buckets']);
     // bob
     $this->assertEquals('bob', $nameResults['buckets'][0]['key']);
     $tags = array(array('key' => 'foo', 'doc_count' => 2), array('key' => 'bar', 'doc_count' => 1), array('key' => 'baz', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][0]['main']['tags']['buckets']);
     // john
     $this->assertEquals('john', $nameResults['buckets'][1]['key']);
     $tags = array(array('key' => 'bar', 'doc_count' => 1), array('key' => 'foo', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][1]['main']['tags']['buckets']);
     // susan
     $this->assertEquals('susan', $nameResults['buckets'][2]['key']);
     $tags = array(array('key' => 'baz', 'doc_count' => 1), array('key' => 'foo', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][2]['main']['tags']['buckets']);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:33,代码来源:ReverseNestedTest.php

示例9: testQuery

 /**
  * @group functional
  */
 public function testQuery()
 {
     $client = $this->_getClient();
     $nodes = $client->getCluster()->getNodes();
     if (!$nodes[0]->getInfo()->hasPlugin('geocluster-facet')) {
         $this->markTestSkipped('geocluster-facet plugin not installed');
     }
     $index = $this->_createIndex();
     $type = $index->getType('testQuery');
     $geoField = 'location';
     $type->setMapping(new Mapping($type, array($geoField => array('type' => 'geo_point', 'lat_lon' => true))));
     $doc = new Document(1, array('name' => 'item1', 'location' => array(20, 20)));
     $type->addDocument($doc);
     $doc = new Document(2, array('name' => 'item2', 'location' => array(20, 20)));
     $type->addDocument($doc);
     $doc = new Document(3, array('name' => 'item3', 'location' => array(20, 20)));
     $type->addDocument($doc);
     $index->refresh();
     $facet = new GeoCluster('clusters');
     $facet->setField($geoField)->setFactor(1)->setShowIds(false);
     $query = new Query();
     $query->setFacets(array($facet));
     $response = $type->search($query);
     $facets = $response->getFacets();
     $this->assertEquals(1, count($facets['clusters']['clusters']));
     $index->delete();
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:30,代码来源:GeoClusterTest.php

示例10: testResponse

 public function testResponse()
 {
     $index = $this->_createIndex();
     $type = $index->getType('helloworld');
     $mapping = new Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss')));
     $type->setMapping($mapping);
     $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
     $type->addDocument($doc);
     $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
     $type->addDocument($doc);
     $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
     $type->addDocument($doc);
     $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
     $type->addDocument($doc);
     $query = new Query();
     $query->setQuery(new MatchAll());
     $index->refresh();
     $resultSet = $type->search($query);
     $engineTime = $resultSet->getResponse()->getEngineTime();
     $shardsStats = $resultSet->getResponse()->getShardsStatistics();
     $this->assertInternalType('int', $engineTime);
     $this->assertTrue(is_array($shardsStats));
     $this->assertArrayHasKey('total', $shardsStats);
     $this->assertArrayHasKey('successful', $shardsStats);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:25,代码来源:ResponseTest.php

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

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

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

示例14: testSearch

 /**
  * @group functional
  */
 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldmlt');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => 'nospam@gmail.com', 'content' => 'This is a fake nospam email address for gmail'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $mltQuery = new MoreLikeThis();
     $mltQuery->setLike('fake gmail sample');
     $mltQuery->setFields(array('email', 'content'));
     $mltQuery->setMaxQueryTerms(3);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinTermFrequency(1);
     $query = new Query();
     $query->setQuery($mltQuery);
     $resultSet = $type->search($query);
     $resultSet->getResponse()->getData();
     $this->assertEquals(2, $resultSet->count());
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:32,代码来源:MoreLikeThisTest.php

示例15: testScriptedMetricAggregation

 /**
  * @group functional
  */
 public function testScriptedMetricAggregation()
 {
     $agg = new ScriptedMetric('scripted', "_agg['durations'] = [:]", "key = doc['start'].value+ \":\"+ doc['end'].value; _agg.durations[key] = doc['end'].value - doc['start'].value;", 'values = []; for (item in _agg.durations) { values.add(item.value) }; return values');
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('scripted');
     $this->assertEquals(array(100, 50, 150), $results['value'][0]);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:11,代码来源:ScriptedMetricTest.php


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