vignesh-manel commented on code in PR #28529:
URL: https://github.com/apache/camel/pull/28529#discussion_r4390665021


##########
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:
   Done in ab4b0e254e7d, as you suggested: `updateDocument(new Term("path", 
file.getPath()), doc)`.
   
   - New test 
`LuceneIndexProducerLifecycleTest.sourceDirectoryIndexedAgainReplacesTheDocumentsOfItsFiles`
 creates two `LuceneIndexer` instances on the same `srcDir` and `indexDir`, and 
changes the file between them. It checks that there is one document 
(`numDocs`), that the new contents are found, and that the old ones are not. 
Before the change it failed with `expected: <1> but was: <2>`.
   - The upgrade guide entry now says that a re-created endpoint replaces the 
documents of the `srcDir` files.
   - I also checked one case the change could break: an exchange inserted with 
a header `path` set to that file's path keeps its document when `srcDir` is 
indexed again. Headers are tokenized, so they never hold the whole path as one 
term.
   - Still open, and not changed here (stated in the PR description): a file 
deleted from `srcDir` keeps its document, and a relative `srcDir` gives a 
different `path` term from another working directory.
   
   I merged main into the branch (another upgrade guide entry, camel-wordpress, 
had been appended at the end), with no rebase. `camel-lucene` passes 15 unit 
tests and 6 ITs, and `-Psourcecheck` passes. CI is running on 67a20f4d842b.
   
   _Claude Code on behalf of vignesh-manel_
   



-- 
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]

Reply via email to