Facet a Mutli-value(MVA) type field in sphinx

34 Views Asked by At

I have executed below query in sphinx,

select MVA_FIELD from mySphinxIndex  facet MVA_FIELD order by count(*) desc;

What I got is like,

+----------------------------+----------+
| MVA_FIELD                  | count(*) |
+----------------------------+----------+
|                            |      664 |
| 0                          |      536 |
| 13                         |      439 |
| 4,13                       |        8 |
| 19,13                      |        8 |
| 18,13,20                   |        8 |
| 8,17,18                    |        8 |
| 8,18,13                    |        8 |
| 8,15,18                    |        8 |
| 8,13,20                    |        7 |
| 17,13                      |        7 |
| 18,19,20                   |        7 |
| 8,17                       |        7 |
| 13,17,19                   |        7 |
| 11,6                       |        7 |
| 6,11,13                    |        7 |
| 15,18                      |        7 |
| 11,13,20                   |        7 |
| 11,13,17                   |        7 |
| 6,18,19                    |        6 |
| 7,20                       |        6 |
| 8,11,13                    |        6 |
| 13,17,20                   |        6 |

I want to get the count of each ids in MVA_FIELD. For example, I just want the count of 0, 4, 13,... each id separately. How to achieve this ?

1

There are 1 best solutions below

1
barryhunter On

Honestly dont how how to do it with FACET suger, but with a normal GROUP BY query, would just use the GROUPBY() function when grouping by a MVA attribute

SELECT GROUPBY() AS value,COUNT(*) FROM mySphinxIndex GROUP BY MVA_FIELD ORDER BY COUNT(*) DESC;

From the docs

  • A special GROUPBY() function is also supported. It returns the GROUP BY key. That is particularly useful when grouping by an MVA value, in order to pick the specific value that was used to create the current group.