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


PHP Query::create方法代码示例

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


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

示例1: findWithTenant

 public function findWithTenant($searchText, $tenantId, $sortDirection = 'desc')
 {
     $boolFilter = new Filter\Bool();
     $boolFilter->addMust(new Filter\Term(['tenant.id' => $tenantId]));
     $boolQuery = new Query\Bool();
     if ($searchText !== null) {
         $fieldQuery = new Query\MultiMatch();
         $fieldQuery->setQuery("*" . $searchText . "*");
         $fieldQuery->setFields(['name', 'description']);
         $boolQuery->addMust($fieldQuery);
     }
     $filtered = new Query\Filtered($boolQuery, $boolFilter);
     $query = Query::create($filtered);
     $query->addSort(['created_at' => $sortDirection]);
     return $this->findPaginated($query);
 }
开发者ID:cvele,项目名称:fondacija,代码行数:16,代码来源:OrganizationRepository.php

示例2: setRescoreQuery

 /**
  * Sets rescoreQuery object.
  *
  * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
  *
  * @return $this
  */
 public function setRescoreQuery($rescoreQuery)
 {
     $rescoreQuery = BaseQuery::create($rescoreQuery);
     $query = $this->getParam('query');
     $query['rescore_query'] = $rescoreQuery;
     return $this->setParam('query', $query);
 }
开发者ID:hibrahim,项目名称:Elastica,代码行数:14,代码来源:Query.php

示例3: setQuery

    /**
     * Sets query object
     *
     * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
     * @return \Elastica\Query\TopChildren
     */
    public function setQuery($query)
    {
        $query = BaseQuery::create($query);
        $data = $query->toArray();

        return $this->setParam('query', $data['query']);
    }
开发者ID:xxspartan16,项目名称:BMS-Market,代码行数:13,代码来源:TopChildren.php

示例4: testSetSort

 public function testSetSort()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     $doc = new Document(1, array('name' => 'hello world'));
     $type->addDocument($doc);
     $doc = new Document(2, array('firstname' => 'guschti', 'lastname' => 'ruflin'));
     $type->addDocument($doc);
     $doc = new Document(3, array('firstname' => 'nicolas', 'lastname' => 'ruflin'));
     $type->addDocument($doc);
     $queryTerm = new Term();
     $queryTerm->setTerm('lastname', 'ruflin');
     $index->refresh();
     $query = Query::create($queryTerm);
     // ASC order
     $query->setSort(array(array('firstname' => array('order' => 'asc'))));
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     $first = $resultSet->current()->getData();
     $second = $resultSet->next()->getData();
     $this->assertEquals('guschti', $first['firstname']);
     $this->assertEquals('nicolas', $second['firstname']);
     // DESC order
     $query->setSort(array('firstname' => array('order' => 'desc')));
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     $first = $resultSet->current()->getData();
     $second = $resultSet->next()->getData();
     $this->assertEquals('nicolas', $first['firstname']);
     $this->assertEquals('guschti', $second['firstname']);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:31,代码来源:QueryTest.php

示例5: search

 /**
  * Performs a search query and returns either a ResultList (SS template compatible) or an Elastica\ResultSet
  * @param \Elastica\Query|string|array $query
  * @param array $options Options defined in \Elastica\Search
  * @param bool $returnResultList
  * @return ResultList
  */
 public function search($query, $options = null, $returnResultList = true)
 {
     if ($returnResultList) {
         return new ResultList($this->getIndex(), Query::create($query), $this->logger);
     }
     return $this->getIndex()->search($query, $options);
 }
开发者ID:heyday,项目名称:silverstripe-elastica,代码行数:14,代码来源:ElasticaService.php

示例6: testMappingStoreFields

 /**
  * @group functional
  */
 public function testMappingStoreFields()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $mapping = new Mapping($type, array('firstname' => array('type' => 'string', 'store' => true), 'lastname' => array('type' => 'string')));
     $mapping->disableSource();
     $type->setMapping($mapping);
     $firstname = 'Nicolas';
     $doc = new Document(1, array('firstname' => $firstname, 'lastname' => 'Ruflin'));
     $type->addDocument($doc);
     $index->refresh();
     $queryString = new QueryString('ruflin');
     $query = Query::create($queryString);
     $query->setFields(array('*'));
     $resultSet = $type->search($query);
     $result = $resultSet->current();
     $fields = $result->getFields();
     $this->assertEquals($firstname, $fields['firstname'][0]);
     $this->assertArrayNotHasKey('lastname', $fields);
     $this->assertEquals(1, count($fields));
     $index->flush();
     $document = $type->getDocument(1);
     $this->assertEmpty($document->getData());
     $index->delete();
 }
开发者ID:zhangxiaoliu,项目名称:Elastica,代码行数:30,代码来源:MappingTest.php

示例7: setRescoreQuery

 /**
  * Sets rescoreQuery object.
  *
  * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query
  *
  * @return $this
  */
 public function setRescoreQuery($rescoreQuery)
 {
     $query = BaseQuery::create($rescoreQuery);
     $data = $query->toArray();
     $query = $this->getParam('query');
     $query['rescore_query'] = $data['query'];
     return $this->setParam('query', $query);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:15,代码来源:Query.php

示例8: testFindHybridMethodTransformsSearchResults

 public function testFindHybridMethodTransformsSearchResults()
 {
     $transformer = $this->createMockTransformer('hybridTransform');
     $query = Query::create('');
     $limit = 10;
     $finder = $this->createMockFinderForSearch($transformer, $query, $limit);
     $finder->findHybrid($query, $limit);
 }
开发者ID:alekitto,项目名称:FOSElasticaBundle,代码行数:8,代码来源:TransformedFinderTest.php

示例9: autocomplete

 public function autocomplete($term, $limit = 10)
 {
     $fuzzyQuery = new \Elastica\Query\FuzzyLikeThis();
     $fuzzyQuery->addFields(['nameTranslatableRU', 'nameTranslatableEN']);
     $fuzzyQuery->setLikeText($term);
     //$baseQuery = $prefixQuery;
     $filtered = new \Elastica\Query\Filtered($fuzzyQuery);
     $query = \Elastica\Query::create($filtered);
     return $this->find($query, $limit);
 }
开发者ID:krombox,项目名称:motion,代码行数:10,代码来源:CityRepository.php

示例10: autocomplete

 public function autocomplete($term, $limit = 10)
 {
     if ($term != null) {
         $prefixQuery = new \Elastica\Query\Prefix();
         $prefixQuery->setPrefix('tag.name', $term);
     } else {
         $prefixQuery = new \Elastica\Query\MatchAll();
     }
     $baseQuery = $prefixQuery;
     $filtered = new \Elastica\Query\Filtered($baseQuery);
     $query = \Elastica\Query::create($filtered);
     return $this->find($query, $limit);
 }
开发者ID:krombox,项目名称:motion,代码行数:13,代码来源:MyTagRepository.php

示例11: testFuzzySuggestWorks

 /**
  * @group functional
  */
 public function testFuzzySuggestWorks()
 {
     $suggest = new Completion('suggestName', 'fieldName');
     $suggest->setFuzzy(array('fuzziness' => 2));
     $suggest->setText('Neavermint');
     $index = $this->_getIndexForTest();
     $resultSet = $index->search(Query::create($suggest));
     $this->assertTrue($resultSet->hasSuggests());
     $suggests = $resultSet->getSuggests();
     $options = $suggests['suggestName'][0]['options'];
     $this->assertCount(1, $options);
     $this->assertEquals('Nevermind - Nirvana', $options[0]['text']);
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:16,代码来源:CompletionTest.php

示例12: searchAdvanced

 public function searchAdvanced($q = '')
 {
     if ($q == '') {
         $baseQuery = new \Elastica\Query\MatchAll();
     } else {
         $baseQuery = new \Elastica\Query\Match();
         $baseQuery->setFieldQuery('description', $q);
         $baseQuery->setFieldFuzziness('description', 0.7);
         $baseQuery->setFieldMinimumShouldMatch('description', '80%');
     }
     $boolFilter = new \Elastica\Filter\BoolFilter();
     $dateFrom = new \DateTime();
     $dateFrom->sub(new \DateInterval('P7D'));
     $dateTo = new \DateTime();
     $dateTo->add(new \DateInterval('P1D'));
     $boolFilter->addMust(new \Elastica\Filter\Range('createdAt', array('gte' => \Elastica\Util::convertDate($dateFrom->getTimestamp()), 'lte' => \Elastica\Util::convertDate($dateTo->getTimestamp()))));
     /*
      * $boolFilter->addMust(
      *     new \Elastica\Filter\Term(array('isPublished' => true))
      * );
      * $boolFilter->addMust(
      *     new \Elastica\Filter\Terms('isPublished', array('1', '2', '3'))
      * );
      */
     /*
      * $baseQuery = new \Elastica\Filter\Bool();
      * $baseQuery->addShould(
      *     new \Elastica\Filter\Term(array('id' => intval($q)))
      * );
      * $baseQuery->addShould(
      *     new \Elastica\Filter\Term(array('amount' => floatval($q)))
      * );
      * $filtered = new \Elastica\Query\Filtered();
      * $filtered->setFilter($baseQuery);
      * return $this->finder->find($filtered);
      */
     /*
      * $baseQuery  = new \Elastica\Query\Bool;
      * $idQueryTerm = new \Elastica\Query\Term;
      * $idQueryTerm->setTerm('id', intval($q));
      * $baseQuery->addShould($idQueryTerm);
      */
     $filtered = new \Elastica\Query\Filtered($baseQuery, $boolFilter);
     $query = \Elastica\Query::create($filtered);
     $query->addSort(array('id' => array('order' => 'asc')));
     $query->setSize(1);
     return $this->find($query);
 }
开发者ID:romanruskov,项目名称:loanplatform,代码行数:48,代码来源:LoanRepository.php

示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $indexName = $input->getOption('index');
     /** @var $index \Elastica\Index */
     $index = $this->getContainer()->get('fos_elastica.index_manager')->getIndex($indexName ? $indexName : null);
     $type = $index->getType($input->getArgument('type'));
     $query = Query::create($input->getArgument('query'));
     $query->setSize($input->getOption('limit'));
     if ($input->getOption('explain')) {
         $query->setExplain(true);
     }
     $resultSet = $type->search($query);
     $output->writeLn(sprintf('Found %d results', $type->count($query)));
     foreach ($resultSet->getResults() as $result) {
         $output->writeLn($this->formatResult($result, $input->getOption('show-field'), $input->getOption('show-source'), $input->getOption('show-id'), $input->getOption('explain')));
     }
 }
开发者ID:anteros,项目名称:FOSElasticaBundle,代码行数:20,代码来源:SearchCommand.php

示例14: testPartialFailure

 public function testPartialFailure()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('elastica_partial_failure');
     $index->create(array('index' => array('number_of_shards' => 5, 'number_of_replicas' => 0)), true);
     $type = $index->getType('folks');
     $type->addDocument(new Document('', array('name' => 'ruflin')));
     $type->addDocument(new Document('', array('name' => 'bobrik')));
     $type->addDocument(new Document('', array('name' => 'kimchy')));
     $index->refresh();
     $query = Query::create(array('query' => array('filtered' => array('filter' => array('script' => array('script' => 'doc["undefined"] > 8'))))));
     try {
         $index->search($query);
         $this->fail('PartialShardFailureException should have been thrown');
     } catch (PartialShardFailureException $e) {
         $resultSet = new ResultSet($e->getResponse(), $query);
         $this->assertEquals(0, count($resultSet->getResults()));
     }
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:19,代码来源:PartialShardFailureExceptionTest.php

示例15: testElasticaSubscriber

 public function testElasticaSubscriber()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new ElasticaQuerySubscriber());
     $dispatcher->addSubscriber(new MockPaginationSubscriber());
     // pagination view
     $p = new Paginator($dispatcher);
     $query = Query::create(new Term(array('name' => 'Fred')));
     $response = $this->getMockBuilder('Elastica\\ResultSet')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('getTotalHits')->will($this->returnValue(2));
     $response->expects($this->once())->method('getResults')->will($this->returnValue(array(new Result(array()), new Result(array()))));
     $searchable = $this->getMockBuilder('Elastica\\SearchableInterface')->getMock();
     $searchable->expects($this->once())->method('search')->with($query)->will($this->returnValue($response));
     $view = $p->paginate(array($searchable, $query), 1, 10);
     $this->assertEquals(0, $query->getParam('from'), 'Query offset set correctly');
     $this->assertEquals(10, $query->getParam('size'), 'Query limit set correctly');
     $this->assertSame($response, $view->getCustomParameter('resultSet'), 'Elastica ResultSet available in Paginator');
     $this->assertEquals(1, $view->getCurrentPageNumber());
     $this->assertEquals(10, $view->getItemNumberPerPage());
     $this->assertEquals(2, count($view->getItems()));
     $this->assertEquals(2, $view->getTotalItemCount());
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:22,代码来源:ElasticaTest.php


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