Add advanced query example to README

This commit is contained in:
topweb 2012-07-26 13:12:48 +03:00 committed by Jeremy Mikola
parent 51f03ebbc3
commit 14d2b82529

View file

@ -548,3 +548,72 @@ class Client extends BaseClient
}
}
```
<h3>Example of Advanced Query</h3>
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:
```