diff --git a/README.md b/README.md index 131b1b4..59324d6 100644 --- a/README.md +++ b/README.md @@ -636,3 +636,61 @@ class Client extends BaseClient } } ``` + +### Example of Advanced Query + +If you would like to perform more advanced queries, here is one example using +the snowball stemming algorithm. + +It searches for Article entities using `title`, `tags`, and `categoryIds`. +Results must match at least one specified `categoryIds`, and should match the +`title` or `tags` criteria. Additionally, we define a snowball analyzer to +apply to queries against the `title` field. + +```php +$finder = $this->container->get('foq_elastica.finder.website.article'); +$boolQuery = new \Elastica_Query_Bool(); + +$fieldQuery = new \Elastica_Query_Text(); +$fieldQuery->setFieldQuery('title', 'I am a title string'); +$fieldQuery->setFieldParam('title', 'analyzer', 'my_analyzer'); +$boolQuery->addShould($fieldQuery); + +$tagsQuery = new \Elastica_Query_Terms(); +$tagsQuery->setTerms('tags', array('tag1', 'tag2')); +$boolQuery->addShould($tagsQuery); + +$categoryQuery = new \Elastica_Query_Terms(); +$categoryQuery->setTerms('categoryIds', array('1', '2', '3')); +$boolQuery->addMust($categoryQuery); + +$data = $finder->find($boolQuery); +``` + +Configuration: + +```yaml +foq_elastica: + clients: + default: { host: localhost, port: 9200 } + indexes: + site: + settings: + index: + analysis: + analyzer: + my_analyzer: + type: snowball + language: English + types: + article: + mappings: + title: { boost: 10, analyzer: my_analyzer } + tags: + categoryIds: + persistence: + driver: orm + model: Acme\DemoBundle\Entity\Article + provider: + finder: +``` diff --git a/Transformer/ModelToElasticaAutoTransformer.php b/Transformer/ModelToElasticaAutoTransformer.php index e65d59d..1666beb 100644 --- a/Transformer/ModelToElasticaAutoTransformer.php +++ b/Transformer/ModelToElasticaAutoTransformer.php @@ -107,7 +107,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf $normalizeValue = function(&$v) { if ($v instanceof \DateTime) { - $v = (int)$v->format('U'); + $v = $v->format('v'); } elseif (!is_scalar($v) && !is_null($v)) { $v = (string)$v; }