本文整理汇总了PHP中Elastica\Query::setQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setQuery方法的具体用法?PHP Query::setQuery怎么用?PHP Query::setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Query
的用法示例。
在下文中一共展示了Query::setQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getESQuery
/**
* @return Query
*/
public function getESQuery()
{
if (!$this->esQuery) {
$this->esQuery = new Query();
$this->boolQuery = new Query\BoolQuery();
$this->esQuery->setQuery($this->boolQuery);
$familyQuery = new Query\Match('family', implode(' ', $this->family->getMatchingCodes()));
$this->boolQuery->addMust($familyQuery);
}
return $this->esQuery;
}
开发者ID:VincentChalnot,项目名称:SidusEAVFilterBundle,代码行数:14,代码来源:EAVElasticaFilterConfigurationHandler.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']));
}
示例3: 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']));
}
示例4: 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;
}
示例5: 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());
}
示例6: 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);
}
示例7: search
/**
* @param string $search
* @return ResultSet
*/
public function search($search)
{
$query = new Query();
$query->setQuery($this->getBoolQuery($search));
$query = $this->searchManager->createQuery()->searchWith($query)->hydrateWith($this->getHydrateQuery())->setMaxResults(50);
$this->onSearch($search, $query);
return $query->getResult();
}
示例8: cleanUp
/**
* Remove all outdated documents in the index of the configured type
*
* @return void
*/
public function cleanUp()
{
$dateRange = new Range();
$dateRange->addField(self::$ETL_TIMESTAMP, array('lt' => $this->timestamp));
$query = new Query();
$query->setQuery($dateRange);
$this->type->deleteByQuery($query);
$this->log("Removed outdated documents that were outdated.");
}
示例9: indexAction
/**
* @param Request $request
* @param int $page
* @return \Symfony\Component\HttpFoundation\Response
*/
public function indexAction(Request $request, $page = 1)
{
$getRoles = $request->query->get('role_filters');
$getSubjects = $request->query->get('subject_filters');
$getJournals = $request->query->get('journal_filters');
$roleFilters = !empty($getRoles) ? explode(',', $getRoles) : [];
$subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
$journalFilters = !empty($getJournals) ? explode(',', $getJournals) : [];
$userSearcher = $this->get('fos_elastica.index.search.user');
$userQuery = new Query('*');
if (!empty($roleFilters) || !empty($subjectFilters) || !empty($journalFilters)) {
$boolQuery = new Query\Bool();
foreach ($roleFilters as $role) {
$match = new Query\Match();
$match->setField('journalUsers.roles', $role);
$boolQuery->addMust($match);
}
foreach ($subjectFilters as $subject) {
$match = new Query\Match();
$match->setField('subjects', $subject);
$boolQuery->addMust($match);
}
foreach ($journalFilters as $journal) {
$match = new Query\Match();
$match->setField('journalUsers.journal.title', $journal);
$boolQuery->addMust($match);
}
$userQuery->setQuery($boolQuery);
}
$roleAgg = new Aggregation\Terms('roles');
$roleAgg->setField('journalUsers.roles');
$roleAgg->setOrder('_term', 'asc');
$roleAgg->setSize(0);
$userQuery->addAggregation($roleAgg);
$subjectAgg = new Aggregation\Terms('subjects');
$subjectAgg->setField('subjects');
$subjectAgg->setOrder('_term', 'asc');
$subjectAgg->setSize(0);
$userQuery->addAggregation($subjectAgg);
$journalAgg = new Aggregation\Terms('journals');
$journalAgg->setField('journalUsers.journal.title');
$journalAgg->setOrder('_term', 'asc');
$journalAgg->setSize(0);
$userQuery->addAggregation($journalAgg);
$adapter = new ElasticaAdapter($userSearcher, $userQuery);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(20);
$pagerfanta->setCurrentPage($page);
$people = $pagerfanta->getCurrentPageResults();
$roles = $adapter->getResultSet()->getAggregation('roles')['buckets'];
$subjects = $adapter->getResultSet()->getAggregation('subjects')['buckets'];
$journals = $adapter->getResultSet()->getAggregation('journals')['buckets'];
$data = ['people' => $people, 'roles' => $roles, 'subjects' => $subjects, 'journals' => $journals, 'pagerfanta' => $pagerfanta, 'role_filters' => $roleFilters, 'subject_filters' => $subjectFilters, 'journal_filters' => $journalFilters, 'page' => 'ojs_site_people_index'];
return $this->render('OjsSiteBundle:People:index.html.twig', $data);
}
示例10: addFulltextSearchToQuery
/**
* @param \Elastica\Query $baseQuery
*
* @return \Elastica\Query
*/
protected function addFulltextSearchToQuery(Query $baseQuery)
{
if (!empty($this->searchString)) {
$matchQuery = $this->createFulltextSearchQuery($this->searchString);
} else {
$matchQuery = new MatchAll();
}
$boolQuery = (new BoolQuery())->addMust($matchQuery);
$baseQuery->setQuery($boolQuery);
return $baseQuery;
}
示例11: search
/**
* @param $keyword
* @return \Elastica\ResultSet
*/
public function search($keyword)
{
$query = new Query();
$query->setSize(1000);
$fuzzyQuery = new Query\FuzzyLikeThis();
$fuzzyQuery->setLikeText($keyword);
$fuzzyQuery->setMinSimilarity(0.7);
$query->setQuery($fuzzyQuery);
$results = $this->search->search($query);
return $results;
}
示例12: 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());
}
示例13: 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);
}
示例14: search
/**
* @param Search $search
* @return Result[]
*/
public function search(Search $search)
{
$bool = new Bool();
$match = new Match();
$match->setField('text', $search->getInput());
$bool->addMust($match);
$query = new Query();
$query->setQuery($bool);
$query->setHighlight(['pre_tags' => ['<mark>'], 'post_tags' => ['</mark>'], 'fields' => ['text' => ['highlight_query' => [$bool->toArray()]]]]);
$results = $this->getIndex()->search($query, 50)->getResults();
$this->onSearch($search, $results);
return $results;
}
示例15: searchText
/**
* Search revisions with provided term.
*
* @param string $term Term to search
* @return Status
*/
public function searchText($term)
{
// full-text search
$queryString = new QueryString($term);
$queryString->setFields(array('revisions.text'));
$this->query->setQuery($queryString);
// add aggregation to determine exact amount of matching search terms
$terms = $this->getTerms($term);
$this->query->addAggregation($this->termsAggregation($terms));
// @todo: abstract-away this config? (core/cirrus also has this - share it somehow?)
$this->query->setHighlight(array('fields' => array(static::HIGHLIGHT_FIELD => array('type' => 'plain', 'order' => 'score', 'number_of_fragments' => 1, 'fragment_size' => 10000)), 'pre_tags' => array(static::HIGHLIGHT_PRE), 'post_tags' => array(static::HIGHLIGHT_POST)));
// @todo: support insource: queries (and perhaps others)
$searchable = Connection::getFlowIndex($this->indexBaseName);
if ($this->type !== false) {
$searchable = $searchable->getType($this->type);
}
$search = $searchable->createSearch($this->query);
// @todo: PoolCounter config at PoolCounterSettings-eqiad.php
// @todo: do we want this class to extend from ElasticsearchIntermediary and use its success & failure methods (like CirrusSearch/Searcher does)?
// Perform the search
$work = new PoolCounterWorkViaCallback('Flow-Search', "_elasticsearch", array('doWork' => function () use($search) {
try {
$result = $search->search();
return Status::newGood($result);
} catch (ExceptionInterface $e) {
if (strpos($e->getMessage(), 'dynamic scripting for [groovy] disabled')) {
// known issue with default ES config, let's display a more helpful message
return Status::newFatal(new \RawMessage("Couldn't complete search: dynamic scripting needs to be enabled. " . "Please add 'script.disable_dynamic: false' to your elasticsearch.yml"));
}
return Status::newFatal('flow-error-search');
}
}, 'error' => function (Status $status) {
$status = $status->getErrorsArray();
wfLogWarning('Pool error searching Elasticsearch: ' . $status[0][0]);
return Status::newFatal('flow-error-search');
}));
$result = $work->execute();
return $result;
}