Created
October 20, 2010 18:18
-
-
Save tsnow/636992 to your computer and use it in GitHub Desktop.
Trying to find the siteids for place searching
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
--EXISTING SQL FOR SPHINX | |
SELECT SQL_NO_CACHE | |
`places`.`id` * 2 + 1 AS `id` , | |
`places`.`name` AS `name`, | |
`places`.`address` AS `address`, | |
`places`.`city` AS `city`, | |
`places`.`description` AS `description`, | |
GROUP_CONCAT(DISTINCT IFNULL(`reviews`.`body`, '0') SEPARATOR ' ') AS `body`, | |
GROUP_CONCAT(DISTINCT IFNULL(`reviews`.`title`, '0') SEPARATOR ' ') AS `title`, | |
GROUP_CONCAT(DISTINCT IFNULL(`tags`.`name`, '0') SEPARATOR ' ') AS `tags`, | |
`places`.`id` AS `sphinx_internal_id`, 3051125961 AS `class_crc`, | |
'3051125961' AS `subclass_crcs`, 0 AS `sphinx_deleted`, | |
GROUP_CONCAT(DISTINCT IFNULL(`users`.`site_id`, '0') SEPARATOR ',') AS `site_id` | |
FROM `places` | |
LEFT OUTER JOIN `reviews` ON `reviews`.reviewable_id = `places`.id | |
AND `reviews`.reviewable_type = 'Place' | |
LEFT OUTER JOIN `taggings` ON `taggings`.taggable_id = `places`.id | |
AND `taggings`.taggable_type = 'Place' | |
LEFT OUTER JOIN `tags` ON `tags`.id = `taggings`.tag_id | |
LEFT OUTER JOIN `users` ON `users`.id = `reviews`.user_id | |
WHERE `places`.`id` >= $start AND `places`.`id` <= $end | |
GROUP BY `places`.`id` ORDER BY NULL | |
--NEW SQL FOR SPHINX | |
SELECT SQL_NO_CACHE | |
`places`.`id` * 2 + 1 AS `id` , | |
`places`.`name` AS `name`, | |
`places`.`address` AS `address`, | |
`places`.`city` AS `city`, | |
`places`.`description` AS `description`, | |
GROUP_CONCAT(DISTINCT IFNULL(`reviews`.`body`, '0') SEPARATOR ' ') AS `body`, | |
GROUP_CONCAT(DISTINCT IFNULL(`reviews`.`title`, '0') SEPARATOR ' ') AS `title`, | |
GROUP_CONCAT(DISTINCT IFNULL(`tags`.`name`, '0') SEPARATOR ' ') AS `tags`, | |
`places`.`id` AS `sphinx_internal_id`, 3051125961 AS `class_crc`, | |
'3051125961' AS `subclass_crcs`, 0 AS `sphinx_deleted`, | |
GROUP_CONCAT(DISTINCT IFNULL(`users`.`site_id`, '0'), IFNULL(`city_sites`.`id`, '0'), IFNULL(`region_sites`.`id`, '0') SEPARATOR ',') AS `site_id` | |
FROM `places` | |
LEFT OUTER JOIN `reviews` ON `reviews`.reviewable_id = `places`.id | |
AND `reviews`.reviewable_type = 'Place' | |
LEFT OUTER JOIN `taggings` ON `taggings`.taggable_id = `places`.id | |
AND `taggings`.taggable_type = 'Place' | |
LEFT OUTER JOIN `tags` ON `tags`.id = `taggings`.tag_id | |
LEFT OUTER JOIN `users` ON `users`.id = `reviews`.user_id | |
-- NEW Joins | |
LEFT OUTER JOIN `edges` as city_edges ON city_edges.child_id = places.id | |
AND city_edges.child_type = 'Place' AND city_edges.parent_type = "City" | |
LEFT OUTER JOIN `edges` as region_edges ON region_edges.child_id = city_edges.id | |
AND region_edges.child_type = "City" AND region_edges.parent_type = "Region" | |
LEFT OUTER JOIN sites as city_sites ON city_sites.root_node_id = city_edges.parent_id and city_sites.root_node_type = "City" | |
LEFT OUTER JOIN sites as region_sites ON region_sites.root_node_id = | |
region_edges.parent_id and region_sites.root_node_type = "Region" | |
WHERE `places`.`id` >= $start AND `places`.`id` <= $end | |
GROUP BY `places`.`id` ORDER BY NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment