有没有推荐的IndexSearcher方法?

时间:2021-07-05 03:08:15

I'm using Lucene search API in a web based application. Which method of Lucene's IndexSearcher class is recommended to use?Is any method faster than other?

我在基于Web的应用程序中使用Lucene搜索API。建议使用Lucene的IndexSearcher类的哪种方法?是否有比其他方法更快的方法?

1.IndexSearcher(Directory directory) 2.IndexSearcher(IndexReader r) 3.IndexSearcher(String path)

1.IndexSearcher(目录目录)2.IndexSearcher(IndexReader r)3.IndexSearcher(String path)

Thanks for reading.

谢谢阅读。

2 个解决方案

#1


The constructor which accepts Directory and path to index internally use the constructor that accpets IndexReader. So, there is no performance advantage of one over others. Keep in mind that if you create searcher with IndexReader, you have to close the reader explicitly after you close the searcher.

接受目录和索引路径的构造函数在内部使用接受IndexReader的构造函数。因此,没有其他人的性能优势。请记住,如果使用IndexReader创建搜索器,则必须在关闭搜索器后明确关闭阅读器。

#2


It's all about convenience.

一切都与方便有关。

If you just want to create an IndexSearcher, use the one that accepts a path.

如果您只想创建IndexSearcher,请使用接受路径的索引。

If you already have a Directory object, use the one that accepts a Directory.

如果您已有Directory对象,请使用接受Directory的对象。

And if you have an IndexReader... you get the point. Just remember that if you provided an IndexReader, you're expected to close it yourself after you've closed the IndexSearcher.

如果你有一个IndexReader ......你明白了。请记住,如果您提供了一个IndexReader,那么您应该在关闭IndexSearcher后自行关闭它。

I highly recommend grabbing a copy of the Lucene source code. It is very readable, and can answer a lot of these questions.

我强烈建议您获取Lucene源代码的副本。它非常易读,可以回答很多这些问题。

#1


The constructor which accepts Directory and path to index internally use the constructor that accpets IndexReader. So, there is no performance advantage of one over others. Keep in mind that if you create searcher with IndexReader, you have to close the reader explicitly after you close the searcher.

接受目录和索引路径的构造函数在内部使用接受IndexReader的构造函数。因此,没有其他人的性能优势。请记住,如果使用IndexReader创建搜索器,则必须在关闭搜索器后明确关闭阅读器。

#2


It's all about convenience.

一切都与方便有关。

If you just want to create an IndexSearcher, use the one that accepts a path.

如果您只想创建IndexSearcher,请使用接受路径的索引。

If you already have a Directory object, use the one that accepts a Directory.

如果您已有Directory对象,请使用接受Directory的对象。

And if you have an IndexReader... you get the point. Just remember that if you provided an IndexReader, you're expected to close it yourself after you've closed the IndexSearcher.

如果你有一个IndexReader ......你明白了。请记住,如果您提供了一个IndexReader,那么您应该在关闭IndexSearcher后自行关闭它。

I highly recommend grabbing a copy of the Lucene source code. It is very readable, and can answer a lot of these questions.

我强烈建议您获取Lucene源代码的副本。它非常易读,可以回答很多这些问题。