Lucene3.6.2 entry series _ near real-time search

Source: Internet
Author: User
Tags createindex
Package COM. jadyer. lucene; import Java. io. file; import Java. io. ioexception; import Org. apache. lucene. analysis. standard. standardanalyzer; import org.apache.e.doc ument. document; import org.apache.e.doc ument. field; import Org. apache. lucene. index. indexreader; import Org. apache. lucene. index. indexwriter; import Org. apache. lucene. index. indexwriterconfig; import Org. apache. lucene. index. term; import Org. apa Che. lucene. search. indexsearcher; import Org. apache. lucene. search. nrtmanager; import Org. apache. lucene. search. nrtmanagerreopenthread; import Org. apache. lucene. search. query; import Org. apache. lucene. search. scoredoc; import Org. apache. lucene. search. termquery; import Org. apache. lucene. search. topdocs; import Org. apache. lucene. search. nrtmanager. trackingindexwriter; import Org. apache. lucene. store. directory; impor T Org. apache. lucene. store. fsdirectory; import Org. apache. lucene. util. version;/*** [lucene3.6.2 getting started series] section 12th _ near real-time search * @ see real-time search (near-real-time) ----> as long as the data changes, then update the index immediately (indexwriter. commit () * @ see near real-time search ----------------> when data changes, first save the index to the memory, then execute the commit action on all indexes in the memory at a unified time * @ see in order to achieve near real-time search, the method provided by javase3.0 is called reopen, later versions provided two thread-safe classes: nrtmanager and searchermanager * @ see. However, the usage of these two thread-safe classes in javase3.5 and 3.6 is a bit different. Note that * @ Create Aug 7, 2013 4:19:58 * @ author Xuan Yu 

Below is a small test written with junit4.x

Package COM. jadyer. test; import Org. JUnit. after; import Org. JUnit. before; import Org. JUnit. test; import COM. jadyer. lucene. hellonrtsearch; public class hellonrtsearchtest {@ beforepublic void Init () {hellonrtsearch. createindex () ;}@ afterpublic void destroy () {hellonrtsearch. getdocscount () ;}@ testpublic void searchfile () {hellonrtsearch Hello = new hellonrtsearch (); For (INT I = 0; I <5; I ++) {hello. searchfile (); system. out. println ("-----------------------------------------------------------"); Hello. deleteindex (); if (I = 2) {hello. updateindex ();} Try {system. out. println ("......... start sleep for 5 S (simulating near real-time search scenarios) "); thread. sleep (1, 5000); system. out. println ("......... sleep ends ");} catch (interruptedexception e) {e. printstacktrace () ;}}// new hellonrtsearch cannot be used independently. Make sure they are the same object. Otherwise, the delete and update operations will not be commithello. commitindex ();}}

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.