Lucene notes ____ notes for indexreader and indexwriter

Source: Internet
Author: User

In the use of javasne, enabling and disabling indexreader and indexwriter is time-consuming, especially for indexreader operations,

(Indexreader reads the index information on the disk into the memory)

Therefore, we generally create indexreader as a single instance to reduce consumption.

Let's look at the example below:

Private indexreader reader; Public indexsearcher getsearcher (directory) {try {If (reader = NULL) {reader = indexreader. open (directory);} else {indexreader TR = indexreader. openifchanged (Reader); If (TR! = NULL) {reader. close (); reader = TR;} return New indexsearcher (Reader);} catch (corruptindexexception e) {e. printstacktrace ();} catch (ioexception e) {e. printstacktrace ();} return NULL ;}

In this case, we will not close the reader and check whether the reader exists during use. Then we can see another function openifchanged.

Explanation:

If the index is opened and the reader changes, a new reader is returned. Otherwise, null is returned. Therefore, openifchanged is used in the preceding method.

To determine whether it is the original reader.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.