@@ -79,6 +79,42 @@ public function testSearchAll()
79
79
self ::assertGreaterThanOrEqual (2 , $ result );
80
80
}
81
81
82
+ /**
83
+ * Test sorting of all products after full reindex
84
+ *
85
+ * @magentoDbIsolation enabled
86
+ * @magentoConfigFixture default/catalog/search/engine elasticsearch6
87
+ * @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest_configurable
88
+ * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_products.php
89
+ */
90
+ public function testSort ()
91
+ {
92
+ /** @var $productFifth \Magento\Catalog\Model\Product */
93
+ $ productSimple = Bootstrap::getObjectManager ()->create (\Magento \Catalog \Model \Product::class);
94
+ $ productSimple ->setTypeId ('simple ' )
95
+ ->setAttributeSetId (4 )
96
+ ->setWebsiteIds ([1 ])
97
+ ->setName ('ABC ' )
98
+ ->setSku ('abc-first-in-sort ' )
99
+ ->setPrice (20 )
100
+ ->setMetaTitle ('meta title ' )
101
+ ->setMetaKeyword ('meta keyword ' )
102
+ ->setMetaDescription ('meta description ' )
103
+ ->setVisibility (\Magento \Catalog \Model \Product \Visibility::VISIBILITY_BOTH )
104
+ ->setStatus (\Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED )
105
+ ->setStockData (['use_config_manage_stock ' => 0 ])
106
+ ->save ();
107
+ $ productConfigurableOption = $ this ->productRepository ->get ('simple_10 ' );
108
+ $ productConfigurableOption ->setName ('1ABC ' );
109
+ $ this ->productRepository ->save ($ productConfigurableOption );
110
+ $ this ->reindexAll ();
111
+ $ productSimple = $ this ->productRepository ->get ('abc-first-in-sort ' );
112
+ $ result = $ this ->sortByName ();
113
+ $ firstInSearchResults = (int ) $ result [0 ]['_id ' ];
114
+ $ productSimpleId = (int ) $ productSimple ->getId ();
115
+ $ this ->assertEquals ($ productSimpleId , $ firstInSearchResults );
116
+ }
117
+
82
118
/**
83
119
* Test search of specific product after full reindex
84
120
*
@@ -125,6 +161,38 @@ private function searchByName($text)
125
161
return isset ($ queryResult ['hits ' ]['hits ' ]) ? $ queryResult ['hits ' ]['hits ' ] : [];
126
162
}
127
163
164
+ /**
165
+ * @return array
166
+ */
167
+ private function sortByName ()
168
+ {
169
+ $ storeId = $ this ->storeManager ->getDefaultStoreView ()->getId ();
170
+ $ searchQuery = [
171
+ 'index ' => $ this ->searchIndexNameResolver ->getIndexName ($ storeId , 'catalogsearch_fulltext ' ),
172
+ 'type ' => $ this ->clientConfig ->getEntityType (),
173
+ 'body ' => [
174
+ 'sort ' => [
175
+ 'name.sort_name ' => [
176
+ 'order ' => 'asc '
177
+ ],
178
+ ],
179
+ 'query ' => [
180
+ 'bool ' => [
181
+ 'must ' => [
182
+ [
183
+ 'terms ' => [
184
+ 'visibility ' => [2 , 4 ],
185
+ ],
186
+ ],
187
+ ],
188
+ ],
189
+ ],
190
+ ],
191
+ ];
192
+ $ queryResult = $ this ->client ->query ($ searchQuery );
193
+ return isset ($ queryResult ['hits ' ]['hits ' ]) ? $ queryResult ['hits ' ]['hits ' ] : [];
194
+ }
195
+
128
196
/**
129
197
* Make fulltext catalog search reindex
130
198
*
0 commit comments