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

每个Lucene doc都是一个配方,每个配方都有成分.

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

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

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

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

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")

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...