tags:

views:

307

answers:

1

in my sphinx source config I have an attribute like so:

sql_attr_multi = uint categories from query; SELECT entry_id, cat_id FROM categories_entries

When querying the sphinx index, is it possible to get only records that do not have a category attribute? As a kludgy fix I have executed a query on the database to find all potential category ids and then excluded those attributes from the Sphinx results:

$query = $DB->query("SELECT GROUP_CONCAT(cat_id SEPARATOR ',') AS categories 
    FROM categories WHERE category_group='3' 
    GROUP BY category_group");

$sphinxclient->SetFilter("categories", explode(",", $query->result[0]['categories']), true);

This works but it seems like there should be a better way.

+1  A: 

There's no way to check if an MVA collection is empty for a given document... however, you could add another integer attribute which is the COUNT for categories attached to each document. Then you can filter on that equalling zero, or being within a certain range.

pat
interesting approach. seems a bit less hacky than my current solution.
Ty W