M
M
Madion2015-01-23 15:31:01
Sphinx
Madion, 2015-01-23 15:31:01

Sphinx how to set up a search on two tables?

Hello!
Today I started to study sphinx in order to "attach" it to working projects. I've been struggling for hours with this task, googling doesn't help.
There are two tables:

tbl_articles 
-------------------------
id | title | category_id

and
tbl_categories
------------------------
id | title

It is necessary that the search goes through the title field in the tbl_articles and tbl_categories tables.
In a config on everyone tried to register.
Written like this:
source articles : init {	
   sql_query = SELECT articles.category_id AS pid, articles.id, articles.title \
        FROM tbl_categories AS tbl_categories, tbl_articles AS articles \
        WHERE tbl_categories.id = articles.category_id \
  
   sql_attr_multi = uint pid from query; SELECT id, category_id FROM tbl_articles
}

As a result, it searches only by the title of the tbl_categories table.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2015-01-23
@Arik

It has not worked for a long time, but the first value was always id, the rest gets into the search!
the rest (sql_attr_*) are attributes, if you need to add a condition. for example, only by catId = 7, etc.

source articles : init 
    {	
    sql_query = SELECT a.`id`, a.`title`, b.`title` as `catTitle` FROM `tbl_articles` AS a LEFT JOIN `tbl_categories` AS b ON b.`id` = a.`category_id`
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question