Merge branch '2.0'

Conflicts:
	Transformer/ModelToElasticaAutoTransformer.php
This commit is contained in:
Jeremy Mikola 2013-03-07 17:38:42 -05:00
commit 8f5f12315d
2 changed files with 59 additions and 1 deletions

View file

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

View file

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