-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8688e27
Showing
8 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
composer.lock export-ignore | ||
/Tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
/composer.phar | ||
/phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Alexander Schranz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Schranz Search SEAL Read Write Adapter | ||
|
||
The `ReadWriteAdapter` allows to use one adapter instance for reading | ||
and one for writing. This is useful if you want to reindex something | ||
without a downtime. | ||
|
||
> This is a subtree split of the `schranz-search/schranz-search` project create issues in the [main repository](https://github.com/schranz-search/schranz-search). | ||
## Usage | ||
|
||
To use the adapter an instance of `ReadWriteAdapter` need to be created | ||
which get a `$readAdapter` and `$writeAdapter` which are instances of the | ||
`AdapterInterface`. | ||
|
||
```php | ||
<?php | ||
|
||
use Schranz\Search\SEAL\Adapter\Elasticsearch\ElasticsearchAdapter; | ||
use Schranz\Search\SEAL\Adapter\ReadWrite\ReadWriteAdapter; | ||
use Schranz\Search\SEAL\Engine; | ||
|
||
$readAdapter = new ElasticsearchAdapter(/* .. */); // can be any adapter | ||
$writeAdapter = new ElasticsearchAdapter(/* .. */); // can be any adapter | ||
|
||
$engine = new Engine( | ||
new ReadWriteAdapter( | ||
$readAdapter, | ||
$writeAdapter | ||
), | ||
$schema, | ||
); | ||
``` | ||
|
||
> **Note** | ||
> Read a document and partial update it based on the read document should be avoided | ||
> when using this adapter, as the read document could already be outdated. So always | ||
> fully update the document and never do based on read documents. | ||
> Have a look at the `MultiAdapter` to write into read and write adapter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Schranz\Search\SEAL\Adapter\ReadWrite; | ||
|
||
use Schranz\Search\SEAL\Adapter\AdapterInterface; | ||
use Schranz\Search\SEAL\Adapter\ConnectionInterface; | ||
use Schranz\Search\SEAL\Adapter\SchemaManagerInterface; | ||
|
||
final class ReadWriteAdapter implements AdapterInterface | ||
{ | ||
private ?ConnectionInterface $connection = null; | ||
|
||
public function __construct( | ||
private readonly AdapterInterface $readAdapter, | ||
private readonly AdapterInterface $writeAdapter, | ||
) {} | ||
|
||
public function getSchemaManager(): SchemaManagerInterface | ||
{ | ||
return $this->writeAdapter->getSchemaManager(); | ||
} | ||
|
||
public function getConnection(): ConnectionInterface | ||
{ | ||
if ($this->connection === null) { | ||
$this->connection = new ReadWriteConnection( | ||
$this->readAdapter->getConnection(), | ||
$this->writeAdapter->getConnection(), | ||
); | ||
} | ||
|
||
return $this->connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Schranz\Search\SEAL\Adapter\ReadWrite; | ||
|
||
use Schranz\Search\SEAL\Adapter\ConnectionInterface; | ||
use Schranz\Search\SEAL\Schema\Index; | ||
use Schranz\Search\SEAL\Search\Result; | ||
use Schranz\Search\SEAL\Search\Search; | ||
|
||
/** | ||
* @internal This class should never be needed to be instanced manually. | ||
*/ | ||
final class ReadWriteConnection implements ConnectionInterface | ||
{ | ||
public function __construct( | ||
public readonly ConnectionInterface $readConnection, | ||
public readonly ConnectionInterface $writeConnection, | ||
) {} | ||
|
||
public function save(Index $index, array $document): array | ||
{ | ||
return $this->writeConnection->save($index, $document); | ||
} | ||
|
||
public function delete(Index $index, string $identifier): void | ||
{ | ||
$this->writeConnection->delete($index, $identifier); | ||
} | ||
|
||
public function search(Search $search): Result | ||
{ | ||
return $this->readConnection->search($search); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "schranz-search/seal-read-write-adapter", | ||
"description": "An adapter to support to split read and write operations for the schranz-search/seal package.", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Schranz\\Search\\SEAL\\Adapter\\ReadWrite\\": "" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Alexander Schranz", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"schranz-search/seal": "^0.1" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "./../seal", | ||
"options": { | ||
"symlink": true | ||
} | ||
} | ||
], | ||
"minimum-stability": "dev" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.