Search code examples
phpsphinx

Sphinx show one or x from each category


I have a products index on sphinx . Im searching and filtering by category. Im sorting via "id desc" and with that settings i see the last products. Thats okey. But the real problem is that :

I want to show that not listed one category and the other (because my products added one, and than the other). i want to list both id desc (the last products first) and shuffled category.

Via design:

id category_id name
-- ----------- ----
1       1       a
2       1       b
3       1       c
4       2       d
5       2       e
6       2       f

Now (The order):

f-e-d-c-b-a

But i want

f-c-e-b-d-a

My sphinx code :

        $sphinx = new SphinxClient();
        $sphinx->SetServer("127.0.0.1", 9312);


            $sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
            $sphinx->SetRankingMode(SPH_RANK_WORDCOUNT);
           $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'id DESC');



        $sphinx->SetArrayResult(true);


        $filtersArr = $this->getSphinxFilterParams($params);

        foreach ($filtersArr['filter'] as $attr => $val)
        {
            $sphinx->SetFilter($attr, $val[0], $val[1]);
        }

Is there anyway to make that ?


Solution

  • There is a thread on the sphinx forum about this here: http://sphinxsearch.com/forum/view.html?id=10546

    While it is mostly possibly with the sphinxAPI (via the undocumented setOuterSelect), suggest migrating to SphinxQL, as it will be most easier to work with.