I’m trying to setup Sphinxsearch in a way that it can fully index my MySQL tables. If I’m right everything that’s indexed has to be grabbed by sql_query. Every query can be used but I’m confused on how to apply it to the following tables.
CREATE TABLE books (
book_id INT(10) PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(200),
abstract TEXT
);
CREATE TABLE authors (
author_id INT(10) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(200)
);
CREATE TABLE book_author (
book_author_id INT(10) PRIMARY KEY AUTO_INCREMENT,
book_id INT(10),
author_id INT(10)
);
Now I want to be able to search for something like: Sphinx searching A. Aksyonoff and search in both the authors and the book table. But how am I supposed to combine those results, and get both a list of authors that match and a list of books that match the query. Or is there even a better way? So basicly, what would I have to fill in in sql_query and what should I take as attributes.
I tried using JOINs but when there are multiple authors, I lose track.
One way
That will give you an index:
One document per book – title and abstract fully searchable.
List of authors in the
authorsfield – so that text queries will match.You also have a MVA attribute
author_idswhich will give you the IDs of authors in results.To get the names again for display purposes can use those ids against the database table (or if the size of the index permits use string attributes).
The MVA could also be used to group by in sphinx – to give you a breakdown of the authors matching a specific text query.