卢森斯搜索全部?使用查询解析器

发布于 2024-10-09 07:52:39 字数 494 浏览 0 评论 0原文

这是我的代码的一部分。我不想在 desc 中搜索文本,而是想搜索所有内容(desc、标题、示例等)。我该怎么做?我是否要创建另一个字段调用 all 并将每个字段复制到其中?我可以做类似“”、null 或“*”的操作来表示全部搜索吗? (我尝试了每一个,但没有得到结果)。

如何使用我的文本搜索所有字段?

public static List<Pair<long, float>> Search(string text)
{
    var searcher = new IndexSearcher(directory, true);
    var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "desc", analyzer);
    var query = parser.Parse(text);
    var hits = searcher.Search(query);
    // etc
}

Here's part of my code. Instead of searching the text in desc i'd like to search in everything (desc, title, example, etc). How do i do this? do i make another field call all and copy each field into it? can i do something like "", null or "*" to denote search them all? (I tried each and got no results).

How do i search all fields with my text?

public static List<Pair<long, float>> Search(string text)
{
    var searcher = new IndexSearcher(directory, true);
    var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "desc", analyzer);
    var query = parser.Parse(text);
    var hits = searcher.Search(query);
    // etc
}

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

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

发布评论

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

评论(1

北城挽邺 2024-10-16 07:52:39

如果 lucene 隐含地支持“全部”的概念,那就太好了。您剩下索引 1 个附加字段(将其命名为“all”),其内容将是 desc、标题、示例等的串联,但不存储它,只是索引。

It would be good if lucene implicitly supported the notion of "all". You are left with indexing 1 additional filed (name it as "all") whose contents will be a concatenation of desc, title, example etc but do not store it, just index.

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