Hi All,

I have a Item model which belongs to a category. Categories can belong
to a parent category.

I'm trying to index the categories with the following (I've removed
surplus config):

class Item < ActiveRecord::Base
  define_index do
    has "CONCAT_WS(',', IFNULL(categories.id, 0),
IFNULL(categories.parent_id, 0))", :as => :category, :source
=> :field, :facet => true
    join category
  end
end

Search queries work as expected, returning the correct items. Facets
on the other hand, appear to be wrong:

> Item.facets
 => {:category=>{nil=>137}, :shop=>{8=>137}}

This is the relevant part of the sphinx config:

source item_core_0
{
  ...snip...
  sql_query = SELECT SQL_NO_CACHE `items`.`id` * CAST(1 AS SIGNED) + 0
AS `id` , `items`.`name` AS `name`, `items`.`shop_name` AS
`shop_name`, `items`.`id` AS `sphinx_internal_id`, 0 AS
`sphinx_deleted`, 3207170592 AS `class_crc`, CONCAT_WS(',',
IFNULL(categories.id, 0), IFNULL(categories.parent_id, 0)) AS
`category`, CRC32(CONCAT_WS(',', IFNULL(categories.id, 0),
IFNULL(categories.parent_id, 0))) AS `category_facet`,
COALESCE(items.sale_price, items.price) AS `price`, `items`.`shop_id`
AS `shop`, UNIX_TIMESTAMP(`items`.`created_at`) AS `created_at` FROM
`items` LEFT OUTER JOIN `categories` ON `categories`.`id` =
`items`.`category_id` WHERE (`items`.`id` >= $start AND `items`.`id`
<= $end AND items.stock = 1) GROUP BY `items`.`id`, `items`.`name`,
`items`.`shop_name`, `items`.`id`, `items`.`shop_id`,
`items`.`created_at` ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1)
FROM `items`
  sql_attr_uint = sphinx_internal_id
  sql_attr_uint = sphinx_deleted
  sql_attr_uint = class_crc
  sql_attr_uint = shop
  sql_attr_timestamp = created_at
  sql_attr_float = price
  sql_attr_multi = uint category from field
  sql_attr_multi = uint category_facet from field
  sql_query_info = SELECT * FROM `items` WHERE `id` = (($id - 0) / 1)
}

Any help would be greatly appreciated.

Cheers,

Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to