Lucene.net 中搜索的过滤器索引

发布于 2024-11-24 02:23:14 字数 496 浏览 2 评论 0原文

我目前正在开发一个涉及 C# 中的 Lucene 库的项目,但是我在项目设计中遇到了有关索引中文档检索的问题。我的索引中的文档是用多个字段创建的,我希望能够在其中两个字段之间进行过滤,然后在这个子集中搜索术语,但是我仍然熟悉 lucene,并且不完全确定这是否可能。我已经学会了如何执行基本查询,但我认为我应该使用 lucenes 过滤器类,但我不太确定如何执行。如果有人能就此提供建议,我将不胜感激

。我正在完成的项目涉及对来自各种电子邮件帐户的电子邮件进行索引。我的索引中的文档具有以下一些字段: 帐户:(例如[电子邮件受保护]) 文件夹:(例如已发送、垃圾箱、收件箱...) 数据:(电子邮件正文)

我希望能够过滤我的索引,以便我可以拥有一个仅包含来自特定帐户和文件夹的文档的子集,然后在此之后我希望能够搜索该子集的数据字段。

I am currently working on a project involving the Lucene library within C# however I have reached an issue with design of my project concerning the retrevial of documents within the index. The documents within my index have been created with several fields and i'd like to be able to filter between two of these fields and then search this subset for terms however I am still familiarising myself with lucene and am not fully sure if this is possible. I have learnt how to perform basic queries but I think I should be using lucenes filter class but i am not exactly sure how. I would be greatful if anyone could offer advice on this

The project I am completing involves indexing email messages from various email accounts. the documents in my index have some of the following fields:
Account: (e.g. [email protected])
Folder: (e.g. sent, trash, inbox...)
Data: (the body of the email)

I'd like to be able to filter my index so i can have a subset which only containts documents from a particular account and folder and then after this I'd like to be able to search the data field of this subset.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的影子我的梦 2024-12-01 02:23:15

正如 @Jf Beaulac 所建议的,您可以使用 BooleanQuery 进行“过滤”。

private Query CreateFilteredQuery (string account, string folder, Query criteria)
{
     BooleanQuery bq = new BooleanQuery();
     bq.Add(new TermQuery (new Lucene.Net.Index.Term ("account", account)), BooleanClause.Occur.MUST);
     bq.Add(new TermQuery (new Lucene.Net.Index.Term ("folder", folder)), BooleanClause.Occur.MUST);
     bq.Add(criteria, BooleanClause.Occur.MUST);
     return bq;
}


Query filteredQuery = CreateFilteredQuery ("[email protected]", "inbox", myQueryParser.Parse (criteria));
var hits = myIndexSearcher.Search (filteredQuery);

这是一个关于查询和过滤器之间差异的好问题:为什么我们使用过滤器搜索时

As @Jf Beaulac suggested, you can do "filtering" with a BooleanQuery.

private Query CreateFilteredQuery (string account, string folder, Query criteria)
{
     BooleanQuery bq = new BooleanQuery();
     bq.Add(new TermQuery (new Lucene.Net.Index.Term ("account", account)), BooleanClause.Occur.MUST);
     bq.Add(new TermQuery (new Lucene.Net.Index.Term ("folder", folder)), BooleanClause.Occur.MUST);
     bq.Add(criteria, BooleanClause.Occur.MUST);
     return bq;
}


Query filteredQuery = CreateFilteredQuery ("[email protected]", "inbox", myQueryParser.Parse (criteria));
var hits = myIndexSearcher.Search (filteredQuery);

Here is a good question about the differences between queries and filters: Why do we use Filters while searching

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文