Lucene.NET-与AND在多个字段中搜索多个单词 [英] Lucene.NET - do an AND search multiple words on multiple fields

查看:195
本文介绍了Lucene.NET-与AND在多个字段中搜索多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的产品实体定义一个Document对象,该对象具有几个字段:标题,品牌,类别,大小,颜色,材料.

I define a Document object for my product entity which has several fields: Title, Brand, Category, Size, Color, Material.

现在,我想支持用户对多个字段进行AND搜索.具有一个,两个或多个字段包含所有搜索词的任何文档都将得到响应.

Now I want to support user to do an AND search on multiple fields. Any document that have one, two or more fields contain all the search words will be responded.

例如,当用户输入"gucci shirt red"时,我想返回具有与所有3个标记"gucci","shirt"和"red"匹配的字段的所有文档.因此,下面的所有文档都会得到答复:

For example, when user enter "gucci shirt red" I want to return all documents that have fields matched with all 3 tokens "gucci", "shirt" AND "red". So all documents below will be responded:

1.带标题的文档包含所有3个词,例如Title ="Gucci Modern Shirt Red"或"Gucci blue shirt" ...

1.Documents with title contains all the 3 words, for example Title = "Gucci Modern Shirt Red" or "Gucci blue shirt"...

2.标题为"Gucci经典衬衫"且颜色为红色"的文档

2.Documents with Title = "Gucci classical shirt" AND Color = "red"

3.Documents(类别=男式衬衫" AND Brand ="gucci" AND Color =红色"

3.Documents with Category = "mens shirt" AND Brand = "gucci" AND Color = "red"

4.etc.

我知道Lucene支持+运算符,它必须对搜索查询进行操作.例如,我可以翻译上面的关键字以查询"+ gucci + shirt + red",那么我肯定上面示例(1)的文档将得到响应.但这对上面的情况(2)和(3)有用吗?

I know that Lucene support operator + that do a MUST for search query. For example I can translate the above keyword to query "+gucci +shirt +red" then I'm sure documents of example (1) above will definitely be responded. But does it work for cases (2) and (3) above ?

推荐答案

否,如果没有在查询中提供明确搜索的字段,它将转到默认字段,该默认字段将显示为您的标题"案子.您将需要一个类似以下的查询:

No, when not given a a field to search explicitly in the query, it will go to the default field, which it would appear is the "title" in your case. You would need a query more like:

+shirt +color:red +brand:gucci

例如.

或者,一种常见用法是设置捕获全部"字段,在该字段中将所有(或大子集)可搜索数据混搭在一起,从而使您可以在该字段上以非常宽松的方式搜索所有内容.情况下,您只需要使用以下内容即可:

Or, one common usage is to set up a catch all field, in which all (or a large subset) of searchable data is mashed together, allowing you to search everything in a very loose fashion, on that field, in which case you would just use something like:

all:(+shirt +gucci +red)

或者,如果您将该字段设置为默认字段,则:

Or, if you made that field your default field instead:

+shirt +gucci +red

如您所述.

这篇关于Lucene.NET-与AND在多个字段中搜索多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆