L
L
leetnigga2018-02-20 16:46:03
MySQL
leetnigga, 2018-02-20 16:46:03

How to search in Sphinx given a bunch of attributes?

Hello.
There is a MySQL database with several million rows.
The main table in it looks like:
ID | text | ... a dozen flag fields ...
Depending on the checkboxes in the search query form, several more tables of the table type (ID | Parent_ID | Data) can join to it.
Currently, a typical request looks like this:

SELECT * FROM table
JOIN child_table on (table.ID = child_table.Parent_ID)
JOIN child_table2 on (table.ID = child_table2.Parent_ID)
...
WHERE 
table.Flag1 = '...' 
AND table.Flag2 = '...' 
AND child_table.Data = '...' 
AND child_table2.Data = '...'

Sometimes, in addition to these flag fields, it is necessary to search for the Text field in the table:
SELECT * FROM table
JOIN child_table on (table.ID = child_table.Parent_ID)
JOIN child_table2 on (table.ID = child_table2.Parent_ID)
...
WHERE 
table.Flag1 = '...' 
AND table.Flag2 = '...' 
AND child_table.Data = '...' 
AND child_table2.Data = '...' 
AND MATCH(table.Text) AGAINST ('....')

Naturally, full-text search from mysql slows down at such volumes. To get rid of the brakes, I decided to use the Sphinx, but I ran into a problem: how to build an index in it correctly?
That is:
- should I drive all these flags (including those from child tables) into the Sphinx index (via rt_attr_uint, for example), and look for all the data in it, or
- I filter in MySQL only by flags = I get a list of IDs, then I filter in Sphinx only by text = I get another list, then I find the intersection of these lists = my result, or
- some other option?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Puma Thailand, 2018-02-20
@leetnigga

Drive everything into the sphinx

O
Oleg, 2018-02-21
@402d

The sphinx has multi attributes. But if you don't like it, you can de-anomalize by making a text field where to collect them.
Priz99998k Priz33334k.
PrefixIdSufix space and so on

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question