當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。