A
A
Andrey Sidorov2016-07-22 19:32:41
Sphinx
Andrey Sidorov, 2016-07-22 19:32:41

How to search in Sphinx in one table, and take data from another?

Good afternoon, I read various examples and could not figure it out.
I have one table like this:
product_values

product_id |          name             |         values 
-------------------------------------------------------------------------------
         1       |   Product One         |       soft touch plastic, big screen 
         2       |   Product Two         |       small screen, metal 
         3       |   Product Three      |       plastic, 5" screen, 4G

And there is another one, where one product can be located on several lines (in fact, this is a view from several tables, but not the point):
product_full
product_id            |    category_name    | color     | other_values
--------------------------------------------------------------------------------
           1        |       phone         |    black |         exclusive, vip, gold
           1        |       mobile        |    red    |         exclusive, vip, silver
           1        |       telecom      |     gold  |         vip, gold, powerfull
           2        |       phone         |     black |         dark,cheap, etc.
           2        |       telecom      |      red    |         for girls, vip, exclusive

In the first table, I am looking for products that match the request, and in the second table, structured data for output to the frontend. How can I look for suitable product_id in the first table, and then select these id in the second? It seems to me that if I get the product ID and then query them in mysql , then this will be a very crooked solution.
PS Search only in the first table is necessary, in the second it is not necessary to search. Only extract data by product_id
PS It seems that I found a solution, but it does not suit me - too many duplicate fields will need to be created, as well as many fields to be selected when searching:
sql_query = SELECT product_values.name, product_values.values, \ 
product_full.category_name, product_full.color, product_full.other_values \
FROM product_values \
INNER JOIN product_full ON (product_full.product_id=product_values.product_id);

А при поиске указывать ... MATCH('@name Product @values screen')

Considering that there are a lot of fields in the tables and they are sometimes duplicated, it somehow looks redundant, although it is quite a working option

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Пума Тайланд, 2016-07-22
@opium

ищите сфинксом, а данные выбирайте в sql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question