Skip to content

Commit

Permalink
Add blocks on twig to simplify overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Aug 8, 2024
1 parent 7e35912 commit a7c3660
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
8 changes: 8 additions & 0 deletions templates/query/completion-suggesters/query.json.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
{% block query_suggest %}
"suggest": {
"prefix": {{ searchTerm|json_encode|raw }},
{% block query_suggest_suggest_completion %}
"completion": {
"field": "suggest",
"size": {{ size|json_encode|raw }},
Expand All @@ -10,6 +12,12 @@
"transpositions": true,
"min_length": 4
}
{% block query_suggest_suggest_completion_extra %}
{% endblock %}
}
{% endblock %}
}
{% endblock %}
{% block query_extra %}
{% endblock %}
}
47 changes: 45 additions & 2 deletions templates/query/search/query.json.twig
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
{% set searchTerm = searchTerm|json_encode %}
{
{% block query_bool %}
"bool": {
{% block query_bool_filter %}
"filter": [
{% block query_bool_filter_enabled %}
{
"term": {
"enabled": true
}
}
{% endblock %}
{% block query_bool_filter_filters %}
{% for filterType, filters in filters %}
{% if filters|length > 0 %}
,{% include '@WebgriffeSyliusElasticsearchPlugin/query/search/search/' ~ filterType ~ '.json.twig' %}
{% endif %}
{% endfor %}{% block extra_filter_fields %}{% endblock %}
{% endfor %}
{% endblock %}
{% block query_bool_filter_extra %}{% endblock %}
],
{% endblock %}
{% block query_bool_should %}
"should": [
{% block query_bool_should_product_code %}
{
"term": {
"code": {{ searchTerm|raw }}
}
},
{% endblock %}
{% block query_bool_should_variant_codes %}
{
"nested": {
"path": "variants",
Expand All @@ -29,6 +41,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_name %}
{
"nested": {
"path": "name",
Expand All @@ -45,6 +59,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_variant_names %}
{
"nested": {
"path": "variants",
Expand All @@ -61,6 +77,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_description %}
{
"nested": {
"path": "description",
Expand All @@ -77,6 +95,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_short_description %}
{
"nested": {
"path": "short-description",
Expand All @@ -93,6 +113,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_slug %}
{
"nested": {
"path": "slug",
Expand All @@ -109,6 +131,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_meta_description %}
{
"nested": {
"path": "meta-description",
Expand All @@ -125,6 +149,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_meta_keywords %}
{
"nested": {
"path": "meta-keywords",
Expand All @@ -141,6 +167,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_taxon_names %}
{
"nested": {
"path": "taxons",
Expand All @@ -157,6 +185,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_translated_attribute_values %}
{
"nested": {
"path": "translated-attributes",
Expand All @@ -173,6 +203,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_attribute_values %}
{
"nested": {
"path": "attributes",
Expand All @@ -189,6 +221,8 @@
}
}
},
{% endblock %}
{% block query_bool_should_product_option_values %}
{
"nested": {
"path": "product-options",
Expand All @@ -204,7 +238,16 @@
}
}
}
}{% block extra_should_fields %}{% endblock %}
}
{% endblock %}
{% block query_bool_should_extra %}
{% endblock %}
]
{% endblock %}
{% block query_bool_extra %}
{% endblock %}
}
{% endblock %}
{% block query_extra %}
{% endblock %}
}
17 changes: 16 additions & 1 deletion templates/query/taxon/query.json.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
{% block query_bool %}
"bool": {
{% block query_bool_filter %}
"filter": [
{% block query_bool_filter_enabled %}
{
"term": {
"enabled": true
}
},
{% endblock %}
{% block query_bool_filter_taxon %}
{
"nested": {
"path": "taxons",
Expand All @@ -22,11 +27,21 @@
}
}
}
{% endblock %}
{% block query_bool_filter_filters %}
{% for filterType, filters in filters %}
{% if filters|length > 0 %}
,{% include '@WebgriffeSyliusElasticsearchPlugin/query/taxon/search/' ~ filterType ~ '.json.twig' %}
{% endif %}
{% endfor %}{% block extra_filter_fields %}{% endblock %}
{% endfor %}
{% endblock %}
{% block query_bool_filter_extra %}{% endblock %}
]
{% endblock %}
{% block query_bool_extra %}
{% endblock %}
}
{% endblock %}
{% block query_extra %}
{% endblock %}
}
8 changes: 8 additions & 0 deletions templates/query/term-suggesters/query.json.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
{% block query_suggest %}
"suggest": {
"text": {{ searchTerm|json_encode|raw }},
{% block query_suggest_text_term %}
"term": {
"field": {{ ('name.' ~ localeCode)|json_encode|raw }},
"suggest_mode" : "missing"
{% block query_suggest_text_term_extra %}
{% endblock %}
}
{% endblock %}
}
{% endblock %}
{% block query_extra %}
{% endblock %}
}

0 comments on commit a7c3660

Please sign in to comment.