davsclaus commented on code in PR #28529:
URL: https://github.com/apache/camel/pull/28529#discussion_r4390032174
##########
components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java:
##########
@@ -151,10 +155,23 @@ private void add(File file) throws IOException {
IOHelper.copy(IOHelper.buffered(is), bos);
contents = bos.toString();
}
+ // one document per file, so a hit on the contents gives the
path of its file
+ Document doc = new Document();
+ add(doc, "path", file.getPath(), false);
+ add(doc, "contents", contents, true);
openIndexWriter();
- add("path", file.getPath(), false);
- add("contents", contents, true);
- closeIndexWriter();
+ try {
+ indexWriter.addDocument(doc);
Review Comment:
`srcDir` is indexed every time the endpoint is created
(`LuceneEndpoint.java:72`), into an index opened with `CREATE_OR_APPEND`, so
after this fix each restart adds one more searchable copy of every file. `path`
is indexed untokenized now, so the document of the file can be replaced:
```suggestion
indexWriter.updateDocument(new Term("path",
file.getPath()), doc);
```
(plus `import org.apache.lucene.index.Term;`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]