From 79501dc319606971b2fa35b088ae23336e42f423 Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Mon, 12 Aug 2013 11:04:54 +0100 Subject: [PATCH 1/2] Add moreLikeThis query to finder --- Finder/TransformedFinder.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Finder/TransformedFinder.php b/Finder/TransformedFinder.php index e1eade8..c520f08 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 From 9d1201099d591915d6d8f511f108570f6b296549 Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Mon, 28 Oct 2013 17:07:49 +0100 Subject: [PATCH 2/2] Add date format field --- DependencyInjection/Configuration.php | 3 +- README.md | 18 ++++++++++ .../DependencyInjection/ConfigurationTest.php | 34 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Tests/DependencyInjection/ConfigurationTest.php diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index df0fe19..d44e714 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -325,7 +325,8 @@ class Configuration implements ConfigurationInterface ->scalarNode('type')->end() ->scalarNode('identifier')->defaultValue('id')->end() ->end() - ->end(); + ->end() + ->scalarNode('format')->end(); if (isset($nestings['fields'])) { $this->addNestedFieldConfig($node, $nestings, 'fields'); diff --git a/README.md b/README.md index c289cd6..1c5c5f3 100644 --- a/README.md +++ b/README.md @@ -666,3 +666,21 @@ fos_elastica: provider: finder: ``` + +#### 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()); + } +}