diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f9f633f..8a067b5 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -339,6 +339,14 @@ class Configuration implements ConfigurationInterface ->scalarNode('index_options')->end() ->scalarNode('ignore_above')->end() ->scalarNode('position_offset_gap')->end() + ->arrayNode('_parent') + ->treatNullLike(array()) + ->children() + ->scalarNode('type')->end() + ->scalarNode('identifier')->defaultValue('id')->end() + ->end() + ->end() + ->scalarNode('format')->end(); ; if (isset($nestings['fields'])) { diff --git a/Finder/TransformedFinder.php b/Finder/TransformedFinder.php index e0b9cd0..123aba6 100644 --- a/Finder/TransformedFinder.php +++ b/Finder/TransformedFinder.php @@ -45,6 +45,22 @@ class TransformedFinder implements PaginatedFinderInterface return $this->transformer->hybridTransform($results); } + /** + * Find documents similar to one with passed id. + * + * @param integer $id + * @param array $params + * @param array $query + * @return array of model objects + **/ + public function moreLikeThis($id, $params = array(), $query = array()) + { + $doc = new Document($id); + $results = $this->searchable->moreLikeThis($doc, $params, $query)->getResults(); + + return $this->transformer->transform($results); + } + /** * @param $query * @param null|int $limit diff --git a/README.md b/README.md index 22d4100..e132a15 100644 --- a/README.md +++ b/README.md @@ -102,9 +102,9 @@ Here we created a "website" index, that uses our "default" client. Our index is now available as a service: `fos_elastica.index.website`. It is an instance of `\Elastica\Index`. -If you need to have different index name from the service name, for example, -in order to have different indexes for different environments then you can -use the ```index_name``` key to change the index name. The service name will +If you need to have different index name from the service name, for example, +in order to have different indexes for different environments then you can +use the ```index_name``` key to change the index name. The service name will remain the same across the environments: fos_elastica: @@ -114,8 +114,8 @@ remain the same across the environments: website: client: default index_name: website_qa - -The service id will be `fos_elastica.index.website` but the underlying index name is website_qa. + +The service id will be `fos_elastica.index.website` but the underlying index name is website_qa. #### Declare a type @@ -796,3 +796,21 @@ $term = new \Elastica\Filter\Term(array('active' => true)); $filteredQuery = new \Elastica\Query\Filtered($query, $term); $results = $this->container->get('fos_elastica.finder.index.type')->find($filteredQuery); ``` + +### Date format example + +If you want to specify a [date format](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html): + +```yaml +fos_elastica: + clients: + default: { host: localhost, port: 9200 } + indexes: + site: + types: + user: + mappings: + username: { type: string } + lastlogin: { type: date, format: basic_date_time } + birthday: { type: date, format: "yyyy-MM-dd" } +``` diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000..f410621 --- /dev/null +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,34 @@ +configuration = new Configuration(array()); + } + + public function testEmptyConfigContainsFormatMappingOptionNode() + { + $tree = $this->configuration->getConfigTree(); + $children = $tree->getChildren(); + $children = $children['indexes']->getPrototype()->getChildren(); + $typeNodes = $children['types']->getPrototype()->getChildren(); + $mappings = $typeNodes['mappings']->getPrototype()->getChildren(); + + $this->assertArrayHasKey('format', $mappings); + $this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $mappings['format']); + $this->assertNull($mappings['format']->getDefaultValue()); + } +}