Skip to content

Commit

Permalink
Update docs to include dotted notation.
Browse files Browse the repository at this point in the history
This makes them much more readable as well.
  • Loading branch information
dieterve committed Sep 11, 2015
1 parent aff13fd commit 82992a2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 64 deletions.
37 changes: 14 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ class MoviesFrom2014Query extends AbstractQuery
{
$this->searchIn('movies', 'movies');

$body = array(
'query' => array(
'filtered' => array(
'filter' => array(
'term' => array(
'year' => 2014
)
)
)
)
);

// Full notation
$body = [
'query' => [
'filtered' => [
'filter' => [
'term' => ['year' => 2014]
]
]
]
];
$this->setBody($body);

// Short (dotted) notation
$this->set('query.filtered.filter.term.year', 2014);
}
}

Expand All @@ -58,17 +59,7 @@ class MoviesFrom2014Query extends AbstractQuery
{
$this->searchIn('movies', 'movies');

$body = array(
'query' => array(
'filtered' => array(
'filter' => array(
new YearFilter(2014)
)
)
)
);

$this->setBody($body);
$this->set('query.filtered.filter', [new YearFilter(2014)]);
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/index-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ $suggestionsIndex = new SuggestionsIndex();
$searcher->indicesManager()->register($suggestionsIndex);

// Grouped registration
$indices = array(
$indices = [
$suggestionsIndex
);
];
$searcher->indicesManager()->registerIndices($indices);

// Other
Expand Down
46 changes: 18 additions & 28 deletions docs/query-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ var_dump($result->getResults());

## Body building

Inside your Query class you can build the body of the query however you like. We only require you to call `setBody` with
the body array. Here are some examples.
Inside your Query class you can build the body of the query however you like. A query is
[body aware](https://github.com/madewithlove/elasticsearcher/tree/master/src/Traits/BodyTrait.php)
for easy manipulation. Here are some examples.

Basic example:

Expand All @@ -45,19 +46,20 @@ class MoviesYouMightLikeQuery extends QueryAbstract
{
$this->searchIn('suggestions', 'movies');

$body = array(
'query' => array(
'filtered' => array(
'filter' => array(
'term' => array(
'status' => 'active'
)
)
)
)
);

$this->setBody($body);
// Long notation
$body = [
'query' => [
'filtered' => [
'filter' => [
'term' => ['status' => 'active']
]
]
]
];
$this->setBody($body);

// Short dotted notation
$this->set('query.filtered.filter.term.status', 'active');
}
}
```
Expand All @@ -73,19 +75,7 @@ class MoviesYouMightLikeQuery extends AbstractQuery
{
$this->searchIn('suggestions', 'movies');

$body = array(
'query' => array(
'filtered' => array(
'filter' => array(
'term' => array(
'status' => $this->getData('status')
)
)
)
)
);

$this->setBody($body);
$this->set('query.filtered.filter.term.status', $this->getData('status'));
}
}
```
Expand Down
3 changes: 3 additions & 0 deletions docs/re-useable-fragments.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ comes with a build-in set of fragments but you are encouraged to build your own.
For example: `BookingRangeFilter(date, date)`, `MovieIDFilter(int)`, .... As long as they extend
`ElasticSearcher\Abstracts\AbstractFragment` they can be used in queries or indices.

A fragment is [body aware](https://github.com/madewithlove/elasticsearcher/tree/master/src/Traits/BodyTrait.php)
for easy manipulation.

## Examples

```php
Expand Down
12 changes: 1 addition & 11 deletions tests/dummy/Queries/MoviesFrom2014Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ public function setup()
{
$this->searchIn('movies', 'movies');

$body = array(
'query' => array(
'filtered' => array(
'filter' => array(
new TermFilter('year', 2014)
)
)
)
);

$this->setBody($body);
$this->set('query.filtered.filter', [new TermFilter('year', 2014)]);
}
}

0 comments on commit 82992a2

Please sign in to comment.