From 401446e1c4129b37838461f9aec848e049805b9e Mon Sep 17 00:00:00 2001
From: Tim Nagel <tim@nagel.com.au>
Date: Thu, 22 Jan 2015 09:06:21 +1100
Subject: [PATCH 1/7] Add integration testing around _parent mapping

---
 Tests/Functional/MappingToElasticaTest.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Tests/Functional/MappingToElasticaTest.php b/Tests/Functional/MappingToElasticaTest.php
index f42df61..2c9235a 100644
--- a/Tests/Functional/MappingToElasticaTest.php
+++ b/Tests/Functional/MappingToElasticaTest.php
@@ -32,11 +32,15 @@ class MappingToElasticaTest extends WebTestCase
         $this->assertTrue($mapping['type']['properties']['field1']['store']);
         $this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
 
-        $parent = $this->getType($client, 'parent');
-        $mapping = $parent->getMapping();
+        $type = $this->getType($client, 'type');
+        $mapping = $type->getMapping()['type'];
+        $this->assertEquals('parent', $mapping['_parent']['type']);
 
-        $this->assertEquals('my_analyzer', $mapping['parent']['index_analyzer']);
-        $this->assertEquals('whitespace', $mapping['parent']['search_analyzer']);
+        $parent = $this->getType($client, 'parent');
+        $mapping = $parent->getMapping()['parent'];
+
+        $this->assertEquals('my_analyzer', $mapping['index_analyzer']);
+        $this->assertEquals('whitespace', $mapping['search_analyzer']);
     }
 
     public function testResetType()

From c901d605529eb7a4b5a2cf7552640b082f0b19c5 Mon Sep 17 00:00:00 2001
From: Tim Nagel <tim@nagel.com.au>
Date: Thu, 22 Jan 2015 09:10:46 +1100
Subject: [PATCH 2/7] Clarified what index_name does. Closes #731

---
 Resources/doc/setup.md | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/Resources/doc/setup.md b/Resources/doc/setup.md
index 6a1c2ae..a977ff7 100644
--- a/Resources/doc/setup.md
+++ b/Resources/doc/setup.md
@@ -48,25 +48,28 @@ fos_elastica:
     clients:
         default: { host: localhost, port: 9200 }
     indexes:
-        search: ~
+        app: ~
 ```
 
 In this example, an Elastica index (an instance of `Elastica\Index`) is available as a
-service with the key `fos_elastica.index.search`.
+service with the key `fos_elastica.index.app`.
 
-If the Elasticsearch index name needs to be different to the service name in your
-application, for example, renaming the search index based on different environments.
+You may want the index `app` to be named something else on ElasticSearch depending on
+if your application is running in a different env or other conditions that suit your
+application. To set your customer index to a name that depends on the environment of your
+Symfony application, use the example below:
 
 ```yaml
 #app/config/config.yml
 fos_elastica:
     indexes:
-        search:
-            index_name: search_dev
+        app:
+            index_name: app_%kernel.env%
 ```
 
-In this case, the service `fos_elastica.index.search` will be using an Elasticsearch
-index of search_dev.
+In this case, the service `fos_elastica.index.app` will relate to an ElasticSearch index
+that varies depending on your kernel's environment. For example, in dev it will relate to
+`app_dev`.
 
 D) Defining index types
 -----------------------
@@ -81,7 +84,7 @@ will end up being indexed.
 ```yaml
 fos_elastica:
     indexes:
-        search:
+        app:
             types:
                 user:
                     mappings:
@@ -92,7 +95,7 @@ fos_elastica:
 ```
 
 Each defined type is made available as a service, and in this case the service key is
-`fos_elastica.index.search.user` and is an instance of `Elastica\Type`.
+`fos_elastica.index.app.user` and is an instance of `Elastica\Type`.
 
 FOSElasticaBundle requires a provider for each type that will notify when an object
 that maps to a type has been modified. The bundle ships with support for Doctrine and

From 7471c13d75f2c98b30775acbc4f13422ba25558a Mon Sep 17 00:00:00 2001
From: CedCannes <cedric_headroom@yahoo.fr>
Date: Mon, 19 Jan 2015 23:55:52 +0100
Subject: [PATCH 3/7] Update manual-provider.md

Typo in class path
---
 Resources/doc/cookbook/manual-provider.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Resources/doc/cookbook/manual-provider.md b/Resources/doc/cookbook/manual-provider.md
index f4365da..ed5568e 100644
--- a/Resources/doc/cookbook/manual-provider.md
+++ b/Resources/doc/cookbook/manual-provider.md
@@ -8,7 +8,7 @@ index and type for which the service will provide.
 # app/config/config.yml
 services:
     acme.search_provider.user:
-        class: Acme\UserBundle\Search\UserProvider
+        class: Acme\UserBundle\Provider\UserProvider
         arguments:
             - @fos_elastica.index.website.user
         tags:

From 64fa26e3d9fa38b9fdda1280a72bf5f820046fdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20Perrin?= <mperrin@greenflex.com>
Date: Wed, 17 Dec 2014 12:44:57 +0100
Subject: [PATCH 4/7] Fix PHP notice when using indexes without defined types

---
 Configuration/Source/ContainerSource.php | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/Configuration/Source/ContainerSource.php b/Configuration/Source/ContainerSource.php
index 8d094c7..da77009 100644
--- a/Configuration/Source/ContainerSource.php
+++ b/Configuration/Source/ContainerSource.php
@@ -41,13 +41,16 @@ class ContainerSource implements SourceInterface
         $indexes = array();
         foreach ($this->configArray as $config) {
             $types = array();
-            foreach ($config['types'] as $typeConfig) {
-                $types[$typeConfig['name']] = new TypeConfig(
-                    $typeConfig['name'],
-                    $typeConfig['mapping'],
-                    $typeConfig['config']
-                );
-                // TODO: handle prototypes..
+
+            if (isset($config['types'])) {
+                foreach ($config['types'] as $typeConfig) {
+                    $types[$typeConfig['name']] = new TypeConfig(
+                        $typeConfig['name'],
+                        $typeConfig['mapping'],
+                        $typeConfig['config']
+                    );
+                    // TODO: handle prototypes..
+                }
             }
 
             $index = new IndexConfig($config['name'], $types, array(

From b9b0c1b961d8cfaac02e0787af0ee7f4cbc5c9a0 Mon Sep 17 00:00:00 2001
From: Tim Nagel <tim@nagel.com.au>
Date: Thu, 22 Jan 2015 09:33:46 +1100
Subject: [PATCH 5/7] Move TypeConfig creation to its own method

---
 Configuration/Source/ContainerSource.php | 38 ++++++++++++++++--------
 Tests/Functional/app/Basic/config.yml    |  1 +
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/Configuration/Source/ContainerSource.php b/Configuration/Source/ContainerSource.php
index da77009..abcdf1b 100644
--- a/Configuration/Source/ContainerSource.php
+++ b/Configuration/Source/ContainerSource.php
@@ -40,19 +40,7 @@ class ContainerSource implements SourceInterface
     {
         $indexes = array();
         foreach ($this->configArray as $config) {
-            $types = array();
-
-            if (isset($config['types'])) {
-                foreach ($config['types'] as $typeConfig) {
-                    $types[$typeConfig['name']] = new TypeConfig(
-                        $typeConfig['name'],
-                        $typeConfig['mapping'],
-                        $typeConfig['config']
-                    );
-                    // TODO: handle prototypes..
-                }
-            }
-
+            $types = $this->getTypes($config);
             $index = new IndexConfig($config['name'], $types, array(
                 'elasticSearchName' => $config['elasticsearch_name'],
                 'settings' => $config['settings'],
@@ -64,4 +52,28 @@ class ContainerSource implements SourceInterface
 
         return $indexes;
     }
+
+    /**
+     * Builds TypeConfig objects for each type.
+     *
+     * @param array $config
+     * @return array
+     */
+    protected function getTypes($config)
+    {
+        $types = array();
+
+        if (isset($config['types'])) {
+            foreach ($config['types'] as $typeConfig) {
+                $types[$typeConfig['name']] = new TypeConfig(
+                    $typeConfig['name'],
+                    $typeConfig['mapping'],
+                    $typeConfig['config']
+                );
+                // TODO: handle prototypes..
+            }
+        }
+
+        return $types;
+    }
 }
diff --git a/Tests/Functional/app/Basic/config.yml b/Tests/Functional/app/Basic/config.yml
index ebd1ea0..3d0e120 100644
--- a/Tests/Functional/app/Basic/config.yml
+++ b/Tests/Functional/app/Basic/config.yml
@@ -92,3 +92,4 @@ fos_elastica:
                         identifier: "id"
                 null_mappings:
                     mappings: ~
+        empty_index: ~

From 55abe132c658ce6612a72a22fb7f7df46f838b0c Mon Sep 17 00:00:00 2001
From: Tim Nagel <tim@nagel.com.au>
Date: Thu, 22 Jan 2015 09:36:33 +1100
Subject: [PATCH 6/7] Update changelog

---
 CHANGELOG-3.0.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/CHANGELOG-3.0.md b/CHANGELOG-3.0.md
index 70bd181..d7a826f 100644
--- a/CHANGELOG-3.0.md
+++ b/CHANGELOG-3.0.md
@@ -12,6 +12,10 @@ https://github.com/FriendsOfSymfony/FOSElasticaBundle/compare/v3.0.0...v3.0.1
 To generate a changelog summary since the last version, run
 `git log --no-merges --oneline v3.0.0...3.0.x`
 
+* 3.0.8 (Unreleased)
+
+ * Fixed handling of empty indexes #760
+
 * 3.0.7 (2015-01-21)
 
  * Fixed the indexing of parent/child relations, broken since 3.0 #774

From e772ca645017285bc7bfaa29f63b54a60fd1f622 Mon Sep 17 00:00:00 2001
From: Tim Nagel <tim@nagel.com.au>
Date: Thu, 22 Jan 2015 11:23:51 +1100
Subject: [PATCH 7/7] Fix php 5.3 compatibility

---
 Tests/Functional/MappingToElasticaTest.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Tests/Functional/MappingToElasticaTest.php b/Tests/Functional/MappingToElasticaTest.php
index 2c9235a..8fec8a9 100644
--- a/Tests/Functional/MappingToElasticaTest.php
+++ b/Tests/Functional/MappingToElasticaTest.php
@@ -33,14 +33,14 @@ class MappingToElasticaTest extends WebTestCase
         $this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
 
         $type = $this->getType($client, 'type');
-        $mapping = $type->getMapping()['type'];
-        $this->assertEquals('parent', $mapping['_parent']['type']);
+        $mapping = $type->getMapping();
+        $this->assertEquals('parent', $mapping['type']['_parent']['type']);
 
         $parent = $this->getType($client, 'parent');
-        $mapping = $parent->getMapping()['parent'];
+        $mapping = $parent->getMapping();
 
-        $this->assertEquals('my_analyzer', $mapping['index_analyzer']);
-        $this->assertEquals('whitespace', $mapping['search_analyzer']);
+        $this->assertEquals('my_analyzer', $mapping['type']['index_analyzer']);
+        $this->assertEquals('whitespace', $mapping['type']['search_analyzer']);
     }
 
     public function testResetType()
