граненый поиск поля с несколькими значениями - PullRequest
0 голосов
/ 07 января 2020

У меня есть таблица, где поле с несколькими значениями запятой:

+------+---------------+
| id   | education_ids |
+------+---------------+
|    3 | 7,5           |
|    4 | 7,3           |
|    5 | 1,5           |
|    8 | 3             |
|    9 | 5,7           |
|   11 | 9             |
...
+------+---------------+

, когда я пытаюсь использовать фасетный поиск:

select id,education_ids from jobResume facet education_ids;

Я получаю этот ответ:

+---------------+----------+
| education_ids | count(*) |
+---------------+----------+
| 7,5           |     3558 |
| 7,3           |     3655 |
| 1,5           |     3686 |
| 3             |    31909 |
| 5,7           |     3490 |
| 9             |    31743 |
| 9,6           |     3535 |
| 8,2           |     3547 |
| 6,2,7         |      291 |
| 7,8,1         |      291 |
| 1,2           |     3637 |
| 7             |    31986 |
| 5,9,7         |      408 |
| 1,1,5         |      365 |
| 5             |    31768 |
| 3,8,3,7       |       32 |
| 3,7,6         |      431 |
| 2             |    31617 |
| 5,5           |     3614 |
| 9,9,2,2       |        6 |
+---------------+----------+

но это не то, что я хотел увидеть. Я хотел бы, чтобы у каждого значения был свой счет, например, здесь:

+---------------+----------+
| education_ids | count(*) |
+---------------+----------+
|            10 |      961 |
|            11 |     1653 |
|            12 |     1998 |
|            13 |     2090 |
|            14 |     1058 |
|            15 |      347 |
...
+---------------+----------+

можно ли получить такой результат с помощью sphinx?

1 Ответ

1 голос
/ 07 января 2020

Убедитесь, что вы используете MVA, а не строковый атрибут:

index rt
{
    type = rt
    rt_field = f
    rt_attr_multi = education_ids
    path = rt
}

snikolaev@dev:$ mysql -P9306 -h0
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 3.2.2 62ea5ff@191220 release

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> insert into rt(education_ids) values((7,5)), ((7,3)), ((7,1)), ((5,1)), ((5,3));
Query OK, 5 rows affected (0.00 sec)

mysql> select * from rt facet education_ids;
+---------------------+---------------+
| id                  | education_ids |
+---------------------+---------------+
| 2810610458032078849 | 5,7           |
| 2810610458032078850 | 3,7           |
| 2810610458032078851 | 1,7           |
| 2810610458032078852 | 1,5           |
| 2810610458032078853 | 3,5           |
+---------------------+---------------+
5 rows in set (0.00 sec)

+---------------+----------+
| education_ids | count(*) |
+---------------+----------+
|             7 |        3 |
|             5 |        3 |
|             3 |        2 |
|             1 |        2 |
+---------------+----------+
4 rows in set (0.00 sec)

Кстати, вот интерактивный курс об огранке в Sphinx / Manticore, если вы хотите узнать больше об этом - https://play.manticoresearch.com/faceting/

...