Skip to content

Instantly share code, notes, and snippets.

@clemens
Created December 17, 2010 12:51
Show Gist options
  • Save clemens/744886 to your computer and use it in GitHub Desktop.
Save clemens/744886 to your computer and use it in GitHub Desktop.
the query selects all ids from the full branch from the nested set
class Product
define_index do
# ...
has %(
(
SELECT GROUP_CONCAT(IFNULL(parent.`id`, '0') SEPARATOR ',')
FROM `categories` AS node,
`categories` AS parent
WHERE node.`merchant_id` = `products`.`merchant_id` AND
parent.`merchant_id` = `products`.`merchant_id` AND
node.`lft` BETWEEN parent.`lft` AND parent.`rgt` AND node.`id` = `category_id`
ORDER BY parent.`lft`
)
), :source => :query, :type => :multi, :as => :category_ids, :facet => true
end
end
@clemens
Copy link
Author

clemens commented Dec 17, 2010

It's Rails 2.3, Thinking Sphinx 1.4.0, Riddle 1.2.1 and Sphinx 0.9.9 r2117.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment