D
D
d1mvla5off2019-07-08 08:51:20
Sphinx
d1mvla5off, 2019-07-08 08:51:20

How to search for multiple matches grouped by some field?

Analogue in sql:

select
    distinct
    group_id,
    text
from index_1 as i1
where text like '%search_text_1%'
    and exists (select 1 from index_1 as i2 where i2.group_id = i1.group_id and i2.text like
    '%search_text_2%')

An attempt on the Sphinx:
select
    group_id,
    text
from index_1
where match('@text %search_text_1%')
...?
group by group_id

Tell me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-07-08
@tumbler

The query looks like "find a group for which one document has one text, and another (or the same) has another". It seems to me that you need to make an index in which the document is a group, and just look for both matches at once. Why is that:

  • If you search by "AND", then there will be only group documents in which there is both one and the other text (i.e. the situation "in another document the second text" is not found)
  • If you search by "OR" and then filter the results by HAVING COUNT(*) > 1, then you get extra results (2 documents with the first text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question