Last active
August 29, 2015 14:27
-
-
Save mpchadwick/301a44554906a8d30989 to your computer and use it in GitHub Desktop.
Mageto Improved Autocomplete Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################# | |
# ORIGINAL | |
# Then the term matching the search is plucked to the top in PHP | |
# This eliminates the ability to put a "limit" on the result set | |
################################################################# | |
SELECT | |
DISTINCT IFNULL(synonym_for, query_text) AS `query`, | |
`main_table`.`num_results`, | |
`main_table`.* | |
FROM `catalogsearch_query` AS `main_table` | |
WHERE | |
(num_results > 0 AND display_in_terms = 1 AND query_text LIKE '%tissue box%') | |
AND (store_id = 1) | |
ORDER BY `popularity` DESC | |
################################################################# | |
# IMPROVED | |
# We push our search term to the front in the order by | |
# This allows us to use a LIMIT in the query | |
################################################################# | |
SELECT | |
DISTINCT IFNULL(synonym_for, query_text) AS `query`, | |
`main_table`.`num_results`, | |
`main_table`.* | |
FROM `catalogsearch_query` AS `main_table` | |
WHERE | |
(num_results > 0 AND display_in_terms = 1 AND query_text LIKE '%tissue box%') | |
AND (store_id = 1) | |
ORDER BY | |
CASE | |
WHEN `query` = 'tissue box' THEN 0 | |
ELSE 1 | |
END, `popularity` DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment