I'm using Lucene to create an concept-based image search engine. Firstly, I open my database and copy it into a RAM index. Then I write an analyzer to find user input word and its synonym. At last, I want to open the index to get results.
getImage() - Used to call addDoc() copy database into my index
This is getImageResult() which I want to used to get result. I think maybe this is the bug.
However, if I remove:
StandardAnalyzer analyzer = new StandardAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
IndexWriter iwriter = new IndexWriter(index, config);
iwriter.commit();
It will raise an exception: no segments* file found in RAMDirectory. And if I Keep this part, I can't get any result.
I'm not entirely sure, but I assume you are trying to write to an index with your first snippet there, and then search it with the second, right?
Your getImageResult()
method in opening a brand new index in a brand new directory. Anything previously written to a different RAMDirectory
will not be available for you to search there.
You should either:
RAMDirectory
in both places, or FSDirectory
, with which it will be saved to the file system, and can be reopened. See FSDirectory.open
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.