简体   繁体   中英

Lucene Term lookup

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");

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.

I think you need to first read a basic lucene tutorial such as this . Note that the code used in the tutorial is old, ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM