Skip to content

Commit

Permalink
Introduce Document suffix for Elasticsearch models
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Jun 8, 2017
1 parent ad51be3 commit 2508365
Show file tree
Hide file tree
Showing 27 changed files with 136 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace spec\Sylius\ElasticSearchPlugin\Document;

use Sylius\ElasticSearchPlugin\Document\Attribute;
use Sylius\ElasticSearchPlugin\Document\AttributeDocument;
use PhpSpec\ObjectBehavior;

final class AttributeSpec extends ObjectBehavior
final class AttributeDocumentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Attribute::class);
$this->shouldHaveType(AttributeDocument::class);
}

function it_has_code()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace spec\Sylius\ElasticSearchPlugin\Document;

use Sylius\ElasticSearchPlugin\Document\Attribute;
use Sylius\ElasticSearchPlugin\Document\AttributeValue;
use Sylius\ElasticSearchPlugin\Document\AttributeDocument;
use Sylius\ElasticSearchPlugin\Document\AttributeValueDocument;
use PhpSpec\ObjectBehavior;

final class AttributeValueSpec extends ObjectBehavior
final class AttributeValueDocumentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(AttributeValue::class);
$this->shouldHaveType(AttributeValueDocument::class);
}

function it_has_value()
Expand All @@ -22,7 +22,7 @@ function it_has_value()

function it_has_attribute()
{
$attribute = new Attribute();
$attribute = new AttributeDocument();
$this->setAttribute($attribute);

$this->getAttribute()->shouldReturn($attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace spec\Sylius\ElasticSearchPlugin\Document;

use Sylius\ElasticSearchPlugin\Document\Image;
use Sylius\ElasticSearchPlugin\Document\ImageDocument;
use PhpSpec\ObjectBehavior;

final class ImageSpec extends ObjectBehavior
final class ImageDocumentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Image::class);
$this->shouldHaveType(ImageDocument::class);
}

function it_has_code()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace spec\Sylius\ElasticSearchPlugin\Document;

use Sylius\ElasticSearchPlugin\Document\Price;
use Sylius\ElasticSearchPlugin\Document\PriceDocument;
use PhpSpec\ObjectBehavior;

final class PriceSpec extends ObjectBehavior
final class PriceDocumentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Price::class);
$this->shouldHaveType(PriceDocument::class);
}

function it_has_amount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace spec\Sylius\ElasticSearchPlugin\Document;

use ONGR\ElasticsearchBundle\Collection\Collection;
use Sylius\ElasticSearchPlugin\Document\Price;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\PriceDocument;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use PhpSpec\ObjectBehavior;
use Sylius\ElasticSearchPlugin\Document\Taxon;
use Sylius\ElasticSearchPlugin\Document\TaxonDocument;

final class ProductSpec extends ObjectBehavior
final class ProductDocumentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Product::class);
$this->shouldHaveType(ProductDocument::class);
}

function it_has_code()
Expand Down Expand Up @@ -52,15 +52,15 @@ function it_has_description()

function it_has_price()
{
$price = new Price();
$price = new PriceDocument();
$this->setPrice($price);

$this->getPrice()->shouldReturn($price);
}

function it_has_main_taxon()
{
$taxon = new Taxon();
$taxon = new TaxonDocument();
$this->setMainTaxon($taxon);

$this->getMainTaxon()->shouldReturn($taxon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace spec\Sylius\ElasticSearchPlugin\Document;

use ONGR\ElasticsearchBundle\Collection\Collection;
use Sylius\ElasticSearchPlugin\Document\Taxon;
use Sylius\ElasticSearchPlugin\Document\TaxonDocument;
use PhpSpec\ObjectBehavior;

final class TaxonSpec extends ObjectBehavior
final class TaxonDocumentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Taxon::class);
$this->shouldHaveType(TaxonDocument::class);
}

function it_has_code()
Expand Down
14 changes: 7 additions & 7 deletions spec/Projection/ProductProjectorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Event\ProductCreated;
use Sylius\ElasticSearchPlugin\Factory\ProductFactoryInterface;
use Sylius\ElasticSearchPlugin\Factory\ProductDocumentFactoryInterface;
use Sylius\ElasticSearchPlugin\Projection\ProductProjector;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

final class ProductProjectorSpec extends ObjectBehavior
{
function let(Manager $manager, ProductFactoryInterface $factory)
function let(Manager $manager, ProductDocumentFactoryInterface $factory)
{
$this->beConstructedWith($manager, $factory);
}
Expand All @@ -28,15 +28,15 @@ function it_is_initializable()

function it_saves_product_document_if_product_has_channel_defined(
Manager $manager,
ProductFactoryInterface $factory,
ProductDocumentFactoryInterface $factory,
ProductInterface $product,
LocaleInterface $locale,
ChannelInterface $channel
) {
$channel->getLocales()->willReturn(new ArrayCollection([$locale->getWrappedObject()]));
$product->getChannels()->willReturn(new ArrayCollection([$channel->getWrappedObject()]));

$productDocument = new Product();
$productDocument = new ProductDocument();
$factory->createFromSyliusSimpleProductModel($product, $locale, $channel)->willReturn($productDocument);

$manager->persist($productDocument)->shouldBeCalled();
Expand All @@ -47,7 +47,7 @@ function it_saves_product_document_if_product_has_channel_defined(

function it_does_not_save_product_document_if_product_has_not_channel_defined(
Manager $manager,
ProductFactoryInterface $factory,
ProductDocumentFactoryInterface $factory,
ProductInterface $product
) {
$product->getChannels()->willReturn(new ArrayCollection([]));
Expand All @@ -61,7 +61,7 @@ function it_does_not_save_product_document_if_product_has_not_channel_defined(

function it_does_not_save_product_document_if_channel_has_not_locales_defined(
Manager $manager,
ProductFactoryInterface $factory,
ProductDocumentFactoryInterface $factory,
ProductInterface $product,
ChannelInterface $channel
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery;
use ONGR\ElasticsearchDSL\Query\Joining\NestedQuery;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria;
use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInChannelFilter;
use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Filter\ProductInChannelApplicator;
Expand Down Expand Up @@ -38,7 +38,7 @@ function it_applies_search_criteria_with_channel_code(
Search $search,
NestedQuery $nestedQuery
) {
$criteria = Criteria::fromQueryParameters(Product::class, ['channel_code' => 'web']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['channel_code' => 'web']);
$productInChannelQueryFactory->create($criteria->filtering()->fields())->willReturn($nestedQuery);
$search->addPostFilter($nestedQuery, BoolQuery::MUST)->shouldBeCalled();

Expand All @@ -47,11 +47,11 @@ function it_applies_search_criteria_with_channel_code(

function it_supports_channel_code_parameter()
{
$criteria = Criteria::fromQueryParameters(Product::class, ['channel_code' => 'web']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['channel_code' => 'web']);

$this->supports($criteria)->shouldReturn(true);

$criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => 'tree']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => 'tree']);

$this->supports($criteria)->shouldReturn(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery;
use ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria;
use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInPriceRangeFilter;
use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Filter\ProductInPriceRangeApplicator;
Expand Down Expand Up @@ -35,7 +35,7 @@ function it_is_search_criteria_applicator()

function it_applies_search_criteria_for_given_query(QueryFactoryInterface $productInPriceRangeQueryFactory, Search $search, TermQuery $termQuery)
{
$criteria = Criteria::fromQueryParameters(Product::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]);
$productInPriceRangeQueryFactory->create($criteria->filtering()->fields())->willReturn($termQuery);
$search->addPostFilter($termQuery, BoolQuery::MUST)->shouldBeCalled();

Expand All @@ -44,10 +44,10 @@ function it_applies_search_criteria_for_given_query(QueryFactoryInterface $produ

function it_supports_product_price_range_parameter()
{
$criteria = Criteria::fromQueryParameters(Product::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]);
$this->supports($criteria)->shouldReturn(true);

$criteria = Criteria::fromQueryParameters(Product::class, []);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, []);
$this->supports($criteria)->shouldReturn(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery;
use ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria;
use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInTaxonFilter;
use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Filter\ProductInTaxonApplicator;
Expand Down Expand Up @@ -38,7 +38,7 @@ function it_applies_search_query_for_given_criteria(
TermQuery $termQuery,
Search $search
) {
$criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => 'mugs']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => 'mugs']);

$productInMainTaxon->create($criteria->filtering()->fields())->willReturn($termQuery);

Expand All @@ -49,10 +49,10 @@ function it_applies_search_query_for_given_criteria(

function it_supports_taxon_code_paramter()
{
$criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => 'mugs']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => 'mugs']);
$this->supports($criteria)->shouldReturn(true);

$criteria = Criteria::fromQueryParameters(Product::class, []);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, []);
$this->supports($criteria)->shouldReturn(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace spec\Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Query;

use ONGR\ElasticsearchDSL\Query\FullText\MatchQuery;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria;
use Sylius\ElasticSearchPlugin\Search\Criteria\SearchPhrase;
use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Query\MatchProductByNameApplicator;
Expand Down Expand Up @@ -38,7 +38,7 @@ function it_applies_match_product_by_name_query(
MatchQuery $matchQuery,
Search $search
) {
$criteria = Criteria::fromQueryParameters(Product::class, ['search' => 'banana']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['search' => 'banana']);
$matchProductNameQueryFactory->create($criteria->filtering()->fields())->willReturn($matchQuery);
$search->addQuery($matchQuery)->shouldBeCalled();

Expand All @@ -47,10 +47,10 @@ function it_applies_match_product_by_name_query(

function it_supports_search_parameter()
{
$criteria = Criteria::fromQueryParameters(Product::class, ['search' => 'banana']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['search' => 'banana']);
$this->supports($criteria)->shouldReturn(true);

$criteria = Criteria::fromQueryParameters(Product::class, []);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, []);
$this->supports($criteria)->shouldReturn(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace spec\Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Sort;

use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria;
use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\SearchCriteriaApplicatorInterface;
use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Sort\SortByFieldApplicator;
Expand Down Expand Up @@ -36,7 +36,7 @@ function it_applies_sort_query_to_search_with_given_sorting(
Search $search,
FieldSort $fieldSort
) {
$criteria = Criteria::fromQueryParameters(Product::class, ['sort' => '-name']);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, ['sort' => '-name']);
$sortByFieldSortFactory->create($criteria->ordering())->willReturn($fieldSort);
$search->addSort($fieldSort)->shouldBeCalled();

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\ElasticSearchPlugin\Document\Product;
use Sylius\ElasticSearchPlugin\Document\ProductDocument;
use Sylius\ElasticSearchPlugin\Factory\ProductListViewFactoryInterface;
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria;
use Sylius\ElasticSearchPlugin\Search\SearchEngineInterface;
Expand Down Expand Up @@ -65,7 +65,7 @@ public function __invoke(Request $request)
$content = $request->query->all();
}

$criteria = Criteria::fromQueryParameters(Product::class, $content);
$criteria = Criteria::fromQueryParameters(ProductDocument::class, $content);

$result = $this->searchEngine->match($criteria);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @ElasticSearch\Object
*/
final class Attribute
final class AttributeDocument
{
/**
* @var string
Expand Down
Loading

0 comments on commit 2508365

Please sign in to comment.