Skip to content

Commit

Permalink
[Search] New Component and Contract
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Nov 30, 2023
1 parent 4219657 commit 8ab268a
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 8 deletions.
8 changes: 8 additions & 0 deletions bard.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@
"path": "src/SonsOfPHP/Contract/Pager",
"repository": "[email protected]:SonsOfPHP/pager-contract.git"
},
{
"path": "src/SonsOfPHP/Component/Search",
"repository": "[email protected]:SonsOfPHP/search.git"
},
{
"path": "src/SonsOfPHP/Contract/Search",
"repository": "[email protected]:SonsOfPHP/search-contract.git"
},
{
"path": "src/SonsOfPHP/Contract/Version",
"repository": "[email protected]:SonsOfPHP/version-contract.git"
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"psr/log-implementation": "^1.0 || ^2.0 || ^3.0",
"sonsofphp/logger-implementation": "0.3.x-dev",
"sonsofphp/pager-implementation": "0.3.x-dev",
"psr/link-implementation": "^1.0 || ^2.0"
"psr/link-implementation": "^1.0 || ^2.0",
"sonsofphp/search-implementation": "0.3.x-dev"
},
"require": {
"php": ">=8.1",
Expand Down Expand Up @@ -110,7 +111,9 @@
"sonsofphp/money-twig": "self.version",
"sonsofphp/pager-doctrine-collections": "self.version",
"sonsofphp/pager-doctrine-dbal": "self.version",
"sonsofphp/pager-doctrine-orm": "self.version"
"sonsofphp/pager-doctrine-orm": "self.version",
"sonsofphp/search-contract": "self.version",
"sonsofphp/search": "self.version"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -146,6 +149,8 @@
"SonsOfPHP\\Contract\\Logger\\": "src/SonsOfPHP/Contract/Logger",
"SonsOfPHP\\Contract\\Money\\": "src/SonsOfPHP/Contract/Money",
"SonsOfPHP\\Contract\\Pager\\": "src/SonsOfPHP/Contract/Pager",
"SonsOfPHP\\Component\\Search\\": "src/SonsOfPHP/Component/Search",
"SonsOfPHP\\Contract\\Search\\": "src/SonsOfPHP/Contract/Search",
"SonsOfPHP\\Contract\\Version\\": "src/SonsOfPHP/Contract/Version"
},
"exclude-from-classmap": [
Expand All @@ -172,7 +177,8 @@
"src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/Tests",
"src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/Tests",
"src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/Tests",
"src/SonsOfPHP/Component/Version/Tests"
"src/SonsOfPHP/Component/Version/Tests",
"src/SonsOfPHP/Component/Search/Tests"
]
},
"extra": {
Expand Down
28 changes: 28 additions & 0 deletions docs/components/search/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Search
description: Abstract PHP Search Library that supports many different backends
---

## Installation

```shell
composer require sonsofphp/search
```

## Usage

```php
<?php

use SonsOfPHP\Component\Search\Backend\ElasticBackend;
use SonsOfPHP\Component\Search\Search;
use SonsOfPHP\Component\Search\Query;

$search = new Search(new ElasticBackend(/*...*/));
$query = new Query();
// ...
$pager = $search->query($query); // @var \SonsOfPHP\Contract\Pager\PagerInterface
foreach ($pager as $result) {
// ...
}
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ nav:
- Operators: components/money/operators.md
- Queries: components/money/queries.md
- Pager: components/pager/index.md
- Search: components/search/index.md
- Version: components/version/index.md
- Contracts:
- contracts/index.md
Expand Down
10 changes: 5 additions & 5 deletions src/SonsOfPHP/Component/Pager/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Sons of PHP - Logger
====================
Sons of PHP - Pager
===================

## Learn More

Expand All @@ -11,6 +11,6 @@ Sons of PHP - Logger
[discussions]: https://github.com/orgs/SonsOfPHP/discussions
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
[contributing]: https://docs.sonsofphp.com/contributing/
[docs]: https://docs.sonsofphp.com/components/logger/
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ALogger
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ALogger
[docs]: https://docs.sonsofphp.com/components/pager/
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3APager
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3APager
4 changes: 4 additions & 0 deletions src/SonsOfPHP/Component/Search/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
3 changes: 3 additions & 0 deletions src/SonsOfPHP/Component/Search/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
phpunit.xml
vendor/
19 changes: 19 additions & 0 deletions src/SonsOfPHP/Component/Search/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2022 to Present Joshua Estes

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.
14 changes: 14 additions & 0 deletions src/SonsOfPHP/Component/Search/Query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Component\Search;

use SonsOfPHP\Contract\Search\QueryInterface;

/**
* @author Joshua Estes <[email protected]>
*/
class Query implements QueryInterface, \ArrayAccess, \JsonSerializable
{
}
16 changes: 16 additions & 0 deletions src/SonsOfPHP/Component/Search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Sons of PHP - Search
====================

## Learn More

* [Documentation][docs]
* [Contributing][contributing]
* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo]
* Get Help & Support using [Discussions][discussions]

[discussions]: https://github.com/orgs/SonsOfPHP/discussions
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
[contributing]: https://docs.sonsofphp.com/contributing/
[docs]: https://docs.sonsofphp.com/components/search/
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ASearch
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ASearch
55 changes: 55 additions & 0 deletions src/SonsOfPHP/Component/Search/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "sonsofphp/search",
"type": "library",
"description": "",
"keywords": [
"search"
],
"homepage": "https://github.com/SonsOfPHP/search",
"license": "MIT",
"authors": [
{
"name": "Joshua Estes",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/SonsOfPHP/sonsofphp/issues",
"forum": "https://github.com/orgs/SonsOfPHP/discussions",
"docs": "https://docs.sonsofphp.com"
},
"autoload": {
"psr-4": {
"SonsOfPHP\\Component\\Search\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"sonsofphp/pager": "0.3.x-dev",
"sonsofphp/search-contract": "0.3.x-dev"
},
"provide": {
"sonsofphp/search-implementation": "0.3.x-dev"
},
"extra": {
"sort-packages": true,
"branch-alias": {
"dev-main": "0.3.x-dev"
}
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/JoshuaEstes"
},
{
"type": "tidelift",
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
}
]
}
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Contract/Search/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.gitattributes export-ignore
/.gitignore export-ignore
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Contract/Search/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor/
18 changes: 18 additions & 0 deletions src/SonsOfPHP/Contract/Search/BackendInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Contract\Search;

/**
* @author Joshua Estes <[email protected]>
*/
interface BackendInterface
{
public function indexDocument(mixed $document): void;
public function updateDocument(mixed $document): void;
public function deleteDocument(mixed $document): void;
public function getDocument(mixed $document): void;

public function query(string $index, QueryInterface $query): iterable;
}
19 changes: 19 additions & 0 deletions src/SonsOfPHP/Contract/Search/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2022 to Present Joshua Estes

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.
17 changes: 17 additions & 0 deletions src/SonsOfPHP/Contract/Search/QueryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Contract\Search;

/**
* @author Joshua Estes <[email protected]>
*/
interface QueryInterface// extends \ArrayAccess, \JsonSerializable
{
public function get(string $field): self;
public function set(string $field, mixed $value): self;

public function getOffset(): int;
public function getLength(): ?int;
}
16 changes: 16 additions & 0 deletions src/SonsOfPHP/Contract/Search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Sons of PHP - Search Contract
=============================

## Learn More

* [Documentation][docs]
* [Contributing][contributing]
* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo]
* Get Help & Support using [Discussions][discussions]

[discussions]: https://github.com/orgs/SonsOfPHP/discussions
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
[contributing]: https://docs.sonsofphp.com/contributing/
[docs]: https://docs.sonsofphp.com/contracts/search/
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ASearch
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ASearch
10 changes: 10 additions & 0 deletions src/SonsOfPHP/Contract/Search/SearchExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Contract\Search;

/**
* @author Joshua Estes <[email protected]>
*/
interface SearchExceptionInterface {}
15 changes: 15 additions & 0 deletions src/SonsOfPHP/Contract/Search/SearchInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Contract\Search;

/**
* @author Joshua Estes <[email protected]>
*/
interface SearchInterface
{
public function getBackend(): BackendInterface;

public function query(QueryInterface $query): iterable;
}
53 changes: 53 additions & 0 deletions src/SonsOfPHP/Contract/Search/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "sonsofphp/search-contract",
"type": "library",
"description": "",
"keywords": [
"abstractions",
"contracts",
"decoupling",
"interfaces",
"interoperability",
"standards"
],
"homepage": "https://github.com/SonsOfPHP/search-contract",
"license": "MIT",
"authors": [
{
"name": "Joshua Estes",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/SonsOfPHP/sonsofphp/issues",
"forum": "https://github.com/orgs/SonsOfPHP/discussions",
"docs": "https://docs.sonsofphp.com"
},
"autoload": {
"psr-4": {
"SonsOfPHP\\Contract\\Search\\": ""
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"sonsofphp/pager-contract": "0.3.x-dev"
},
"extra": {
"sort-packages": true,
"branch-alias": {
"dev-main": "0.3.x-dev"
}
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/JoshuaEstes"
},
{
"type": "tidelift",
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
}
]
}

0 comments on commit 8ab268a

Please sign in to comment.