按友谊程度对 Solr 结果进行排序
我目前使用 Solr 1.4(很快就会升级到 3.3)。友谊表非常标准:
id | follower_id | user_id
我想执行常规关键字 solr 搜索并按分离程度以及标准分数排序对结果进行排序。从结果集中来看,如果关键字与我的任何直接朋友相匹配,他们就会首先出现。其次是我朋友的朋友,第三是第三度分离的朋友。所有其他结果都会随之而来。
我非常确定 Solr 不提供任何“预烘焙”方式来执行此操作,因此我可能必须在 MySQL 上进行连接才能正确排序结果。好奇是否有人以前做过这个和/或有一些见解。
I am currently using Solr 1.4 (soon to upgrade to 3.3). The friendship table is pretty standard:
id | follower_id | user_id
I would like to perform a regular keyword solr search and order the results by degrees of separation as well as the standard score ordering. From the result set, given the keyword matched any of my immediate friends, they would show up first. Secondly would be the friends of my friends, and thirdly friends by 3rd degree of separation. All other results would come after.
I am pretty sure Solr doesn't offer any 'pre-baked' way of doing this therefore I would likely have to do a join on MySQL to properly order the results. Curious if anyone has done this before and/or has some insights.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这在 Solr 中根本不可能。但是,如果您没有太多限制并且可以使用其他平台来实现此目的,请考虑 Neo4j?
这个“连接”和度正是 Neo4j 介入的地方。
http://neo4j.org/
It's simply not possible in Solr. However, if you aren't too restricted and could use another platform for this, consider neo4j?
This "connections" and degrees is exactly where Neo4j steps in.
http://neo4j.org/
一种方法可能是创建
level_1
、level_2
等字段,并将度数 x 的好友列表存储在level_x 字段中
。然后,您可以触发多个查询 - 第一个查询将结果限制为level_1
中包含您的结果,第二个查询将结果限制为level_2
中包含您的结果,依此类推。这有点复杂,但我能想到的唯一解决方案是使用 Solr。
One way might be to create fields like
degree_1
,degree_2
etc. and store the list of friends at degree x in the fielddegree_x
. Then you could fire multiple queries - the first restricting the results to those who have you indegree_1
, the second restricting the results to those who have you indegree_2
and so on.It is a bit complicated, but the only solution I could think of using Solr.
我以前没有在 solr 中表示过图表,但我认为在较高的层次上,这就是你可以做的。首先,将人表示为节点,将社交网络表示为数据库中的图。实现传递闭包 sql 中的函数允许您遍历图形。然后,您将结果索引到 solr 中,并将社交网络信息存储到 有效负载,用于示例。
I haven't represented a graph in solr before, but I think at a high level, this is what you could do. First, represent people as nodes and the social network as a graph in the database. Implement transitive closure function in sql to allow you to walk the graph. Then you would index the result into solr with the social network info stored into payloads, for example.
我能够通过执行多个查询并使用范围“with”来限制同事、第二级和第三级同事的 ID,使用 ID 并使用 mysql 进行选择来实现此目的。
这有点肮脏的解决方案,因为我必须执行多个 solr 查询,但在我可以使用动态字段排序选项(solr 3.3,目前不受太阳黑子支持)之前,我真的不知道有任何其他方法可以实现此目的。
I was able to achieve this by performing multiple queries and with the scope "with" to restrict to the id's of colleagues, 2nd and 3rd degree colleagues, using the id's and using mysql to do the select.
It's kinda of a dirty solution as I have to perform multiple solr queries, but until I can use dynamic field sorting options (solr 3.3, not currently supported by sunspot) I really don't know any other way to achieve this.