-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
a31543b
commit 9ba7202
Showing
21 changed files
with
1,895 additions
and
2 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,63 @@ | ||
<?php | ||
|
||
namespace Nosto\Result\Graphql\Search; | ||
|
||
use Nosto\Result\Graphql\Search\SearchResult\Explain; | ||
use Nosto\Result\Graphql\Search\SearchResult\Products; | ||
use Nosto\Util\GraphQL; | ||
use stdClass; | ||
|
||
class SearchResult | ||
{ | ||
/** @var ?string */ | ||
private $redirect; | ||
|
||
/** @var ?string */ | ||
private $query; | ||
|
||
/** @var ?Explain */ | ||
private $explain; | ||
|
||
/** @var ?Products */ | ||
private $products; | ||
|
||
public function __construct(stdClass $data) | ||
{ | ||
$this->redirect = GraphQL::getProperty($data, 'redirect'); | ||
$this->query = GraphQL::getProperty($data, 'query'); | ||
$this->explain = GraphQL::getClassProperty($data, 'explain', Explain::class); | ||
$this->products = GraphQL::getClassProperty($data, 'products', Products::class); | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getRedirect() | ||
{ | ||
return $this->redirect; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getQuery() | ||
{ | ||
return $this->query; | ||
} | ||
|
||
/** | ||
* @return ?Explain | ||
*/ | ||
public function getExplain() | ||
{ | ||
return $this->explain; | ||
} | ||
|
||
/** | ||
* @return ?Products | ||
*/ | ||
public function getProducts() | ||
{ | ||
return $this->products; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Nosto\Result\Graphql\Search\SearchResult; | ||
|
||
use Nosto\Result\Graphql\Search\SearchResult\Explain\MatchedRule; | ||
use Nosto\Util\GraphQL; | ||
use stdClass; | ||
|
||
class Explain | ||
{ | ||
/** @var ?MatchedRule[] */ | ||
private $matchedRules; | ||
|
||
public function __construct(stdClass $data) | ||
{ | ||
$this->matchedRules = GraphQL::getArrayProperty($data, 'matchedRules', MatchedRule::class); | ||
} | ||
|
||
/** | ||
* @return ?MatchedRule[] | ||
*/ | ||
public function getMatchedRules() | ||
{ | ||
return $this->matchedRules; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Result/Graphql/Search/SearchResult/Explain/MatchedRule.php
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,49 @@ | ||
<?php | ||
|
||
namespace Nosto\Result\Graphql\Search\SearchResult\Explain; | ||
|
||
use Nosto\Util\GraphQL; | ||
use stdClass; | ||
|
||
class MatchedRule | ||
{ | ||
/** @var ?string */ | ||
private $id; | ||
|
||
/** @var ?string */ | ||
private $name; | ||
|
||
/** @var ?stdClass */ | ||
private $set; | ||
|
||
public function __construct(stdClass $data) | ||
{ | ||
$this->id = GraphQL::getProperty($data, 'id'); | ||
$this->name = GraphQL::getProperty($data, 'name'); | ||
$this->set = GraphQL::getProperty($data, 'set'); | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return ?stdClass | ||
*/ | ||
public function getSet() | ||
{ | ||
return $this->set; | ||
} | ||
} |
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,130 @@ | ||
<?php | ||
|
||
namespace Nosto\Result\Graphql\Search\SearchResult; | ||
|
||
use Nosto\Result\Graphql\Search\SearchResult\Products\Facet; | ||
use Nosto\Result\Graphql\Search\SearchResult\Products\Hit; | ||
use Nosto\Util\GraphQL; | ||
use stdClass; | ||
|
||
class Products | ||
{ | ||
/** @var ?int */ | ||
private $total; | ||
|
||
/** @var ?int */ | ||
private $size; | ||
|
||
/** @var ?int */ | ||
private $from; | ||
|
||
/** @var ?string */ | ||
private $collapse; | ||
|
||
/** @var ?boolean */ | ||
private $fuzzy; | ||
|
||
/** @var ?string */ | ||
private $categoryId; | ||
|
||
/** @var ?string */ | ||
private $categoryPath; | ||
|
||
/** @var ?Hit[] */ | ||
private $hits; | ||
|
||
/** @var ?Facet[] */ | ||
private $facets; | ||
|
||
public function __construct(stdClass $data) | ||
{ | ||
$this->total = GraphQL::getProperty($data, 'total'); | ||
$this->size = GraphQL::getProperty($data, 'size'); | ||
$this->from = GraphQL::getProperty($data, 'from'); | ||
$this->collapse = GraphQL::getProperty($data, 'collapse'); | ||
$this->fuzzy = GraphQL::getProperty($data, 'fuzzy'); | ||
$this->categoryId = GraphQL::getProperty($data, 'categoryId'); | ||
$this->categoryPath = GraphQL::getProperty($data, 'categoryPath'); | ||
$this->hits = GraphQL::getArrayProperty($data, 'hits', Hit::class); | ||
$this->facets = property_exists($data, 'facets') && $data->facets | ||
? array_map( | ||
function (stdClass $facet) { | ||
return Facet::getInstance($facet); | ||
}, | ||
$data->facets | ||
) | ||
: null; | ||
} | ||
|
||
/** | ||
* @return ?int | ||
*/ | ||
public function getTotal() | ||
{ | ||
return $this->total; | ||
} | ||
|
||
/** | ||
* @return ?int | ||
*/ | ||
public function getSize() | ||
{ | ||
return $this->size; | ||
} | ||
|
||
/** | ||
* @return ?int | ||
*/ | ||
public function getFrom() | ||
{ | ||
return $this->from; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getCollapse() | ||
{ | ||
return $this->collapse; | ||
} | ||
|
||
/** | ||
* @return ?bool | ||
*/ | ||
public function getFuzzy() | ||
{ | ||
return $this->fuzzy; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getCategoryId() | ||
{ | ||
return $this->categoryId; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getCategoryPath() | ||
{ | ||
return $this->categoryPath; | ||
} | ||
|
||
/** | ||
* @return ?Hit[] | ||
*/ | ||
public function getHits() | ||
{ | ||
return $this->hits; | ||
} | ||
|
||
/** | ||
* @return ?Facet[] | ||
*/ | ||
public function getFacets() | ||
{ | ||
return $this->facets; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Result/Graphql/Search/SearchResult/Products/BasicFacet.php
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,7 @@ | ||
<?php | ||
|
||
namespace Nosto\Result\Graphql\Search\SearchResult\Products; | ||
|
||
class BasicFacet extends Facet | ||
{ | ||
} |
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,82 @@ | ||
<?php | ||
|
||
namespace Nosto\Result\Graphql\Search\SearchResult\Products; | ||
|
||
use Exception; | ||
use Nosto\Util\GraphQL; | ||
use stdClass; | ||
|
||
abstract class Facet | ||
{ | ||
const STATS_TYPE = 'stats'; | ||
|
||
const TERMS_TYPE = 'terms'; | ||
|
||
/** @var ?string */ | ||
private $id; | ||
|
||
/** @var ?string */ | ||
private $name; | ||
|
||
/** @var ?string */ | ||
private $field; | ||
|
||
/** @var ?string */ | ||
private $type; | ||
|
||
public function __construct(stdClass $data) | ||
{ | ||
$this->id = GraphQL::getProperty($data, 'id'); | ||
$this->name = GraphQL::getProperty($data, 'name'); | ||
$this->field = GraphQL::getProperty($data, 'field'); | ||
$this->type = GraphQL::getProperty($data, 'type'); | ||
} | ||
|
||
/** | ||
* @return Facet | ||
* @throws Exception | ||
*/ | ||
public static function getInstance(stdClass $facet) | ||
{ | ||
switch ($facet->type) { | ||
case self::STATS_TYPE: | ||
return new StatsFacet($facet); | ||
case self::TERMS_TYPE: | ||
return new TermsFacet($facet); | ||
default: | ||
return new BasicFacet($facet); | ||
} | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getField() | ||
{ | ||
return $this->field; | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
} |
Oops, something went wrong.