This is an automated email from the ASF dual-hosted git repository.

apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b42a6412abf64e976b3ecefe23e9c6db6c6a584b
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Mar 11 11:35:19 2026 +0100

    CAMEL-23141: Hoist storedFields() out of the search loop
    
    Avoid creating a new StoredFields instance per hit by obtaining it
    once before the loop.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../main/java/org/apache/camel/component/lucene/LuceneSearcher.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
 
b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
index 086f16585a99..ace00591c0bb 100644
--- 
a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
+++ 
b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
@@ -25,6 +25,7 @@ import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.StoredFields;
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.queryparser.classic.QueryParser;
 import org.apache.lucene.search.IndexSearcher;
@@ -69,8 +70,9 @@ public class LuceneSearcher {
         int numberOfHits = doSearch(searchPhrase, maxNumberOfHits, 
totalHitsThreshold);
         searchHits.setNumberOfHits(numberOfHits);
 
+        StoredFields storedFields = 
indexSearcher.getIndexReader().storedFields();
         for (ScoreDoc hit : hits) {
-            Document selectedDocument = 
indexSearcher.getIndexReader().storedFields().document(hit.doc);
+            Document selectedDocument = storedFields.document(hit.doc);
             Hit aHit = new Hit();
             if (returnLuceneDocs) {
                 aHit.setDocument(selectedDocument);

Reply via email to