Lucene 术语查找

发布于 2024-12-05 07:38:50 字数 146 浏览 4 评论 0原文

使用 Lucene,是否可以进行直接术语查找而无需迭代术语?

例如:

IndexReader r = IndexReader.open("...");
Term t = r.getTerm("myterm");

With Lucene, is it possible to do a straight term lookup without having to iterate over the terms?

For ex:

IndexReader r = IndexReader.open("...");
Term t = r.getTerm("myterm");

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

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

发布评论

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

评论(2

话少情深 2024-12-12 07:38:50

我认为你需要首先阅读基本的 lucene 教程这样的。请注意,本教程中使用的代码是旧的,即与最新的 lucene 版本不对应。从你对迈克的评论来看,我相信正在寻找“搜索”。

另一种方法是使用 lucene 的包装器,例如提供简单接口的 Elasticsearch。尽管如此,在使用之前了解该界面还是很重要的。

I think you need to first read a basic lucene tutorial such as this. Note that the code used in the tutorial is old, i.e., does not correspond to the latest lucene version. From your comment to Mike, I believe are looking for "search".

An alternative is to use a wrapper over lucene such as Elasticsearch that provides a simple interface. Nevertheless, it is important to understand the interface before using it.

深居我梦 2024-12-12 07:38:50

简而言之,不。正如您所显示的那样,在索引中查找术语实际上没有意义,因为您已经拥有该术语,并且不需要任何有关它的附加信息。

Lucene 将术语存储为与 docids 关联的字段值。不过,您可以使用TermsEnum 枚举索引中的所有术语。您可以找到与文档相关的所有术语,或者找出索引中是否存在给定术语 - 这可能是我能想到的与您所要求的最接近的事情。

In short, no. It doesn't really make sense to look up a term in the index as you've shown since you already have the term, and aren't asking for any additional information about it.

Lucene stores terms as values of fields associated with docids. You can enumerate all the terms in the index, though, with a TermsEnum. You can find all the terms associated with a document, or find out whether a given term exists in the index - that is probably the closest thing I can think of to what you are asking.

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