Merge branch '3.0.x'

This commit is contained in:
Tim Nagel 2015-01-22 11:26:07 +11:00
commit 7f28be3c4e
6 changed files with 50 additions and 23 deletions

View file

@ -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

View file

@ -40,16 +40,7 @@ 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..
}
$types = $this->getTypes($config);
$index = new IndexConfig($config['name'], $types, array(
'elasticSearchName' => $config['elasticsearch_name'],
'settings' => $config['settings'],
@ -61,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;
}
}

View file

@ -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:

View file

@ -58,25 +58,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
-----------------------
@ -91,7 +94,7 @@ will end up being indexed.
```yaml
fos_elastica:
indexes:
search:
app:
types:
user:
mappings:
@ -102,7 +105,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

View file

@ -32,11 +32,15 @@ class MappingToElasticaTest extends WebTestCase
$this->assertTrue($mapping['type']['properties']['field1']['store']);
$this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
$type = $this->getType($client, 'type');
$mapping = $type->getMapping();
$this->assertEquals('parent', $mapping['type']['_parent']['type']);
$parent = $this->getType($client, 'parent');
$mapping = $parent->getMapping();
$this->assertEquals('my_analyzer', $mapping['parent']['index_analyzer']);
$this->assertEquals('whitespace', $mapping['parent']['search_analyzer']);
$this->assertEquals('my_analyzer', $mapping['type']['index_analyzer']);
$this->assertEquals('whitespace', $mapping['type']['search_analyzer']);
}
public function testResetType()

View file

@ -95,3 +95,4 @@ fos_elastica:
identifier: "id"
null_mappings:
mappings: ~
empty_index: ~