本文整理汇总了PHP中Elastica\Index类的典型用法代码示例。如果您正苦于以下问题:PHP Index类的具体用法?PHP Index怎么用?PHP Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testQuery
public function testQuery()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$type = new Type($index, 'constant_score');
$doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans'));
$type->addDocument($doc);
$doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil'));
$type->addDocument($doc);
$doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth'));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$boost = 1.3;
$query_match = new MatchAll();
$query = new ConstantScore();
$query->setQuery($query_match);
$query->setBoost($boost);
$expectedArray = array('constant_score' => array('query' => $query_match->toArray(), 'boost' => $boost));
$this->assertEquals($expectedArray, $query->toArray());
$resultSet = $type->search($query);
$results = $resultSet->getResults();
$this->assertEquals($resultSet->count(), 3);
$this->assertEquals($results[1]->getScore(), 1);
}
示例2: write
/**
* @param array $dataSet
*
* @return bool
*/
public function write(array $dataSet)
{
$type = $this->index->getType($this->type);
$type->updateDocuments($this->createDocuments($dataSet));
$response = $type->getIndex()->refresh();
return $response->isOk();
}
示例3: tearDown
protected function tearDown()
{
parent::tearDown();
if ($this->_index instanceof Index) {
$this->_index->delete();
}
}
示例4: testSearch
/**
* @group functional
*/
public function testSearch()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$type = new Type($index, 'helloworld');
$doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans', 'test' => array('2', '3', '5')));
$type->addDocument($doc);
$doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil', 'test' => array('1', '3', '6')));
$type->addDocument($doc);
$doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth', 'test' => array('2', '3', '7')));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$boolQuery = new BoolQuery();
$termQuery1 = new Term(array('test' => '2'));
$boolQuery->addMust($termQuery1);
$resultSet = $type->search($boolQuery);
$this->assertEquals(2, $resultSet->count());
$termQuery2 = new Term(array('test' => '5'));
$boolQuery->addMust($termQuery2);
$resultSet = $type->search($boolQuery);
$this->assertEquals(1, $resultSet->count());
$termQuery3 = new Term(array('username' => 'hans'));
$boolQuery->addMust($termQuery3);
$resultSet = $type->search($boolQuery);
$this->assertEquals(1, $resultSet->count());
$termQuery4 = new Term(array('username' => 'emil'));
$boolQuery->addMust($termQuery4);
$resultSet = $type->search($boolQuery);
$this->assertEquals(0, $resultSet->count());
}
示例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: matchDoc
/**
* Match a document to percolator queries
*
* @param \Elastica\Document $doc
* @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Not implemented yet
* @return \Elastica\Response
*/
public function matchDoc(Document $doc, $query = null)
{
$path = $this->_index->getName() . '/type/_percolate';
$data = array('doc' => $doc->getData());
$response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
$data = $response->getData();
return $data['matches'];
}
示例7: createMapping
public function createMapping()
{
// Define mapping
$mapping = new \Elastica\Type\Mapping();
$mapping->setType($this->trackIndex->getType('track'));
// Set mapping
$mapping->setProperties(['id' => ['type' => 'integer', 'include_in_all' => false], 'album' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'title' => ['type' => 'string', 'include_in_all' => true]]], 'name' => ['type' => 'string', 'include_in_all' => true], 'name_not_analyzed' => ['type' => 'string', "index" => "not_analyzed"], 'playList' => ['type' => 'nested', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'name' => ['type' => 'string', 'include_in_all' => true]]], 'genre' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'name' => ['type' => 'string', 'include_in_all' => true]]], 'mediaType' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'name' => ['type' => 'string', 'include_in_all' => true]]], 'composer' => ['type' => 'string', 'include_in_all' => true]]);
// Send mapping to type
$mapping->send();
}
开发者ID:slaparra,项目名称:Training-Elastic-Search-Symfony,代码行数:10,代码来源:CreateElasticSearchTrackIndexCommand.php
示例8: getIndex
/**
* @return Index
*/
private function getIndex()
{
if (null === $this->index) {
$this->index = $this->client->getIndex($this->indexName);
if (!$this->index->exists()) {
$this->index->create();
}
}
return $this->index;
}
示例9: sendMapping
/**
* @param \Elastica\Index $index
* @param string $mappingName
* @param array $mappingData
*
* @return void
*/
protected function sendMapping(Index $index, $mappingName, array $mappingData)
{
$type = $index->getType($mappingName);
$this->messenger->info(sprintf('Send mapping type "%s" (index: "%s")', $mappingName, $index->getName()));
$mapping = new Mapping($type);
foreach ($mappingData as $key => $value) {
$mapping->setParam($key, $value);
}
$mapping->send();
}
示例10: testInvalidElasticRequest
/**
* @expectedException \Elastica\Exception\ResponseException
*/
public function testInvalidElasticRequest()
{
$connection = new Connection();
$connection->setHost('localhost');
$connection->setPort(9500);
$connection->setTransport('Thrift');
$client = new Client();
$client->addConnection($connection);
$index = new Index($client, 'missing_index');
$index->getStatus();
}
示例11: testInvalidElasticRequest
/**
* @group functional
* @expectedException \Elastica\Exception\ResponseException
*/
public function testInvalidElasticRequest()
{
$this->_checkPlugin();
$connection = new Connection();
$connection->setHost($this->_getHost());
$connection->setPort(9500);
$connection->setTransport('Thrift');
$client = $this->_getClient();
$client->addConnection($connection);
$index = new Index($client, 'missing_index');
$index->getStatus();
}
示例12: _waitForAllocation
protected function _waitForAllocation(Index $index)
{
do {
$settings = $index->getStatus()->get();
$allocated = true;
foreach ($settings['shards'] as $shard) {
if ($shard[0]['routing']['state'] != 'STARTED') {
$allocated = false;
}
}
} while (!$allocated);
}
示例13: testSetType
/**
* @group unit
*/
public function testSetType()
{
$document = new Document();
$document->setType('type');
$this->assertEquals('type', $document->getType());
$index = new Index($this->_getClient(), 'index');
$type = $index->getType('type');
$document->setIndex('index2');
$this->assertEquals('index2', $document->getIndex());
$document->setType($type);
$this->assertEquals('index', $document->getIndex());
$this->assertEquals('type', $document->getType());
}
示例14: matchDoc
/**
* Match a document to percolator queries
*
* @param \Elastica\Document $doc
* @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the data
* @return \Elastica\Response
*/
public function matchDoc(Document $doc, $query = null)
{
$path = $this->_index->getName() . '/type/_percolate';
$data = array('doc' => $doc->getData());
// Add query to filter results after percolation
if ($query) {
$query = Query::create($query);
$data['query'] = $query->getQuery();
}
$response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
$data = $response->getData();
return $data['matches'];
}
示例15: testGetDocument
public function testGetDocument()
{
$type = self::$index->getType('message');
$document = $type->getDocument(1);
$message = $this->marshaler->unmarshal($document);
$this->assertTrue($this->message->equals($message));
}