setMapping() 공개 메소드

Sets value type mapping for this type.
public setMapping ( Mapping | array $mapping ) : Response
$mapping Elastica\Type\Mapping | array Elastica\Type\MappingType object or property array with all mappings
리턴 Response
 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_functionscore');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'not_analyzed'), 'location' => array('type' => 'geo_point'), 'price' => array('type' => 'float')));
     $this->type->addDocument(new Document(1, array('name' => "Mr. Frostie's", 'location' => array('lat' => 32.799605, 'lon' => -117.243027), 'price' => 4.5)));
     $this->type->addDocument(new Document(2, array('name' => "Miller's Field", 'location' => array('lat' => 32.795964, 'lon' => -117.255028), 'price' => 9.5)));
     $this->index->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_boostingquery');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'analyzed'), 'price' => array('type' => 'float')));
     $this->sampleData = array(array("name" => "Vital Lama", "price" => 5.2), array("name" => "Vital Match", "price" => 2.1), array("name" => "Mercury Vital", "price" => 7.5), array("name" => "Fist Mercury", "price" => 3.8), array("name" => "Lama Vital 2nd", "price" => 3.2));
     foreach ($this->sampleData as $key => $value) {
         $this->type->addDocument(new Document($key, $value));
     }
     $this->index->refresh();
 }
 /**
  * @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' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '*****@*****.**', '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());
 }
예제 #4
0
파일: TypeTest.php 프로젝트: kskod/Elastica
 public function testNoSource()
 {
     $index = $this->_createIndex();
     $type = new Type($index, 'user');
     $mapping = new Mapping($type, array('id' => array('type' => 'integer', 'store' => 'yes'), 'username' => array('type' => 'string', 'store' => 'no')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $mapping = $type->getMapping();
     $this->assertArrayHasKey('user', $mapping);
     $this->assertArrayHasKey('properties', $mapping['user']);
     $this->assertArrayHasKey('id', $mapping['user']['properties']);
     $this->assertArrayHasKey('type', $mapping['user']['properties']['id']);
     $this->assertEquals('integer', $mapping['user']['properties']['id']['type']);
     // Adds 1 document to the index
     $doc1 = new Document(1, array('username' => 'hans', 'test' => array('2', '3', '5')));
     $type->addDocument($doc1);
     // Adds a list of documents with _bulk upload to the index
     $docs = array();
     $docs[] = new Document(2, array('username' => 'john', 'test' => array('1', '3', '6')));
     $docs[] = new Document(3, array('username' => 'rolf', 'test' => array('2', '3', '7')));
     $type->addDocuments($docs);
     // To update index
     $index->refresh();
     $resultSet = $type->search('rolf');
     $this->assertEquals(1, $resultSet->count());
     // Tests if no source is in response except id
     $result = $resultSet->current();
     $this->assertEquals(3, $result->getId());
     $this->assertEmpty($result->getData());
 }
예제 #5
0
 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);
 }
예제 #6
0
 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, 'helloworldfuzzy');
     $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' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $fltQuery = new FuzzyLikeThis();
     $fltQuery->setLikeText("sample gmail");
     $fltQuery->addFields(array("email", "content"));
     $fltQuery->setMinSimilarity(0.3);
     $fltQuery->setMaxQueryTerms(3);
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(1, $resultSet->count());
 }
예제 #7
0
 /**
  * @group functional
  */
 public function testParentMapping()
 {
     $index = $this->_createIndex();
     $childtype = new Type($index, 'childtype');
     $childmapping = new Mapping($childtype, array('name' => array('type' => 'string', 'store' => true)));
     $childmapping->setParent('parenttype');
     $childtype->setMapping($childmapping);
     $data = $childmapping->toArray();
     $this->assertEquals('parenttype', $data[$childtype->getName()]['_parent']['type']);
     $parenttype = new Type($index, 'parenttype');
     $parentmapping = new Mapping($parenttype, array('name' => array('type' => 'string', 'store' => true)));
     $parenttype->setMapping($parentmapping);
 }
예제 #8
0
 public function testAddWordxFile()
 {
     $indexMapping = array('file' => array('type' => 'attachment'), 'text' => array('type' => 'string', 'store' => 'no'));
     $indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0));
     $index = $this->_createIndex();
     $type = new Type($index, 'content');
     $index->create($indexParams, true);
     $type->setMapping($indexMapping);
     $doc1 = new Document(1);
     $doc1->addFile('file', BASE_PATH . '/data/test.docx');
     $doc1->set('text', 'basel world');
     $type->addDocument($doc1);
     $doc2 = new Document(2);
     $doc2->set('text', 'running in basel');
     $type->addDocument($doc2);
     $index->optimize();
     $resultSet = $type->search('xodoa');
     $this->assertEquals(1, $resultSet->count());
     $resultSet = $type->search('basel');
     $this->assertEquals(2, $resultSet->count());
     $resultSet = $type->search('ruflin');
     $this->assertEquals(0, $resultSet->count());
 }
예제 #9
0
 /**
  * Copies type mappings and documents from an old index to a new index.
  *
  * @see \Elastica\Tool\CrossIndex::reindex()
  *
  * @param \Elastica\Index $oldIndex
  * @param \Elastica\Index $newIndex
  * @param array           $options  keys: CrossIndex::OPTION_* constants
  *
  * @return \Elastica\Index The new index object
  */
 public static function copy(Index $oldIndex, Index $newIndex, array $options = array())
 {
     // normalize types to array of string
     $types = array();
     if (isset($options[self::OPTION_TYPE])) {
         $types = $options[self::OPTION_TYPE];
         $types = is_array($types) ? $types : array($types);
         $types = array_map(function ($type) {
             if ($type instanceof Type) {
                 $type = $type->getName();
             }
             return (string) $type;
         }, $types);
     }
     // copy mapping
     foreach ($oldIndex->getMapping() as $type => $mapping) {
         if (!empty($types) && !in_array($type, $types, true)) {
             continue;
         }
         $type = new Type($newIndex, $type);
         $type->setMapping($mapping['properties']);
     }
     // copy documents
     return self::reindex($oldIndex, $newIndex, $options);
 }
예제 #10
0
 /**
  * @group functional
  */
 public function testGetMappingAlias()
 {
     $aliasName = 'test-alias';
     $typeName = 'test-alias-type';
     $index = $this->_createIndex();
     $index->addAlias($aliasName);
     $type = new Type($index, $typeName);
     $mapping = new Mapping($type, $expect = array('id' => array('type' => 'integer', 'store' => true)));
     $type->setMapping($mapping);
     $client = $index->getClient();
     $this->assertEquals(array('test-alias-type' => array('properties' => $expect)), $client->getIndex($aliasName)->getType($typeName)->getMapping());
 }
예제 #11
0
파일: Client.php 프로젝트: revinate/search
 /**
  * {@inheritdoc}
  */
 public function updateMapping(ClassMetadata $classMetadata)
 {
     try {
         $elasticaIndex = new Index($this->client, $classMetadata->getIndexForRead());
         $elasticaType = new Type($elasticaIndex, $classMetadata->type);
         $elasticaTypeMapping = new Mapping($elasticaType, $this->getMapping($classMetadata->fieldMappings));
         $elasticaTypeMapping->setParam('_id', array('path' => $classMetadata->getIdentifier()));
         if ($classMetadata->parent) {
             $elasticaTypeMapping->setParam('_parent', array('type' => $classMetadata->parent));
         }
         if ($classMetadata->dynamic) {
             $elasticaTypeMapping->setParam('dynamic', $classMetadata->dynamic);
         }
         $response = $elasticaType->setMapping($elasticaTypeMapping);
     } catch (\Exception $e) {
         return $e->getMessage();
     }
     return 200 == $response->getStatus() ? true : $response->getError();
 }
 public function testSearchSetAnalyzer()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array('analysis' => array('analyzer' => array('searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('myStopWords'))), 'filter' => array('myStopWords' => array('type' => 'stop', 'stopwords' => array('The'))))), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldfuzzy');
     $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' => '*****@*****.**', 'content' => 'The Fuzzy Test!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '*****@*****.**', 'content' => 'Elastica Fuzzy Test'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $fltQuery = new FuzzyLikeThis();
     $fltQuery->addFields(array("email", "content"));
     $fltQuery->setLikeText("The");
     $fltQuery->setMinSimilarity(0.1);
     $fltQuery->setMaxQueryTerms(3);
     // Test before analyzer applied, should return 1 result
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(1, $resultSet->count());
     $fltQuery->setParam('analyzer', 'searchAnalyzer');
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(0, $resultSet->count());
 }
예제 #13
-1
 protected function setUp()
 {
     /** @var ElasticaService elasticaService */
     $elasticaService = $this->getContainer()->get("revinate_search.elasticsearch_service");
     $this->elasticaClient = $elasticaService->getInstance();
     $this->index = new \Elastica\Index($this->elasticaClient, View::INDEX_NAME);
     if (!$this->index->exists()) {
         $this->index->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
         $this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
         $mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/mapping.json"), true);
         $mapping = new \Elastica\Type\Mapping($this->type, $mappingJson['properties']);
         $this->type->setMapping($mapping);
     } else {
         $this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
     }
     $this->timeSeriesIndex = new \Elastica\Index($this->elasticaClient, StatusLog::INDEX_NAME . self::$timeSeriesTestDateSuffix);
     if (!$this->timeSeriesIndex->exists()) {
         $this->timeSeriesIndex->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
         $this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
         $mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/statusLogMapping.json"), true);
         $mapping = new \Elastica\Type\Mapping($this->timeSeriesType, $mappingJson['properties']);
         $this->timeSeriesType->setMapping($mapping);
     } else {
         $this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
     }
 }