我正在使用apache solr来获取我的webapp的匹配功能,我遇到了这种情况的问题:
我有三个程序员,技能领域是他们的技能,“重量”意味着他/她的技能有多好:
{
name: "John",
skill: [
{name: "java", weight: 90},
{name: "oracle", weight: 90},
{name: "linux", weight: 70}
]
},
{
name: "Sam",
skill: [
{name: "C#", weight: 98},
{name: "java", weight: 75},
{name: "oracle", weight: 70},
{name: "tomcat", weight: 70},
]
},
{
name: "Bob",
skill: [
{name: "oracle", weight: 90},
{name: "java", weight: 85}
]
}
我有找工程师的工作:
{
name: "webapp development",
skillRequired: [
{name: "java", weight: 85},
{name: "oracle", weight: 85},
]
}
我想使用这份工作的“技能要求”来匹配那些程序员(找到最适合这份工作的人)。在这种情况下,应该是John和Bob,Sam因为他的java和oracle技能不够好而被踢掉了。约翰应该比鲍勃得分更高,因为他更了解甲骨文。
问题是,solr无法索引嵌套对象,我认为我能得到的最佳格式是:
name: "John",
skill-name: ["java", "oracle", "linux"],
skill-weight: [90, 90, 70]
等等。所以我不知道是否可以构建一个查询来使这个场景有效。
是否有更好的架构结构?或使用索引/查询时间提升?
我几乎阅读了所有的solr wiki和google,没有运气,欢迎任何提示和解决方法。
问题已解决,请在此处记录我的解决方案以寻求帮助:
第一,我的数据格式是json,所以我需要solr-4.8.0来支持使用json的索引嵌套数据。如果数据是xml格式,solr-4.7.2仍然可以工作。
2,solr-4.8.0需要java7-u55(官方推荐)
3,嵌套文档/对象应通过“ childDocuments ”键提交给solr。为了识别父/子文档的类型,我添加了“type”字段。所以上面的例子看起来像这样:
{
type: "programmer",
name: "John",
_childDocuments_: [
{type:"skill", name: "java", weight: 90},
{type:"skill", name: "oracle", weight: 90},
{type:"skill", name: "linux", weight: 70}
]
},
{
type: "programmer",
name: "Sam",
_childDocuments_: [
{type:"skill",name: "C#", weight: 98},
{type:"skill", name: "java", weight: 75},
{type:"skill", name: "oracle", weight: 70},
{type:"skill", name: "tomcat", weight: 70},
]
},
{
type: "programmer",
name: "Bob",
_childDocuments_: [
{type:"skill", name: "oracle", weight: 90},
{type:"skill", name: "java", weight: 85}
]
}
第4,提交并提交到solr后,我可以将作业与块连接查询匹配(在过滤查询中):
fq={!parent which='type:programmer'}type:skill AND name:java AND weight:[85 TO *]&
fq={!parent which='type:programmer'}type:skill AND name:oracle AND weight:[85 TO *]