本文整理汇总了PHP中Elastica\Type\Mapping类的典型用法代码示例。如果您正苦于以下问题:PHP Mapping类的具体用法?PHP Mapping怎么用?PHP Mapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetIdNoSource
public function testGetIdNoSource()
{
// Creates a new index 'xodoa' and a type 'user' inside this index
$indexName = 'xodoa';
$typeName = 'user';
$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create(array(), true);
$type = $index->getType($typeName);
$mapping = new Mapping($type);
$mapping->disableSource();
$mapping->send();
// Adds 1 document to the index
$docId = 3;
$doc1 = new Document($docId, array('username' => 'hans'));
$type->addDocument($doc1);
// Refreshes index
$index->refresh();
$resultSet = $type->search('hans');
$this->assertEquals(1, $resultSet->count());
$result = $resultSet->current();
$this->assertEquals(array(), $result->getSource());
$this->assertInstanceOf('Elastica\\Result', $result);
$this->assertEquals($indexName, $result->getIndex());
$this->assertEquals($typeName, $result->getType());
$this->assertEquals($docId, $result->getId());
$this->assertGreaterThan(0, $result->getScore());
$this->assertInternalType('array', $result->getData());
}
示例2: _getTestIndex
protected function _getTestIndex()
{
$index = $this->_createIndex('has_child_test');
$parentType = $index->getType('parent');
$childType = $index->getType('child');
$childMapping = new Mapping($childType);
$childMapping->setParent('parent');
$childMapping->send();
$altType = $index->getType('alt');
$altDoc = new Document('alt1', array('name' => 'altname'));
$altType->addDocument($altDoc);
$parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com'));
$parentType->addDocument($parent1);
$parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com'));
$parentType->addDocument($parent2);
$child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com'));
$child1->setParent('parent1');
$childType->addDocument($child1);
$child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => 'child2@test.com'));
$child2->setParent('parent2');
$childType->addDocument($child2);
$child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => 'child3@test.com', 'alt' => array(array('name' => 'testname'))));
$child3->setParent('parent2');
$childType->addDocument($child3);
$index->refresh();
return $index;
}
示例3: validate
/**
* @return Status
*/
public function validate()
{
$this->outputIndented("Validating mappings...");
if ($this->optimizeIndexForExperimentalHighlighter && !in_array('experimental highlighter', $this->availablePlugins)) {
$this->output("impossible!\n");
return Status::newFatal(new RawMessage("wgCirrusSearchOptimizeIndexForExperimentalHighlighter is set to true but the " . "'experimental highlighter' plugin is not installed on all hosts."));
}
$requiredMappings = $this->mappingConfig;
if (!$this->checkMapping($requiredMappings)) {
/** @var Mapping[] $actions */
$actions = array();
// TODO Conflict resolution here might leave old portions of mappings
foreach ($this->types as $typeName => $type) {
$action = new Mapping($type);
foreach ($requiredMappings[$typeName] as $key => $value) {
$action->setParam($key, $value);
}
$actions[] = $action;
}
try {
// @todo Use $action->send(array('master_timeout' => ...))
// after updating to version of Elastica library that supports it.
// See https://github.com/ruflin/Elastica/pull/1004
foreach ($actions as $action) {
$action->getType()->request('_mapping', Request::PUT, $action->toArray(), array('master_timeout' => $this->masterTimeout));
}
$this->output("corrected\n");
} catch (ExceptionInterface $e) {
$this->output("failed!\n");
$message = ElasticsearchIntermediary::extractMessage($e);
return Status::newFatal(new RawMessage("Couldn't update mappings. Here is elasticsearch's error message: {$message}\n"));
}
}
return Status::newGood();
}
示例4: validate
/**
* @return Status
*/
public function validate()
{
$this->outputIndented("Validating mappings...");
if ($this->optimizeIndexForExperimentalHighlighter && !in_array('experimental highlighter', $this->availablePlugins)) {
$this->output("impossible!\n");
return Status::newFatal(new RawMessage("wgCirrusSearchOptimizeIndexForExperimentalHighlighter is set to true but the " . "'experimental highlighter' plugin is not installed on all hosts."));
}
$requiredMappings = $this->mappingConfig;
if (!$this->checkMapping($requiredMappings)) {
/** @var Mapping[] $actions */
$actions = array();
// TODO Conflict resolution here might leave old portions of mappings
foreach ($this->types as $typeName => $type) {
$action = new Mapping($type);
foreach ($requiredMappings[$typeName] as $key => $value) {
$action->setParam($key, $value);
}
$actions[] = $action;
}
try {
foreach ($actions as $action) {
$action->send();
}
$this->output("corrected\n");
} catch (ExceptionInterface $e) {
$this->output("failed!\n");
$message = ElasticsearchIntermediary::extractMessage($e);
return Status::newFatal(new RawMessage("Couldn't update mappings. Here is elasticsearch's error message: {$message}\n"));
}
}
return Status::newGood();
}
示例5: getElasticaMapping
/**
* @return \Elastica\Type\Mapping
*/
public function getElasticaMapping()
{
$mapping = new Mapping();
$mapping->setProperties($this->getElasticaFields());
$mapping->setParam('date_detection', false);
return $mapping;
}
示例6: 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());
}
示例7: testHasParent
/**
* @group functional
*/
public function testHasParent()
{
$index = $this->_createIndex();
$shopType = $index->getType('shop');
$productType = $index->getType('product');
$mapping = new Mapping();
$mapping->setParent('shop');
$productType->setMapping($mapping);
$shopType->addDocuments(array(new Document('zurich', array('brand' => 'google')), new Document('london', array('brand' => 'apple'))));
$doc1 = new Document(1, array('device' => 'chromebook'));
$doc1->setParent('zurich');
$doc2 = new Document(2, array('device' => 'macmini'));
$doc2->setParent('london');
$productType->addDocument($doc1);
$productType->addDocument($doc2);
$index->refresh();
// All documents
$parentQuery = new HasParent(new MatchAll(), $shopType->getName());
$search = new Search($index->getClient());
$results = $search->search($parentQuery);
$this->assertEquals(2, $results->count());
$match = new Match();
$match->setField('brand', 'google');
$parentQuery = new HasParent($match, $shopType->getName());
$search = new Search($index->getClient());
$results = $search->search($parentQuery);
$this->assertEquals(1, $results->count());
$result = $results->current();
$data = $result->getData();
$this->assertEquals($data['device'], 'chromebook');
}
示例8: 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();
}
示例9: updateElasticsearchMapping
/**
* Add a mapping for the location of the photograph
*/
public function updateElasticsearchMapping(\Elastica\Type\Mapping $mapping)
{
// get the properties of the individual fields as an array
$properties = $mapping->getProperties();
// enable tags to be faceted
$properties['RawValue'] = array('type' => 'string', 'index' => 'not_analyzed');
// set the new properties on the mapping
$mapping->setProperties($properties);
return $mapping;
}
示例10: _getIndexForTest
protected function _getIndexForTest()
{
$index = $this->_createIndex();
$mapping = new Mapping();
$mapping->setProperties(array('comments' => array('type' => 'nested', 'properties' => array('name' => array('type' => 'string'), 'body' => array('type' => 'string')))));
$type = $index->getType('test');
$type->setMapping($mapping);
$type->addDocuments(array(new Document(1, array('comments' => array(array('name' => 'bob', 'body' => 'this is bobs comment'), array('name' => 'john', 'body' => 'this is johns comment')), 'tags' => array('foo', 'bar'))), new Document(2, array('comments' => array(array('name' => 'bob', 'body' => 'this is another comment from bob'), array('name' => 'susan', 'body' => 'this is susans comment')), 'tags' => array('foo', 'baz')))));
$index->refresh();
return $index;
}
示例11: _getIndexForTest
protected function _getIndexForTest()
{
$index = $this->_createIndex('elastica_test_filter_nested');
$type = $index->getType('user');
$mapping = new Mapping();
$mapping->setProperties(array('firstname' => array('type' => 'string', 'store' => 'yes'), 'lastname' => array('type' => 'string'), 'hobbies' => array('type' => 'nested', 'include_in_parent' => true, 'properties' => array('hobby' => array('type' => 'string')))));
$type->setMapping($mapping);
$response = $type->addDocuments(array(new Document(1, array('firstname' => 'Nicolas', 'lastname' => 'Ruflin', 'hobbies' => array(array('hobby' => 'opensource')))), new Document(2, array('firstname' => 'Nicolas', 'lastname' => 'Ippolito', 'hobbies' => array(array('hobby' => 'opensource'), array('hobby' => 'guitar'))))));
$index->refresh();
return $index;
}
示例12: postInstall
public function postInstall(RecordInterface $record)
{
$client = new Client(array('host' => $this->registry['search.host'], 'port' => $this->registry['search.port']));
$index = $client->getIndex('amun');
$index->create();
$type = $index->getType('page');
$mapping = new Mapping();
$mapping->setType($type);
$mapping->setProperties(array('id' => array('type' => 'string', 'include_in_all' => false), 'userId' => array('type' => 'integer', 'include_in_all' => false), 'path' => array('type' => 'string', 'include_in_all' => true), 'title' => array('type' => 'string', 'include_in_all' => true), 'content' => array('type' => 'string', 'include_in_all' => true), 'date' => array('type' => 'date', 'include_in_all' => false)));
$mapping->send();
}
示例13: testParentMapping
public function testParentMapping()
{
$index = $this->_createIndex();
$parenttype = new Type($index, 'parenttype');
$parentmapping = new Mapping($parenttype, array('name' => array('type' => 'string', 'store' => 'yes')));
$parenttype->setMapping($parentmapping);
$childtype = new Type($index, 'childtype');
$childmapping = new Mapping($childtype, array('name' => array('type' => 'string', 'store' => 'yes')));
$childmapping->setParam('_parent', array('type' => 'parenttype'));
$childtype->setMapping($childmapping);
}
示例14: setUp
protected function setUp()
{
parent::setUp();
$this->_index = $this->_createIndex("ip_range");
$mapping = new Mapping();
$mapping->setProperties(array("address" => array("type" => "ip")));
$type = $this->_index->getType("test");
$type->setMapping($mapping);
$docs = array(new Document("1", array("address" => "192.168.1.100")), new Document("2", array("address" => "192.168.1.150")), new Document("3", array("address" => "192.168.1.200")));
$type->addDocuments($docs);
$this->_index->refresh();
}
示例15: getType
/**
* @return Type
*/
private function getType()
{
if (null === $this->type) {
$this->type = $this->getIndex()->getType($this->typeName);
$mapping = new Type\Mapping();
$mapping->setType($this->type);
$mapping->setTtl(['enabled' => true]);
$mapping->setProperties([self::ID_FIELD => ['type' => 'string', 'include_in_all' => true], self::VALUE_FIELD => ['type' => 'string', 'include_in_all' => true]]);
$mapping->send();
}
return $this->type;
}