I have created an index using the file system and so far it has indexed all the files in the directory that I pointed at. The thing here is that, at the moment, the directory has only 45 file and those 45 files have been indexed. Now, the directory is constantly getting text files inside of it, I want to index this directory in such a way that it indexes only the new files that came in, rather than indexing the whole directory again and again every time a file comes in. How would I achieve this?
Share
You can use
WatchServicewhich will tell you when new files appear in the folder.This, however, isn’t much useful if your app is offline and new files appear during that period. To address this, you can add a separate field in Lucene and query the index before indexing any new file to check if that file exists.