Skip to content

Commit

Permalink
Merge pull request #196 from maximehuran/feature/score-in-parameters
Browse files Browse the repository at this point in the history
Fields to search in parameters
  • Loading branch information
maximehuran authored Oct 10, 2023
2 parents bb8a72e + 0627f6a commit 006d987
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 43 deletions.
13 changes: 13 additions & 0 deletions dist/src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
parameters:
monsieurbiz.search.product.is_in_stock_scoring_boost: 200 # Enable the boost for in stock products
monsieurbiz.search.product.search.fields_to_search:
- 'name^5'
- 'description'
- 'short_description' # We add our new value in search
monsieurbiz.search.product.search.nested_fields_to_search:
- 'main_taxon:name^2' # We add our new nested value in instant search
monsieurbiz.search.product.instant.fields_to_search:
- 'name^5'
- 'name.autocomplete'
- 'description'
- 'short_description' # We add our new value in search
monsieurbiz.search.product.instant.nested_fields_to_search:
- 'main_taxon:name^2' # We add our new nested value in instant search

imports:
- { resource: "services.yaml" }
Expand Down
26 changes: 0 additions & 26 deletions dist/src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,6 @@ services:
arguments:
- '@.inner'

# Add short_description in searchable fields
monsieurbiz.search.request.query_filter.product_search.search_term_filter:
class: MonsieurBiz\SyliusSearchPlugin\Search\Request\QueryFilter\Product\SearchTermFilter
arguments:
$fieldsToSearch:
- 'name^5'
- 'description'
- 'short_description' # We add our new value in search
$nestedFieldsToSearch:
- 'main_taxon:name^2' # We add our new nested value in search
tags:
- { name: monsieurbiz.search.request.product_search_filter }

monsieurbiz.search.request.query_filter.product_instant_search.search_term_filter:
class: MonsieurBiz\SyliusSearchPlugin\Search\Request\QueryFilter\Product\SearchTermFilter
arguments:
$fieldsToSearch:
- 'name^5'
- 'description'
- 'name.autocomplete'
- 'short_description' # We add our new value in instant search
$nestedFieldsToSearch:
- 'main_taxon:name^2' # We add our new nested value in instant search
tags:
- { name: monsieurbiz.search.request.product_instant_search_filter }

# Define sorters
App\Search\Request\Sorting\Product\ShortDescriptionSorter:
tags:
Expand Down
2 changes: 1 addition & 1 deletion docs/add_custom_boosts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ The boost is enabled when the value of `monsieurbiz.search.product.is_in_stock_s
To create a new boost, you must

- [Create a new class that implements `MonsieurBiz\SyliusSearchPlugin\Search\Request\FunctionScore\FunctionScoreInterface`](../dist/src/Search/Request/FunctionScore/Product/BoostExpensiveProductFunction.php)
- [Tag it with `monsieurbiz.search.request.product_function_score`](../dist/src/Resources/config/services.yaml#L54)
- [Tag it with `monsieurbiz.search.request.product_function_score`](../dist/src/Resources/config/services.yaml#L35)

In our example we will boost, in the search, the product with a price greater than 50.
8 changes: 4 additions & 4 deletions docs/add_custom_entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ Also, the `public function getTarget(): string` method must return the value of

If you want to display your entity in the instant search (`instant_search_enabled` is `true` in configuration).

[Declare your instant search request service](../dist/src/Resources/config/services.yaml#L60).
[Declare your instant search request service](../dist/src/Resources/config/services.yaml#38).

[Don't forget to bind the parameter for the service](../dist/src/Resources/config/services.yaml#L6).

### Define your Search request

[Declare your search request service](../dist/src/Resources/config/services.yaml#L67).
[Declare your search request service](../dist/src/Resources/config/services.yaml#45).

[Don't forget to bind the parameter for the service](../dist/src/Resources/config/services.yaml#L6).

You can extends the `MonsieurBiz\SyliusSearchPlugin\Search\Request\Search` class to manage your aggregations like in [products](../src/Search/Request/ProductRequest/Search.php).

### Define your Search query filter

[Declare your search query filter for instant search](../dist/src/Resources/config/services.yaml#L77).
[Declare your search query filter for instant search](../dist/src/Resources/config/services.yaml#55).

[Declare your search query filter for search](../dist/src/Resources/config/services.yaml#L87).
[Declare your search query filter for search](../dist/src/Resources/config/services.yaml#65).

You can extends the `MonsieurBiz\SyliusSearchPlugin\Search\Request\QueryFilter\SearchTermFilter` class to manage your custom behaviour like in [products](../src/Search/Request/QueryFilter/Product/SearchTermFilter.php).

Expand Down
2 changes: 1 addition & 1 deletion docs/add_custom_sorts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
You can create your own sorter service by implementing the `SorterInterface` interface.
For example, in your test application, [we have a short description sorter](../dist/src/Search/Request/Sorting/Product/ShortDescriptionSorter.php).

Add [the tag `monsieurbiz.search.request.product_sorter` to your service](../dist/src/Resources/config/services.yaml#L49).
Add [the tag `monsieurbiz.search.request.product_sorter` to your service](../dist/src/Resources/config/services.yaml#27).

## Replace existing sorter

Expand Down
7 changes: 3 additions & 4 deletions docs/add_custom_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ You will have the `item.short_description` variable available in your templates.
## Search on the custom value

With only the decorator, you will not be able to search in the content of the new field.
You have to redeclare `monsieurbiz.search.request.query_filter.product_search.search_term_filter`
and `monsieurbiz.search.request.query_filter.product_instant_search.search_term_filter` services
to add the `short_description` fields.
You have to change parameters to define the fields to search for the search page and the instant search.

- [Add `short_description` in search term filter](../dist/src/Resources/config/services.yaml#L34)
- [Add `short_description` in `monsieurbiz.search.product.search.fields_to_search`](../dist/src/Resources/config/config.yaml#6)
- [Add `short_description` in `monsieurbiz.search.product.instant.fields_to_search`](../dist/src/Resources/config/config.yaml#13)
20 changes: 13 additions & 7 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ parameters:
- !php/const MonsieurBiz\SyliusSearchPlugin\Search\Request\RequestInterface::SEARCH_TYPE
- !php/const MonsieurBiz\SyliusSearchPlugin\Search\Request\RequestInterface::TAXON_TYPE
- !php/const MonsieurBiz\SyliusSearchPlugin\Search\Request\RequestInterface::INSTANT_TYPE
monsieurbiz.search.product.search.fields_to_search:
- 'name^5'
- 'description'
monsieurbiz.search.product.search.nested_fields_to_search: []
monsieurbiz.search.product.instant.fields_to_search:
- 'name^5'
- 'name.autocomplete'
- 'description'
monsieurbiz.search.product.instant.nested_fields_to_search: []

services:

Expand Down Expand Up @@ -120,19 +129,16 @@ services:
monsieurbiz.search.request.query_filter.product_search.search_term_filter:
class: MonsieurBiz\SyliusSearchPlugin\Search\Request\QueryFilter\Product\SearchTermFilter
arguments:
$fieldsToSearch:
- 'name^5'
- 'description'
$fieldsToSearch: '%monsieurbiz.search.product.search.fields_to_search%'
$nestedFieldsToSearch: '%monsieurbiz.search.product.search.nested_fields_to_search%'
tags:
- { name: monsieurbiz.search.request.product_search_filter }

monsieurbiz.search.request.query_filter.product_instant_search.search_term_filter:
class: MonsieurBiz\SyliusSearchPlugin\Search\Request\QueryFilter\Product\SearchTermFilter
arguments:
$fieldsToSearch:
- 'name^5'
- 'description'
- 'name.autocomplete'
$fieldsToSearch: '%monsieurbiz.search.product.instant.fields_to_search%'
$nestedFieldsToSearch: '%monsieurbiz.search.product.instant.nested_fields_to_search%'
tags:
- { name: monsieurbiz.search.request.product_instant_search_filter }

Expand Down

0 comments on commit 006d987

Please sign in to comment.