开发者

Lucene Term lookup

开发者 https://www.devze.com 2023-04-05 17:07 出处:网络
With Lucene, is it possible to do a straight term lookup wit开发者_StackOverflow中文版hout having to iterate over the terms?

With Lucene, is it possible to do a straight term lookup wit开发者_StackOverflow中文版hout having to iterate over the terms?

For ex:

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号