From 14d2b825298e576caad5bfef4ba74520628aab17 Mon Sep 17 00:00:00 2001 From: topweb Date: Thu, 26 Jul 2012 13:12:48 +0300 Subject: [PATCH 1/3] Add advanced query example to README --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index 524c443..341ab36 100644 --- a/README.md +++ b/README.md @@ -548,3 +548,72 @@ class Client extends BaseClient } } ``` + + +

Example of Advanced Query

+If you would like to perform more advanced query here is an example, which is using the snowball stemming algorithm. + +It performs search against Article Entity by using title, tags +and categoryIds and return results if the search string is +found in either title or tags fields only in the specified +categoryIds. + +Note: When performing query with Elastica_Query_Terms considering the following: + +``` +Works: 'somestring' +Doesn't work: 'some string', 'some-string', 'SomeString' +``` + +```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: + + +``` +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: +``` + + From d3602e075be22dfce44cd4820a5ee69070495829 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 7 Mar 2013 17:10:54 -0500 Subject: [PATCH 2/3] Revise language for advanced query example --- README.md | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 341ab36..ed557be 100644 --- a/README.md +++ b/README.md @@ -549,24 +549,17 @@ class Client extends BaseClient } ``` +### Example of Advanced Query -

Example of Advanced Query

-If you would like to perform more advanced query here is an example, which is using the snowball stemming algorithm. +If you would like to perform more advanced queries, here is one example using +the snowball stemming algorithm. -It performs search against Article Entity by using title, tags -and categoryIds and return results if the search string is -found in either title or tags fields only in the specified -categoryIds. - -Note: When performing query with Elastica_Query_Terms considering the following: - -``` -Works: 'somestring' -Doesn't work: 'some string', 'some-string', 'SomeString' -``` +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(); @@ -580,20 +573,18 @@ $tagsQuery->setTerms('tags', array('tag1', 'tag2')); $boolQuery->addShould($tagsQuery); $categoryQuery = new \Elastica_Query_Terms(); -$categoryQuery->setTerms('categoryIds', array('1', '2', '3')); -$boolQuery->addMust($categoryQuery); +$categoryQuery->setTerms('categoryIds', array('1', '2', '3')); +$boolQuery->addMust($categoryQuery); $data = $finder->find($boolQuery); - ``` Configuration: - -``` +```yaml foq_elastica: clients: - default: { host: localhost, port: 9200 } + default: { host: localhost, port: 9200 } indexes: site: settings: @@ -607,13 +598,11 @@ foq_elastica: article: mappings: title: { boost: 10, analyzer: my_analyzer } - tags: + tags: categoryIds: persistence: - driver: orm + driver: orm model: Acme\DemoBundle\Entity\Article provider: finder: ``` - - From dd00409e85e2f3b17edc43cbd347f2d5be6dda76 Mon Sep 17 00:00:00 2001 From: Miha Vrhovnik Date: Thu, 7 Mar 2013 17:33:07 -0500 Subject: [PATCH 3/3] Normalize DateTime values as ISO 8601 strings --- Transformer/ModelToElasticaAutoTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transformer/ModelToElasticaAutoTransformer.php b/Transformer/ModelToElasticaAutoTransformer.php index 2fa0b5d..9e1a383 100644 --- a/Transformer/ModelToElasticaAutoTransformer.php +++ b/Transformer/ModelToElasticaAutoTransformer.php @@ -67,7 +67,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; }