Sorting facet count in php

Is it possible to sort by the count on a facet using php?

I tried this (and other variations) without any success:
$result = $search->search($q)->facet($group)->sort(‘count(*)’,‘desc’)->get();

Couldn’t find an example in the documentation.

Thank you :slight_smile:

Hi Jam

So you are looking for an equivalent of this:

mysql> drop table if exists t; create table t(f text, a int); insert into t(a) values(1),(2),(2); select * from t facet a order by count(*) desc;
--------------
drop table if exists t
--------------

Query OK, 0 rows affected (0.01 sec)

--------------
create table t(f text, a int)
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
insert into t(a) values(1),(2),(2)
--------------

Query OK, 3 rows affected (0.00 sec)

--------------
select * from t facet a order by count(*) desc
--------------

+---------------------+------+------+
| id                  | a    | f    |
+---------------------+------+------+
| 1514614548835860493 |    1 |      |
| 1514614548835860494 |    2 |      |
| 1514614548835860495 |    2 |      |
+---------------------+------+------+
3 rows in set (0.01 sec)

+------+----------+
| a    | count(*) |
+------+----------+
|    2 |        2 |
|    1 |        1 |
+------+----------+
2 rows in set (0.01 sec)

in php. Unfortunately it’s not possible via HTTP JSON protocol yet and via the clients based on that including php, too.

Thank you Sergey. I’ve coded a work around (returning a large result set and then sorting with array_multisort in php) but it would be helpful if this functionality could be included in the php client in the future (it was possible with Sphinx). Here is an example of where I am using this (currently running on Sphinx but I’m planning a switch to Manticore) - since I’m working with a large number of categories the data needs to be sorted by the count or else it is useless:
search on ‘coronavirus’ grouped by specialty