具有多对多关系的 sphinx 索引
我正在尝试建立一个在艺术品和流派之间具有基本的多对多关系的 Sphinx 索引:
artworks
---------------
id
title
description
genres
---------------
id
name
artwork_genres
---------------
artworks_id
genres_id
在我的 sphinx 配置文件中,我有类似的内容
source src_artwork {
...
sql_query = SELECT id, title, description FROM artworks
sql_attr_multi = uint tag from query; SELECT id,name FROM genres
}
据我所知,这是来自文档 多值属性 和 sql_attr_multi
但显然那里没有提到绑定表,我无法理解它是如何带入配置中的。我只是想搜索“印象派”以找到属于该流派的艺术品(如果该术语在其他领域中出现,则适当加权)
I am trying to set up a Sphinx index with a basic many-to-many relation between artworks and genres:
artworks
---------------
id
title
description
genres
---------------
id
name
artwork_genres
---------------
artworks_id
genres_id
In my sphinx config file I have something like
source src_artwork {
...
sql_query = SELECT id, title, description FROM artworks
sql_attr_multi = uint tag from query; SELECT id,name FROM genres
}
This is from the docs, as far as I can understand, on multi-valued attributes and sql_attr_multi
But obviously there is no mention of the tie table in there and I can't understand how that is brought into the config. I'd simply like for a search on "Impressionism" to result in artworks belonging to that genre (weighted as appropriate if the term is seen in the other fields)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,我会考虑忽略属性功能。创建用于搜索艺术品的流派字段的最简单方法是将流派表“去规范化”到 sql_query 中。
在 SQL 查询的 FROM 子句中,您可以通过链接表将流派表 JOIN 到艺术品。在 SELECT 子句中,您可以将 GROUP_CONCATgenels.name 放入一列中,该列将成为要搜索的 Sphinx 字段。
您的 sql_query 可能如下所示:
然后,在 @genre 字段中查找“印象派”的艺术品的 sphinx 搜索将返回“行”。
I would consider ignoring the attributes feature in this case. The simplest way to create a genre field by which to search artworks is to "de-normalise" the genres table into the sql_query.
In the FROM clause of your SQL query, you would JOIN the genres table to the artworks via the linking table. In the SELECT clause, you can then GROUP_CONCAT genres.name into a column, which becomes a Sphinx field to search on.
Your sql_query might look like this:
Then a sphinx search for artworks looking for "impressionism" in the @genre field will return the "row".