
[英]Zend Lucene & Symfony: One big index vs several multiple indexes
[英]Lucene index with multiple fields of the same nature
每个Lucene doc都是一个配方,每个配方都有成分。
我努力寻找成分,并给出一个结果,说两个成分匹配四个。 (例如)
那么如何将这些成分添加到doc中呢? 在solr我可以创建多个字段,它会将它们全部保存,我可能做错了,因为它只保存了一个成分。
这也适用于像'tags'这样的字段。
ps我正在使用Zend Framework,如果它很重要的话。
Lucene文档支持添加多个同名字段。 即你可以反复打电话:
document.add(new Field("name"), value)
所以你这样做:
# (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。 但是如果你搜索:
index.search("ingredient", "vanilla" && "apple")
你不会得到document1 。
如果您搜索:
index.search("ingredient", "vanilla" || "apple")
你也可以找回document1 。
如果要查看哪些成分匹配,只需将文档上的字段保存为存储字段,然后为每个匹配的文档检索字段列表并将其与用户查询进行比较。
另请注意,默认情况下,添加到文档的具有相同名称的字段的PositionIncrementGap为0。
这意味着,如果你添加:
document1.add(new Field("ingredient"), "chocolate")
document1.add(new Field("ingredient"), "orange")
然后它会被视为一种叫做“巧克力橙”的单一成分,可能与之匹配:
index.search("ingredient", "chocolate orange")
您可以避免为PositionIncrementGap> 1设置一个值,这将产生:
0场比赛:
index.search("ingredient", "chocolate orange")
和1匹配:
index.search("ingredient", "chocolate" && "orange")
我在这里看到两种可能的方法:
我建议你尝试第二种方法,看看它是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.