如何为sphinx中的镶嵌面对MVA字段进行分组

如何为sphinx中的镶嵌面对MVA字段进行分组,sphinx,Sphinx,我有一个索引,其中一些数据是重复的,除了纬度、经度和id之外,所有字段都是相似的(字段id不是真实id,只是生成了行号()作为id) 例如: mysql> select id,vacancy_id,prof_area_ids,latitude,longitude from jobVacancy; +------+------------+---------------+----------+-----------+ | id | vacancy_id | prof_area_ids |

我有一个索引,其中一些数据是重复的,除了纬度、经度和id之外,所有字段都是相似的(字段id不是真实id,只是生成了
行号()作为id

例如:

mysql> select id,vacancy_id,prof_area_ids,latitude,longitude from jobVacancy;
+------+------------+---------------+----------+-----------+
| id   | vacancy_id | prof_area_ids | latitude | longitude |
+------+------------+---------------+----------+-----------+
|    1 |        917 | 11,199,202    | 0.973178 |  0.743566 |
|    2 |        916 | 17,283,288    | 0.973178 |  0.743566 |
|    3 |        915 | 17,288        | 0.973178 |  0.743566 |
|    4 |        914 | 30,482        | 0.973178 |  0.743566 |
|    5 |        919 | 15,243        | 0.825153 |  0.692837 |
|    6 |        919 | 15,243        | 0.825162 |  0.692828 |
|    7 |        918 | 8,154         | 0.825153 |  0.692837 |
|    8 |        918 | 8,154         | 0.825162 |  0.692828 |
|    9 |        920 | 17,283,288    | 0.958914 |  1.282161 |
|   10 |        920 | 17,283,288    | 0.958915 |  1.282215 |
|   11 |        924 | 12,208        |  0.97333 |  0.658246 |
|   12 |        924 | 12,208        | 0.973336 |  0.658237 |
|   13 |        923 | 21,365        |  0.97333 |  0.658246 |
|   14 |        923 | 21,365        | 0.973336 |  0.658237 |
|   15 |        922 | 20,359        |  0.97333 |  0.658246 |
|   16 |        922 | 20,359        | 0.973336 |  0.658237 |
|   17 |        921 | 19,346        |  0.97333 |  0.658246 |
|   18 |        921 | 19,346        | 0.973336 |  0.658237 |
|   19 |        926 | 12,17,208,292 |  0.88396 |  2.389868 |
|   20 |        925 | 12,208        |  0.88396 |  2.389868 |
+------+------------+---------------+----------+-----------+
20 rows in set (0.00 sec)
现在我想按
空缺\u id

mysql> select id,vacancy_id,prof_area_ids,latitude,longitude from jobVacancy group by vacancy_id;
+------+------------+---------------+----------+-----------+
| id   | vacancy_id | prof_area_ids | latitude | longitude |
+------+------------+---------------+----------+-----------+
|    1 |        917 | 11,199,202    | 0.973178 |  0.743566 |
|    2 |        916 | 17,283,288    | 0.973178 |  0.743566 |
|    3 |        915 | 17,288        | 0.973178 |  0.743566 |
|    4 |        914 | 30,482        | 0.973178 |  0.743566 |
|    5 |        919 | 15,243        | 0.825153 |  0.692837 |
|    7 |        918 | 8,154         | 0.825153 |  0.692837 |
|    9 |        920 | 17,283,288    | 0.958914 |  1.282161 |
|   11 |        924 | 12,208        |  0.97333 |  0.658246 |
|   13 |        923 | 21,365        |  0.97333 |  0.658246 |
|   15 |        922 | 20,359        |  0.97333 |  0.658246 |
|   17 |        921 | 19,346        |  0.97333 |  0.658246 |
|   19 |        926 | 12,17,208,292 |  0.88396 |  2.389868 |
|   20 |        925 | 12,208        |  0.88396 |  2.389868 |
|   21 |        961 | 4,105         | 0.959217 |  1.280721 |
|   23 |        960 | 8,155         | 0.959217 |  1.280721 |
|   25 |        959 | 12,208        | 0.959217 |  1.280721 |
|   27 |        928 | 1,60          | 0.963734 |  1.070297 |
|   29 |        927 | 32,513        | 0.963734 |  1.070297 |
|   31 |        929 | 6,140         | 0.786553 |  0.678649 |
|   33 |        932 | 1,40,46       | 0.824627 |  0.694182 |
+------+------------+---------------+----------+-----------+
20 rows in set (0.00 sec)
结果太棒了!但当我想用facet获取所有分组数据时,问题就开始了

mysql> select id,vacancy_id,prof_area_ids,latitude,longitude from jobVacancy where prof_area_ids=199 group by vacancy_id facet prof_area_ids;
+------+------------+-----------------+----------+-----------+
| id   | vacancy_id | prof_area_ids   | latitude | longitude |
+------+------------+-----------------+----------+-----------+
|    1 |        917 | 11,199,202      | 0.973178 |  0.743566 |
|  191 |       1004 | 11,196,199      | 0.925335 |  2.768874 |
|  313 |       1072 | 1,11,60,197,199 | 0.963968 |  1.070624 |
|  318 |       1136 | 11,196,199      |  0.96071 |  1.448998 |
|  374 |       1097 | 11,199          | 0.785255 |  0.678504 |
+------+------------+-----------------+----------+-----------+
5 rows in set (0.00 sec)

+---------------+----------+
| prof_area_ids | count(*) |
+---------------+----------+
|           202 |        1 |
|           199 |       12 |
|            11 |       12 |
|           196 |        5 |
|           197 |        3 |
|            60 |        3 |
|             1 |        3 |
+---------------+----------+
7 rows in set (0.02 sec)
切面结果不正确。因为事实上,prof_area_id=199的数据计数必须是5,而不是12。那个么,我如何才能为faceted对字段进行分组呢

额外的 我在这里说过,但我只是写了“如果你有一个MVA方面,你需要使用GROUPBY()函数,它返回进行分组的实际值。”并且没有examle

mysql> select id,vacancy_id,prof_area_ids,latitude,longitude,GROUPBY() as selected,COUNT(*) from jobVacancy where prof_area_ids=199 group by vacancy_id facet prof_area_ids;
+------+------------+-----------------+----------+-----------+----------+----------+
| id   | vacancy_id | prof_area_ids   | latitude | longitude | selected | count(*) |
+------+------------+-----------------+----------+-----------+----------+----------+
|    1 |        917 | 11,199,202      | 0.973178 |  0.743566 |      917 |        1 |
|  191 |       1004 | 11,196,199      | 0.925335 |  2.768874 |     1004 |        2 |
|  313 |       1072 | 1,11,60,197,199 | 0.963968 |  1.070624 |     1072 |        3 |
|  318 |       1136 | 11,196,199      |  0.96071 |  1.448998 |     1136 |        3 |
|  374 |       1097 | 11,199          | 0.785255 |  0.678504 |     1097 |        3 |
+------+------------+-----------------+----------+-----------+----------+----------+
5 rows in set (0.00 sec)

+---------------+----------+
| prof_area_ids | count(*) |
+---------------+----------+
|           202 |        1 |
|           199 |       12 |
|            11 |       12 |
|           196 |        5 |
|           197 |        3 |
|            60 |        3 |
|             1 |        3 |
+---------------+----------+
7 rows in set (0.02 sec)
同样,刻面的结果是错误的

切面结果不正确。因为事实上,prof_area_id=199的数据计数必须是5,而不是12。那个么,我如何才能为faceted对字段进行分组呢

看起来您误解了FACET的工作原理。在我看来,您认为它以主查询的结果为基础,但实际上它只是进行另一个分组。例如,这里:

mysql> select g, t from idx_mva where t = 11 group by g facet t;
+------+----------+
| g    | t        |
+------+----------+
|    1 | 11,12    |
|    2 | 11,13,15 |
|    3 | 9,11     |
|    5 | 11,12,15 |
+------+----------+
4 rows in set (0.00 sec)

+------+----------+
| t    | count(*) |
+------+----------+
|   12 |        2 |
|   11 |        6 |
|   15 |        4 |
|   13 |        1 |
|    9 |        1 |
|    3 |        1 |
+------+----------+
6 rows in set (0.00 sec)
对于t=11,您可以看到在第一个查询的结果中发现了3次,但在FACET的查询结果中,这一点的计数是6。这是因为它在索引中实际发生6次:

mysql> select * from idx_mva where t = 11;
+------+------+----------+
| id   | g    | t        |
+------+------+----------+
|    2 |    1 | 11,12    |
|    3 |    1 | 11,15    |
|    3 |    2 | 11,13,15 |
|    6 |    3 | 9,11     |
|    8 |    5 | 11,12,15 |
|   11 |    2 | 3,11,15  |
+------+------+----------+
6 rows in set, 1 warning (0.00 sec)
在第一种情况下会发生3次,因为每个组只返回一次t值。您可以使用group_concat()查看同一组中的更多值:

mysql> select g, group_concat(to_string(t)) from idx_mva where t = 11 group by g facet t;
+------+----------------------------+
| g    | group_concat(to_string(t)) |
+------+----------------------------+
|    1 | 11,12,11,15                |
|    2 | 11,13,15,3,11,15           |
|    3 | 9,11                       |
|    5 | 11,12,15                   |
+------+----------------------------+
4 rows in set (0.00 sec)

+------+----------+
| t    | count(*) |
+------+----------+
|   12 |        2 |
|   11 |        6 |
|   15 |        4 |
|   13 |        1 |
|    9 |        1 |
|    3 |        1 |
+------+----------+
6 rows in set (0.00 sec)
如果你想了解更多关于刻面的知识,这里有一个互动课程-

切面结果不正确。因为事实上,prof_area_id=199的数据计数必须是5,而不是12。那个么,我如何才能为faceted对字段进行分组呢

看起来您误解了FACET的工作原理。在我看来,您认为它以主查询的结果为基础,但实际上它只是进行另一个分组。例如,这里:

mysql> select g, t from idx_mva where t = 11 group by g facet t;
+------+----------+
| g    | t        |
+------+----------+
|    1 | 11,12    |
|    2 | 11,13,15 |
|    3 | 9,11     |
|    5 | 11,12,15 |
+------+----------+
4 rows in set (0.00 sec)

+------+----------+
| t    | count(*) |
+------+----------+
|   12 |        2 |
|   11 |        6 |
|   15 |        4 |
|   13 |        1 |
|    9 |        1 |
|    3 |        1 |
+------+----------+
6 rows in set (0.00 sec)
对于t=11,您可以看到在第一个查询的结果中发现了3次,但在FACET的查询结果中,这一点的计数是6。这是因为它在索引中实际发生6次:

mysql> select * from idx_mva where t = 11;
+------+------+----------+
| id   | g    | t        |
+------+------+----------+
|    2 |    1 | 11,12    |
|    3 |    1 | 11,15    |
|    3 |    2 | 11,13,15 |
|    6 |    3 | 9,11     |
|    8 |    5 | 11,12,15 |
|   11 |    2 | 3,11,15  |
+------+------+----------+
6 rows in set, 1 warning (0.00 sec)
在第一种情况下会发生3次,因为每个组只返回一次t值。您可以使用group_concat()查看同一组中的更多值:

mysql> select g, group_concat(to_string(t)) from idx_mva where t = 11 group by g facet t;
+------+----------------------------+
| g    | group_concat(to_string(t)) |
+------+----------------------------+
|    1 | 11,12,11,15                |
|    2 | 11,13,15,3,11,15           |
|    3 | 9,11                       |
|    5 | 11,12,15                   |
+------+----------------------------+
4 rows in set (0.00 sec)

+------+----------+
| t    | count(*) |
+------+----------+
|   12 |        2 |
|   11 |        6 |
|   15 |        4 |
|   13 |        1 |
|    9 |        1 |
|    3 |        1 |
+------+----------+
6 rows in set (0.00 sec)

如果你想了解更多关于刻面方面的知识,这里有一个互动课程-

似乎想要在刻面上有效地
计数(不同的空缺_id)
,而不是默认的
计数(*)

... FACET prof_area_ids,COUNT(DISTINCT vacancy_id) AS vacancies BY prof_area_ids
不起作用。before BY只支持属性,不支持自定义函数

。。。我只需要写一段很长的路,带着完整的查询

select id,vacancy_id,prof_area_ids,latitude,longitude from jobVacancy
    where prof_area_ids=199 group by vacancy_id;

SELECT GROUPBY() AS prof_area_id, COUNT(DISTINCT vacancy_id) FROM jobVacancy
    WHERE prof_area_ids=199 GROUP BY prof_area_id;
同样的结果,只是稍微详细一点。与其使用刻面速记,不如写下来
完整输出,作为多个单独的查询

似乎需要有效的
计数(不同的空缺\u id)
,而不是默认的
计数(*)
,但遗憾的是

... FACET prof_area_ids,COUNT(DISTINCT vacancy_id) AS vacancies BY prof_area_ids
不起作用。before BY只支持属性,不支持自定义函数

。。。我只需要写一段很长的路,带着完整的查询

select id,vacancy_id,prof_area_ids,latitude,longitude from jobVacancy
    where prof_area_ids=199 group by vacancy_id;

SELECT GROUPBY() AS prof_area_id, COUNT(DISTINCT vacancy_id) FROM jobVacancy
    WHERE prof_area_ids=199 GROUP BY prof_area_id;
同样的结果,只是稍微详细一点。与其使用刻面速记,不如写下来
完整输出,作为多个单独的查询

实际上我不明白facet是如何工作的。我想显示面计数,但我不能这样做,因为结果实际上是错误的。想象一下这个数字写了12,点击按钮显示5个数据-它将是一个骗局)我只是困惑了,它真的不可能与狮身人面像解决吗?我不明白为什么你认为它是错误的。您的意思是只考虑主查询返回的内容,而不是索引中实际存在的内容吗?
您的意思是只考虑主查询返回的内容,而不是索引中实际存在的内容吗?
-很可能您是对的。因为最初使用的是
按空缺id分组
,所以如果FACET从查询中返回计数就更好了。但据我所知,这是不可能的。也许我会确保这里没有重复的数据,然后FACET对我来说是正确的。我实际上不理解FACET是如何工作的。我想显示面计数,但我不能这样做,因为结果实际上是错误的。想象一下这个数字写了12,点击按钮显示5个数据-它将是一个骗局)我只是困惑了,它真的不可能与狮身人面像解决吗?我不明白为什么你认为它是错误的。您的意思是只考虑主查询返回的内容,而不是索引中实际存在的内容吗?
您的意思是只考虑主查询返回的内容,而不是索引中实际存在的内容吗?
-很可能您是对的。因为最初使用的是
按空缺id分组
,所以如果FACET从查询中返回计数就更好了。但据我所知,这是不可能的。也许我会确保这里没有重复的数据,然后再为我计算正确的方面。