Skip to content

Commit

Permalink
Merge branch '0.6' into fix/windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo authored Oct 26, 2024
2 parents c2f2872 + 2feaf7c commit b105524
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 54 deletions.
15 changes: 6 additions & 9 deletions docs/cookbooks/create-own-adapter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,12 @@ Search Engine to Search Engine. A common way is the following example:
{
// optimized single document query
if (
1 === \count($search->indexes)
&& 1 === \count($search->filters)
1 === \count($search->filters)
&& $search->filters[0] instanceof Condition\IdentifierCondition
&& 0 === $search->offset
&& 1 === $search->limit
) {
$singleDocumentIndexName = $search->indexes[\array_key_first($search->indexes)]->name;
$singleDocumentIndexName = $search->index->name;
$singleDocumentIdentifier = $search->filters[0]->identifier;
try {
Expand All @@ -541,13 +540,13 @@ Search Engine to Search Engine. A common way is the following example:
}
return new Result(
$this->hitsToDocuments($search->indexes, []),
$this->hitsToDocuments($search->index, []),
0,
);
}
return new Result(
$this->hitsToDocuments($search->indexes, [$data]),
$this->hitsToDocuments($search->index, [$data]),
1,
);
}
Expand All @@ -556,15 +555,13 @@ Search Engine to Search Engine. A common way is the following example:
}
/**
* @param Index[] $indexes
* @param Index $index
* @param iterable<array<string, mixed>> $hits
*
* @return \Generator<int, array<string, mixed>>
*/
private function hitsToDocuments(array $indexes, iterable $hits): \Generator
private function hitsToDocuments(Index $index, iterable $hits): \Generator
{
$index = $indexes[\array_key_first($indexes)];
foreach ($hits as $hit) {
yield $this->marshaller->unmarshall($index->fields, $hit);
}
Expand Down
6 changes: 2 additions & 4 deletions docs/getting-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,7 @@ many exists in the given index.
public function someMethod()
{
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new \Schranz\Search\SEAL\Search\Condition\SearchCondition('first'))
->getResult();
Expand Down Expand Up @@ -1876,8 +1875,7 @@ we will filter by the ``tags`` field and get all documents which have the tag ``
public function someMethod()
{
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new \Schranz\Search\SEAL\Search\Condition\EqualCondition('tags', 'UI'));
->getResult();
Expand Down
61 changes: 20 additions & 41 deletions docs/search-and-filters/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ The following shows the basic usage as already shown in the "Getting Started" do
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(/* ... */)
->getResult();
Expand All @@ -29,9 +28,7 @@ The following shows the basic usage as already shown in the "Getting Started" do
.. note::

Currently only the ``Elasticsearch`` and ``Opensearch`` adapters supports to search on
multiple indexes at once. The other adapters are not yet supporting to call ``addIndex``
multiple times and will fail so with an exception if you try to do so.
It is also possible to change the index after creating the searchbuilder via ``$searchBuilder->index('other')``.

Conditions
----------
Expand All @@ -47,8 +44,7 @@ The ``SearchCondition`` is the most basic condition and can be used to search fo
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\SearchCondition('Search Term'))
->getResult();
Expand All @@ -65,8 +61,7 @@ The ``EqualCondition`` is used to filter the result by a specific field value ma
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\EqualCondition('tags', 'UI'))
->getResult();
Expand All @@ -84,8 +79,7 @@ The ``NotEqualCondition`` is used to filter the result by a specific field value
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\NotEqualCondition('tags', 'UI'))
->getResult();
Expand All @@ -105,8 +99,7 @@ then using a ``EqualCondition``.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\IdentifierCondition('23b30f01-d8fd-4dca-b36a-4710e360a965'))
->getResult();
Expand All @@ -122,8 +115,7 @@ the given value.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\GreaterThanCondition('rating', 2.5))
->getResult();
Expand All @@ -141,8 +133,7 @@ the given value.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\GreaterThanEqualCondition('rating', 2.5))
->getResult();
Expand All @@ -160,8 +151,7 @@ the given value.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\LessThanCondition('rating', 2.5))
->getResult();
Expand All @@ -179,8 +169,7 @@ the given value.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\LessThanEqualCondition('rating', 2.5))
->getResult();
Expand All @@ -197,8 +186,7 @@ The ``GeoDistanceCondition`` is used to filter results within a radius by specif
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('restaurants')
$result = $this->engine->createSearchBuilder('restaurants')
->addFilter(new Condition\GeoDistanceCondition('location', 45.472735, 9.184019, 2000))
->getResult();
Expand All @@ -215,8 +203,7 @@ The ``GeoBoundingBoxCondition`` is used to filter results within a bounding box
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('restaurants')
$result = $this->engine->createSearchBuilder('restaurants')
->addFilter(new Condition\GeoBoundingBoxCondition('location', 45.494181, 9.214024, 45.449484, 9.179175))
->getResult();
Expand All @@ -239,8 +226,7 @@ The ``OrCondition`` is used to filter by two or more conditions where at least o
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\OrCondition(
new Condition\GreaterThanCondition('rating', 2.5),
new Condition\EqualCondition('isSpecial', true),
Expand All @@ -262,8 +248,7 @@ in combination with ``OrCondition`` filters.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\AndCondition(
new Condition\EqualCondition('tags', 'Tech'),
new Condition\OrCondition(
Expand Down Expand Up @@ -307,8 +292,7 @@ Need to be queried this way `<object>.<field>`:
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\LessThanEqualCondition('rating.value', 2.5))
->getResult();
Expand All @@ -335,8 +319,7 @@ Need to be queried this way `<object>.<type>.<field>`:
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(new Condition\EqualCondition('header.image.media', 21))
->getResult();
Expand All @@ -353,8 +336,7 @@ Beside the searches and filters you can also limit the result by a given ``limit
<?php
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(/* ... */)
->limit(10)
->offset(20)
Expand All @@ -369,8 +351,7 @@ With the ``limit`` and ``offset`` also a basic pagination can be created this wa
$page = 1; // get from query parameter
$pageSize = 10;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addFilter(/* ... */)
->limit($pageSize)
->offset(($page - 1) * $pageSize)
Expand All @@ -397,8 +378,7 @@ your results but also ``sort`` them by a given field.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addSortBy('rating', 'desc')
->getResult();
Expand All @@ -408,8 +388,7 @@ your results but also ``sort`` them by a given field.
use Schranz\Search\SEAL\Search\Condition;
$result = $this->engine->createSearchBuilder()
->addIndex('blog')
$result = $this->engine->createSearchBuilder('blog')
->addSortBy('rating', 'asc')
->getResult();
Expand Down

0 comments on commit b105524

Please sign in to comment.