Domanda

Here is the structure of my database with products and categories

-- Product Table

CREATE TABLE `product_table` (
`product_id` int(11) NOT NULL,
`product_title` text,
`product_description` text
);

-- Product2Category Table

CREATE TABLE `product2category_table` (
`product_id` int(11) NOT NULL,
`category_id` int(11) NOT NULL
);

I am creating the multi-valued attribute on category

sql_attr_multi = uint prod_cat from query; \
select p.product_id, c.category_id from product as p, product2category as c
            where c.product_id = p.product_id;

The relation between product and categories is many to many. As an example a product called lenovo can belong to categories:

category_id category_title
    12           sturdy
    20           laptop

Question: How should I query using php-sphinx api, find all the products with electronics in their description belonging to both the categories ids 12 and 20. Normally $cl->setfilter('prod_cat',array(12,20) will return even the products belonging to either of the categories. I know if I group concatenate all the categories for a product and do the full text search, it is quite simple. But is there a way to handle with the MVA feature.

È stato utile?

Soluzione

$cl->setfilter('prod_cat',array(12));
$cl->setfilter('prod_cat',array(20));

Multiple calls are 'AND'ed :)


As an aside, can simplify your MVA query...

sql_attr_multi = uint prod_cat from query; \
    select product_id, category_id from product2category
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top