使用Examine和Lucene.Net查询以逗号分隔的ID列表? [英] Querying against a comma separated list of IDs with Examine and Lucene.Net?

查看:68
本文介绍了使用Examine和Lucene.Net查询以逗号分隔的ID列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Exum for Umbraco(基于Lucene.net构建)进行搜索.我很确定我的问题与Lucene有关.

I am using Examine for Umbraco (which is built on top of Lucene.net) to do my search. I am quite sure my problem is Lucene related.

我的一个字段包含逗号分隔的ID列表.如何以正确的方式查询此字段?

One of my fields contains a list of comma separated IDs. How do I query this field in the right way?

例如.我有一个值为"64,65"的字段.我尝试使用MultipleCharacterWildcard,它仅在查询ID 64时返回结果,而在查询ID 65时不返回结果.SingleCharacterWildcard不返回任何内容,而Fuzzy仅在字段中只有一个ID时才返回内容.关于如何进行正确搜索的任何想法?我猜我正在寻找的是包含"查询.

Eg. I have a field with the values "64,65". I have tried using MultipleCharacterWildcard which only returns a result if I query for the ID 64, but not for ID 65. SingleCharacterWildcard does not return anything, and Fuzzy only returns something if there is only one ID in the field. Any ideas of how to do a proper search? I guess what I am looking for is a "Contains"-query.

这也是处理逗号分隔列表字段的正确方法吗?还是最好将逗号分隔列表拆分为单个字段?

Also is this the right way to handle fields with comma separated lists or would it be better to instead split the comma separated list up into individual fields?

推荐答案

我当然会将列表拆分成单独的字段.您可以在文档中为同一个字段名称使用多个值,这是代表一组值的一种很自然的方式:

I would certainly split the list up into separate fields. You can have multiple values for the same field name in a document, which is a fairly natural way to represent a set of values:

venue_id: 12345
treatment_id_set: 1234
treatment_id_set: 2345

使用这样的文档,我可以简单地查询"treatment_id_set:1234",以找到支持该治疗的所有场所.当然,治疗的顺序会丢失.如果需要恢复它,请在索引各个成员时存储逗号分隔的值:

With documents like this, I can simply query for "treatment_id_set:1234" to find all the venues supporting that treatment. Of course, the ordering of the treatments is lost. If you need to recover it, store the comma-separated value while indexing the individual members:

# stored, indexed
venue_id: 12345
# stored, not indexed
treatment_id_list: 1234,2345
# not stored, indexed
treatment_id_set: 1234
treatment_id_set: 2345

这篇关于使用Examine和Lucene.Net查询以逗号分隔的ID列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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