Question

I have the following text fields I search with Sphinx: Title, Description, keywords.

However, sometimes things are narrowed down using categories. We have 3 category fields: CatID1, CatID2 and CatID3.

So, for example, I need to see if the word "Kittens" is in the Title, Description, or Keywords, but I also want to filter so that only items that have the categories (Animals - ID Number 8) or (Pets - ID Number 9) or (Felines - Category ID Number 10) in either of those CatID fields.

To clarify, only show items that have a 8,9 or 10 in CatID1, 2 or 3.

Any ideas on how I would accomplish this using sphinx filtering or searching the CatID1 fields as keywords?

Note: I am able to filter and it works great only using one category, i.e:

 if(!empty($cat_str)) {


        $cl->SetFilter( 'catid1', array( $cat_str ));


        }

Thanks!

Craig

Was it helpful?

Solution

SetFilter takes an array. In your example you are putting $cat_str into an array. A array of one item.

So you just needs to build array with all the ids.

$cl->SetFilter( 'catid', array( $cat1, $cat2, $cat3 ));

But thats not very flexible. So you probably build the array dynamically, rather than hard-coded like that. But thats upto your application how to build the array.

But also storing the ids, in three sperate attributes, makes it hard to search. Notice in the above example, just noticed a attribute called catid. This would be a single multi-value attribute, that contains the ids from all three cat fields. That way its easy to search for ids in ANY of the columns at once.

http://sphinxsearch.com/docs/current.html#mva

if using a sql source, could do with something like

sql_query = SELECT id, title ... , CONCAT_WS(',', CatID1, CatID2 and CatID3) as catid FROM ... 
sql_attr_multi = uint catid from field;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top