Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-288: ES refactor #245

Merged
merged 35 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
44bfeca
OP-225: Add Docker support
GracjanJozefczyk May 23, 2024
2fa4ad2
OP-225: Replace Sonata with Sylius event
GracjanJozefczyk May 26, 2024
602191b
OP-225: Refactor shop controllers
GracjanJozefczyk May 27, 2024
fc536d0
OP-225: Fix mobile toggles
GracjanJozefczyk May 27, 2024
5adac26
OP-225: Refactor shop controllers
GracjanJozefczyk May 27, 2024
5b5880f
OP-225: Refactor query builders
GracjanJozefczyk May 27, 2024
c60e05c
OP-225: Refactor forms
GracjanJozefczyk May 27, 2024
80bdbda
OP-225: Custom data handlers
GracjanJozefczyk May 27, 2024
b03f674
OP-225: Facets resolver
GracjanJozefczyk May 27, 2024
54e54af
OP-225: Facets autodiscovery
GracjanJozefczyk May 27, 2024
8f33358
OP-225: Change elastic url
GracjanJozefczyk May 27, 2024
5d9082e
OP-225: PHP 8 constructors
GracjanJozefczyk May 27, 2024
bb813ca
OP-225: Apply ECS
GracjanJozefczyk May 27, 2024
9425502
OP-225: Unit tests
GracjanJozefczyk May 27, 2024
7b68ee2
OP-225: Behat tests
GracjanJozefczyk May 27, 2024
5972fea
OP-225: Drop 1.12 support
GracjanJozefczyk May 27, 2024
b9a1f44
OP-225: Drop PHP 8.0 support
GracjanJozefczyk May 27, 2024
71237a3
OP-225: Test application config
GracjanJozefczyk May 28, 2024
59b4fca
OP-225: Readme update
GracjanJozefczyk May 28, 2024
1c31e10
OP-225: Change price interval
GracjanJozefczyk May 28, 2024
334dffc
OP-225: Facets auto-submit
GracjanJozefczyk Jun 3, 2024
e918ba2
OP-225: Change autocomplete query
GracjanJozefczyk Jun 3, 2024
67bbbcd
OP-225: Fix readme mistake
GracjanJozefczyk Jun 3, 2024
9dbd187
OP-225: Revert mistake commit
GracjanJozefczyk Jun 3, 2024
83f7542
OP-225: Add php build
GracjanJozefczyk Jun 3, 2024
66754e7
OP-225: Repositories not final anymore
GracjanJozefczyk Jun 3, 2024
53ef02c
OP-225: Default taxon value
GracjanJozefczyk Jun 3, 2024
b1a4fe0
OP-225: Add upgrade docs
GracjanJozefczyk Jun 3, 2024
b90179e
OP-225: Fix build file
GracjanJozefczyk Jun 3, 2024
9bdb055
OP-225: Spec test fix
GracjanJozefczyk Jun 3, 2024
30544d4
OP-225: Common text search logic
GracjanJozefczyk Jun 3, 2024
7850206
OP-225: Replace service argument
GracjanJozefczyk Jun 4, 2024
54a2618
Update spec/QueryBuilder/SiteWideProductsQueryBuilderSpec.php
senghe Jun 10, 2024
1b42c4f
Update src/Form/Resolver/FacetsResolver.php
senghe Jun 10, 2024
a7ebf4a
Apply ECS fixes
senghe Jun 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .docker/fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[www]
user = www-data
group = www-data

listen = /var/run/php-www.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

clear_env = no

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

pm.status_path = /status
catch_workers_output = yes

security.limit_extensions = .php
48 changes: 48 additions & 0 deletions .docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
user www-data;
worker_processes auto;
daemon off;
pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

server_tokens off;

client_max_body_size 64m;
sendfile on;
tcp_nodelay on;
tcp_nopush on;

gzip_vary on;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

server {
listen 80;

root /app/tests/Application/public;
index index.php;

location / {
try_files $uri /index.php$is_args$args;
}

location ~ \.php$ {
include fastcgi_params;

fastcgi_pass unix:/var/run/php-www.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
}
}
15 changes: 15 additions & 0 deletions .docker/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[PHP]
memory_limit=512M

[date]
date.timezone=${PHP_DATE_TIMEZONE}

[opcache]
opcache.enable=0
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
;opcache.preload=/app/config/preload.php
opcache.preload_user=www-data
opcache.jit=1255
opcache.jit_buffer_size=256M
14 changes: 14 additions & 0 deletions .docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[supervisord]
nodaemon = true
user = root
pidfile = /run/supervisord.pid

[program:nginx]
command = /usr/sbin/nginx
user = root
autostart = true

[program:php-fpm]
command = /usr/sbin/php-fpm -F
user = root
autostart = true
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "8.1", "8.2", "8.3" ]
symfony: [ "^5.4", "^6.0" ]
sylius: [ "~1.12.0", "~1.13.0" ]
php: [ "8.1" ]
GracjanJozefczyk marked this conversation as resolved.
Show resolved Hide resolved
symfony: [ "^6.0" ]
sylius: [ "~1.13.0" ]
node: [ "18.x", "20.x" ]
mysql: [ "5.7", "8.0" ]
env:
Expand Down
73 changes: 73 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ARG PHP_VERSION=8.1
ENV LC_ALL=C.UTF-8

# Install basic tools
RUN apt-get update && apt-get install -y \
software-properties-common \
curl \
make \
supervisor \
unzip \
python2 \
g++

# Append NODE, NGINX and PHP repositories
RUN add-apt-repository ppa:ondrej/php \
&& add-apt-repository ppa:ondrej/nginx \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash -

# Install required PHP extensions
RUN apt-get update && apt-get install -y \
nodejs \
nginx \
php${PHP_VERSION} \
php${PHP_VERSION}-apcu \
php${PHP_VERSION}-calendar \
php${PHP_VERSION}-common \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-ctype \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-dom \
php${PHP_VERSION}-exif \
php${PHP_VERSION}-fpm \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-intl \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-mysql \
php${PHP_VERSION}-opcache \
php${PHP_VERSION}-pdo \
php${PHP_VERSION}-pgsql \
php${PHP_VERSION}-sqlite \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-xsl \
php${PHP_VERSION}-yaml \
php${PHP_VERSION}-zip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename composer

# Cleanup
RUN apt-get remove --purge -y software-properties-common curl && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* /usr/share/man/*

# Create directory for php-fpm socket
# Link php-fpm binary file without version
# -p Creates missing intermediate path name directories
RUN ln -s /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm && mkdir -p /run/php

# Install yarn
RUN npm install -g yarn && npm cache clean --force

# Initialize config files
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisor.conf
COPY .docker/nginx.conf /etc/nginx/nginx.conf
COPY .docker/fpm.conf /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
COPY .docker/php.ini /etc/php/${PHP_VERSION}/fpm/php.ini
COPY .docker/php.ini /etc/php/${PHP_VERSION}/cli/php.ini

WORKDIR /app

EXPOSE 80

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
108 changes: 81 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ This **open-source plugin was developed to help the Sylius community**. If you h
[![](https://bitbag.io/wp-content/uploads/2020/10/button-contact.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_elasticsearch)


# Requirements

----

This plugin requires elasticsearch server running. You can install it by following the instructions on the [official website](https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html).
In plugin repository there is Docker Compose file that can be used to run Elasticsearch server.

# Installation

----

We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.
If you use Sylius 1.4, you might get a compatibility issue for Pagerfanta. Please read [this issue](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/issues/23) in order to proceed with a workaround.

*Note*: This Plugin supports ElasticSearch 7.0 and above. If you're looking for ElasticSearch Plugin for older versions check SyliusElasticSearchPlugin in version `1.x`.

Expand Down Expand Up @@ -134,7 +139,7 @@ $ bin/console assets:install

fos_elastica:
clients:
default: { host: localhost, port: 9200 }
default: { url: '%env(ELASTICSEARCH_URL)%' }
indexes:
app: ~
```
Expand All @@ -143,7 +148,7 @@ should become:

fos_elastica:
clients:
default: { host: localhost, port: 9200 }
default: { url: '%env(ELASTICSEARCH_URL)%' }
```
In the end, with an elasticsearch server running, execute following commands:
```
Expand Down Expand Up @@ -203,12 +208,35 @@ webpack_encore:


## Usage
### Rendering the shop products list

### Scope of the search

This plugin offers a site-wide search feature and taxon search feature. It is easily extendable to add more search scopes. For example in Marketplace suite you can create Vendor specific search scope.

### Searching site-wide products

There is searchbar in the header of the shop.

<div align="center">
<img src="doc/es_browser.png" />
</div>

You can easily modify it by overriding the `@BitBagSyliusElasticsearchPlugin/Shop/Menu/_searchForm.html.twig` template or disable it by setting:
```yml
sylius_ui:
events:
sylius.shop.layout.header.content:
blocks:
bitbag_es_search_form:
enabled: false
```

### Searching taxon products

When you go now to the `/{_locale}/products-list/{taxon-slug}` page, you should see a totally new set of filters. You should see something like this:

<div align="center">
<img src="https://raw.githubusercontent.com/bitbager/BitBagCommerceAssets/master/BitBagElasticesearchProductIndex.jpg" />
<img src="doc/es_results.png" />
</div>

You might also want to refer the horizontal menu to a new product list page. Follow below instructions to do so:
Expand All @@ -229,12 +257,52 @@ If you're using vertical menu - follow steps above with `_verticalMenu.html.twig
You might not want to show some specific options or attributes in the menu. You can set specific parameters for that:
```yml
parameters:
bitbag_es_excluded_filter_options: []
bitbag_es_excluded_filter_attributes: ['book_isbn', 'book_pages']
bitbag_es_excluded_facet_attributes: ['jeans_material']
bitbag_es_excluded_facet_options: ['t_shirt_size']
```

By default, all options and attributes filters are shown.

It is also possible to disable options and attribute filters autodiscovery by setting the following parameters:
```yml
parameters:
bitbag_es_facets_auto_discover: false
```

By default, all options and attributes are indexed. After you change these parameters, remember to run `bin/console fo:el:po` command again
(a shortcut for `fos:elastica:populate`).
Then you have to manually register your filters:

Available filters:
* [`TaxonFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/TaxonFacet.php) which allows to filter your search results by taxons using the ElasticSearch [`Terms`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) aggregation.
* [`AttributeFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/AttributeFacet.php) which allows to filter your search results by product attributes values using the ElasticSearch [`Terms`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) aggregation.
* [`OptionFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/OptionFacet.php) which is the same as `AttributeFacet` but for product options.
* [`PriceFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/PriceFacet.php) which allows to filter search results by price range the ElasticSearch [`Histogram`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html) aggregation.

Example of manual registration of filters:
```yml
services:
bitbag_sylius_elasticsearch_plugin.facet.attribute.t_shirt_brand:
class: BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet
arguments:
- '@bitbag_sylius_elasticsearch_plugin.property_name_resolver.attribute'
- '@=service("sylius.repository.product_attribute").findOneBy({"code": "t_shirt_brand"})'
- '@sylius.context.locale'

bitbag_sylius_elasticsearch_plugin.facet.registry:
class: BitBag\SyliusElasticsearchPlugin\Facet\Registry
calls:
- method: addFacet
arguments:
- t_shirt_brand
- '@bitbag_sylius_elasticsearch_plugin.facet.attribute.t_shirt_brand'
- method: addFacet
arguments:
- price
- '@bitbag_sylius_elasticsearch_plugin.facet.price'
- method: addFacet
arguments:
- taxon
- '@bitbag_sylius_elasticsearch_plugin.facet.taxon'
```

### Reindexing

Expand All @@ -254,20 +322,6 @@ fos_elastica:

Indexes with `bitbag_shop_product`, `bitbag_attribute_taxons` and `bitbag_option_taxons` keys are available so far.

### Site-wide search

This plugin offers a site-wide search feature as well. You have a search box field where you query all products indexed on ElasticSearch. When you enter a query in the search box the results will appear in the search results page.

### Facets

You can also add search facets (a.k.a. filters) to your search results page, both taxon and site-wide search. To do so you have to add facets to the `bitbag_sylius_elasticsearch_plugin.facet.registry` (for site-wide search) or `bitbag_sylius_elasticsearch_plugin.facet.taxon_registry` (for taxon search) service (see an example of those service definitions [here](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/tests/Application/config/services.yaml)). A facet is a service which implements the `BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface`. You can implement your own facets from scratch or you can [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) one of the basic facet implementation included in this plugin, which are:

* [`TaxonFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/TaxonFacet.php) which allows to filter your search results by taxons using the ElasticSearch [`Terms`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) aggregation.
* [`AttributeFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/AttributeFacet.php) which allows to filter your search results by product attributes values using the ElasticSearch [`Terms`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) aggregation.
* [`OptionFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/OptionFacet.php) which is the same as `AttributeFacet` but for product options.
* [`PriceFacet`](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/Facet/PriceFacet.php) which allows to filter search results by price range the ElasticSearch [`Histogram`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html) aggregation.

You can see an example of the definition of all of these facets [here](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/tests/Application/config/services.yaml).

## Customization

Expand Down Expand Up @@ -307,10 +361,10 @@ We build **unforgettable**, consistent digital customer journeys on top of the *
Our team is fluent in **Polish, English, German and, French**. That is why our cooperation with clients from all over the world is smooth.

**Some numbers from BitBag regarding Sylius:**
- 50+ **experts** including consultants, UI/UX designers, Sylius trained front-end and back-end developers,
- 120+ projects **delivered** on top of Sylius,
- 25+ **countries** of BitBag’s customers,
- 4+ **years** in the Sylius ecosystem.
- 70+ **experts** including consultants, UI/UX designers, Sylius trained front-end and back-end developers,
- 150+ projects **delivered** on top of Sylius,
- 30+ **countries** of BitBag’s customers,
- 7+ **years** in the Sylius ecosystem.

**Our services:**
- Business audit/Consulting in the field of **strategy** development,
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "BitBag Elasticsearch plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^8.1",
"ext-json": "*",
"php": "^8.0",
"friendsofsymfony/elastica-bundle": "^6.0",
"sylius/sylius": ">=1.12.13 || ~1.13.0",
"sylius/sylius": "~1.13.0",
"symfony/property-access": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.15",
"symfony/proxy-manager-bridge": "^5.4 || ^6.0"
Expand Down Expand Up @@ -35,7 +35,7 @@
"phpstan/phpstan-doctrine": "1.3.69",
"phpstan/phpstan-strict-rules": "^1.3.0",
"phpstan/phpstan-webmozart-assert": "^1.2.0",
"phpunit/phpunit": "^10.5",
"phpunit/phpunit": "^9.0 || ^10.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"robertfausk/behat-panther-extension": "^1.1",
"sylius-labs/coding-standard": "^4.2",
Expand Down
Binary file added doc/es_browser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/es_results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading