File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
app/code/Magento/Search/Model/ResourceModel/Query Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,36 @@ public function setPopularQueryFilter($storeIds = null)
149
149
return $ this ;
150
150
}
151
151
152
+ /**
153
+ * Determines whether a Search Term belongs to the top results for given storeId
154
+ *
155
+ * @param string $term
156
+ * @param int $storeId
157
+ * @param int $maxCountCacheableSearchTerms
158
+ * @return bool
159
+ */
160
+ public function isTopSearchResult (string $ term , int $ storeId , int $ maxCountCacheableSearchTerms ):bool
161
+ {
162
+ $ select = $ this ->getSelect ();
163
+ $ select ->reset (\Magento \Framework \DB \Select::FROM );
164
+ $ select ->reset (\Magento \Framework \DB \Select::COLUMNS );
165
+ $ select ->distinct (true );
166
+ $ select ->from (['main_table ' => $ this ->getTable ('search_query ' )], ['query_text ' ]);
167
+ $ select ->where ('main_table.store_id IN (?) ' , $ storeId );
168
+ $ select ->where ('num_results > 0 ' );
169
+ $ select ->order (['popularity desc ' ]);
170
+
171
+ $ select ->limit ($ maxCountCacheableSearchTerms );
172
+
173
+ $ subQuery = new \Zend_Db_Expr ('( ' . $ select ->assemble () . ') ' );
174
+
175
+ $ select ->reset ();
176
+ $ select ->from (['result ' => $ subQuery ], []);
177
+ $ select ->where ('result.query_text = ? ' , $ term );
178
+
179
+ return $ this ->getSize () > 0 ;
180
+ }
181
+
152
182
/**
153
183
* Set Recent Queries Order
154
184
*
You can’t perform that action at this time.
0 commit comments