How do I return multiple documents that share indexes efficiently?

StackOverflow https://stackoverflow.com/questions/21908380

  •  14-10-2022
  •  | 
  •  

Вопрос

I'm indexing some data using Sphinx. I have objects that are categorised and the categories have a heirarchy. My basic table structure is as follows:

Objects
| id | name |
| 1  | ABC  |
| 2  | DEF  |
...

Categories
| id | name          | parent_id |
| 1  | My Category   | 0         |
| 2  | A Child       | 1         |
| 3  | Another Child | 1         |
...

Object_Categories
| object_id | category_id |
| 1         | 2           |
| 2         | 3           |
...

My config currently is:

sql_query = SELECT categories.id, objects.name, parent_id FROM categories \
    LEFT JOIN object_categories ON categories.id = object_categories.category_id \
    LEFT JOIN objects ON objects.id = object_categories.object_id

sql_attr_uint = parent_id

This returns category IDs for any categories that contain objects that match my search, but I need to make an adjustment to get objects in that category or any of it's children.

Obviously, I could UNION this query with another that gets ID from matched categories parents, and so on (it could be up to 4 or 5 levels deep), but this seems hugely inefficient. Is there a way to return multiple document IDs in the first field, or to avoid repeated needless indexing?

I'm a Sphinx noob, so I'm not sure how to approach the problem.

Это было полезно?

Решение

See http://www.sitepoint.com/hierarchical-data-database/

its talking about a database, but the same system works equally well within sphinx. It can take a while to get your head around, but its well worth mastering (IMHO!).

(ie add the left/right columns to the database, and then include them as attributes in the sphinx index)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top