java - Index that is continually written to and queried -
i using lucene 5.2.1.
i trying figure out how should opening indexreader
s indexwriter
s , indexsearcher
s such can have index have items continually written whilst queries going on.
currently code:
path indexpath = paths.get("index"); directory dir = niofsdirectory.open(indexpath); indexwriterconfig iwc = new indexwriterconfig(new standardanalyzer()); iwc.setopenmode(indexwriterconfig.openmode.create_or_append); indexwriter indexwriter = new indexwriter(dir, iwc); indexreader indexreader = directoryreader.open(indexwriter, false);
if start app , start putting documents index, can query fine.
however, when stop app , restart, observing index directory being truncated (so added directory lost)
i not see close() on variable dir (niofsdirectory), , commit() and/or close() on indexwriter(indexwriter). might need close these flush rest of data file.
two notes found in niofsdirectory class 5.2.1. first note important windows o/s.
note: niofsdirectory not recommended on windows because of bug in how filechannel.read implemented in sun's jre. inside of implementation position apparently synchronized. see here details.
note: accessing class either directly or indirectly thread while it's interrupted can close underlying file descriptor if @ same time thread blocked on io. file descriptor remain closed , subsequent access niofsdirectory throw closedchannelexception. if application uses either thread.interrupt() or future.cancel(boolean) should use legacy rafdirectory lucene misc module in favor of niofsdirectory.
Comments
Post a Comment