zend-framework – 具有相同性质的多个字段的Lucene索引

前端之家收集整理的这篇文章主要介绍了zend-framework – 具有相同性质的多个字段的Lucene索引前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每个Lucene doc都是一个配方,每个配方都有成分.

我努力寻找成分,并给出一个结果,说两个成分匹配四个. (例如)@H_404_2@

那么如何将这些成分添加到doc中呢?在solr我可以创建多个字段,它会将它们全部保存,我可能做错了,因为它只保存了一个成分.@H_404_2@

这也适用于像’tags’这样的字段.@H_404_2@

p.s我使用Zend框架,如果它很重要.@H_404_2@

Lucene文档支持添加多个同名字段.即你可以反复打电话:
document.add(new Field("name"),value)

所以你这样做:@H_404_2@

# (pseudo-code) 
document1.add(new Field("ingredient"),"vanilla") 
document1.add(new Field("ingredient"),"strawberry") 
index.add(document)

# And then search for
index.search("ingredient","vanilla" && "strawberry")

你会得到回文件1.但是如果你搜索:@H_404_2@

index.search("ingredient","vanilla" && "apple")

你不会得到document1.@H_404_2@

如果您搜索:@H_404_2@

index.search("ingredient","vanilla" || "apple")

你也可以找回document1.@H_404_2@

如果要查看哪些成分匹配,只需将文档上的字段保存为存储字段,然后为每个匹配的文档检索字段列表并将其与用户查询进行比较.@H_404_2@

另请注意,默认情况下,添加到文档的具有相同名称的字段的PositionIncrementGap为0.@H_404_2@

这意味着,如果你添加:@H_404_2@

document1.add(new Field("ingredient"),"chocolate") 
   document1.add(new Field("ingredient"),"orange")

然后它会被视为一种叫做“巧克力橙”的单一成分,可能与之匹配:@H_404_2@

index.search("ingredient","chocolate orange")

你可以避免为PositionIncrementGap>设置一个值. 1,将产生:@H_404_2@

0场比赛:@H_404_2@

index.search("ingredient","chocolate orange")

和1匹配:@H_404_2@

index.search("ingredient","chocolate" &&  "orange")

猜你在找的PHP相关文章