From 00f37835fc554e976710482be5d811e9c791ccc1 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 16 Jul 2013 13:33:21 -0400 Subject: [PATCH] Rewrite filtered query example in README Cleaning up the description paragraph and removing extra fields and pagination from the example, since we already have pagination examples elsewhere in the README. --- README.md | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2c1aef2..ccae8db 100644 --- a/README.md +++ b/README.md @@ -755,31 +755,19 @@ fos_elastica: finder: ``` -### Filtering Results and executing a default query +### Filtering Results and Executing a Default Query -You may want to remove a certain section of results from a query, filtering is ideal because it is slightly faster in performance compared to a standard query because the only the filtered subset of results are cached. This improves query speed because the query is ran against the predetermined subset from previous queries rather than recalculating the whole query again. Filtering can effectively when trying to look for only active records which are indicated by a field in the database. `FilteredQuery` should be used to combine the `QueryString` operator with the `Filter`, an example of `FilteredQuery` is shown Below. +If may want to omit certain results from a query, filtering can be more +performant than a basic query because the filter results can be cached. In turn, +the query is run against only a subset of the results. A common use case for +filtering would be if your data has fields that indicate whether records are +"active" or "inactive". The following example illustrates how to issue such a +query with Elastica: ```php -$term = new \Elastica\Filter\Term(); -$term->setParams(array( - 'active' => 'active', - 'address.postCode' => $postCode //Accessing elements nested within an object. address is the object and postCode is the property within it. - 'companyGroup' => $department - )); - -$query = new \Elastica\Query\QueryString(); -$query->setQuery($queryString); +$query = new \Elastica\Query\QueryString($queryString); +$term = new \Elastica\Filter\Term(array('active' => true)); $filteredQuery = new \Elastica\Query\Filtered($query, $term); - -$results = $this->container->get('fos_elastica.finder.company.company')->findPaginated($filteredQuery); - -// Filter results for paging -$results->setMaxPerPage($limit); -$results->setCurrentPage($page); - -// Number of total results for paging -$total = $results->getNbResults(); - +$results = $this->container->get('fos_elastica.finder.index.type')->find($filteredQuery); ``` -