I have an index:
--------------------------------------------------
| id | name | folder | tag1 | tag2 | topic |
--------------------------------------------------
| 1 | file 1 | AAA | [1,2] | [3,4] | 1 |
--------------------------------------------------
| 2 | file 2 | BBB | [1] | [4,5] | 1 |
--------------------------------------------------
| 3 | file 3 | AAA | [2] | [4] | 2 |
--------------------------------------------------
What I need to do is to filter files by tag and the following request works fine:
SELECT id, name,
ANY(var=1 FOR var IN tag1) as tag_filter_1,
ANY(var=5 FOR var IN tag2) as tag_filter_2,
GROUP_CONCAT(id) as files
FROM index
WHERE tag_filter_1 = 1 AND tag_filter_2 = 1
GROUP BY topic;
Now I need to modify the query to apply the tag1 filter only for the files from AAA folder and at the same time keep filtering by tag2 from all the folders.
I was thinking about OR condition but it's not supported. Also, the option was to use GROUP_CONCAT(tag1) and then filter the Sphinx results in PHP but tag1 is JSON, not scalar.
I am wondering if it's possible to solve this using SNIPPET or IF function and how. Or any other ideas?