[Yanel-dev] Super small patch for LuceneSearcher in Yarep

Balz Schreier balz.schreier at gmail.com
Tue Apr 19 11:17:04 CEST 2011


Hi Michi,

can you apply this patch? it is really a very easy patch:
- the private property "config" has been exposed via getter and setter
- all accesses within the class are done via getConfig() instead of direct
access.

The motivation for this patch: Someone might subclass the searcher class and
therefore must be able to set the config property of the superclass. if it
is private, it does not work.
in addition, the subclass can override getConfig() and return whatever
config is needed (in Test-Cases you might want yet another config to inject
etc.).


Does this make sense?

Cheers
Balz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wyona.org/pipermail/yanel-development/attachments/20110419/4b0c11ff/attachment.html>
-------------- next part --------------
Index: src/impl/java/org/wyona/yarep/impl/search/lucene/LuceneSearcher.java
===================================================================
--- src/impl/java/org/wyona/yarep/impl/search/lucene/LuceneSearcher.java	(revision 57761)
+++ src/impl/java/org/wyona/yarep/impl/search/lucene/LuceneSearcher.java	(working copy)
@@ -34,10 +34,10 @@
             //TODO: this is not really nice re performance, it reads the index form the file-system for each search
             //it would be nice to initialize IndexSearcher at startup and reuse the IndexSearcher 
             //but in this case the IndexSearcher then uses the index as it was at startup and not reloading it when the index has changed at runtime
-            org.apache.lucene.search.Searcher searcher = new IndexSearcher(config.getFulltextSearchIndexFile().getAbsolutePath());
+            org.apache.lucene.search.Searcher searcher = new IndexSearcher(getConfig().getFulltextSearchIndexFile().getAbsolutePath());
             if (searcher != null) {
                 try {
-                    org.apache.lucene.search.Query luceneQuery = new org.apache.lucene.queryParser.QueryParser(LuceneIndexer.INDEX_PROPERTY_FULL, config.getFulltextAnalyzer()).parse(query);
+                    org.apache.lucene.search.Query luceneQuery = new org.apache.lucene.queryParser.QueryParser(LuceneIndexer.INDEX_PROPERTY_FULL, getConfig().getFulltextAnalyzer()).parse(query);
                     org.apache.lucene.search.Hits hits = searcher.search(luceneQuery);
                     log.info("Query \"" + query + "\" returned " + hits.length() + " hits");
 
@@ -48,9 +48,9 @@
                             //log.debug("This seems to be a revision: " + resultPath);
                             String resultPathWithoutRevision = path.substring(0, path.lastIndexOf("#revision="));
                             String revisionName = path.substring(path.lastIndexOf("#revision=") + 10);
-                            if (config.getRepo().existsNode(resultPathWithoutRevision)) {
+                            if (getConfig().getRepo().existsNode(resultPathWithoutRevision)) {
                                 try {
-                                    results.add(config.getRepo().getNode(resultPathWithoutRevision).getRevision(revisionName));
+                                    results.add(getConfig().getRepo().getNode(resultPathWithoutRevision).getRevision(revisionName));
                                 } catch(org.wyona.yarep.core.NoSuchRevisionException e) {
                                     log.error("Revision found within search index, but no such revision within repository: " + resultPathWithoutRevision + "#" + revisionName);
                                 }
@@ -58,10 +58,10 @@
                                 log.error("Node found within search index, but no such node within repository: " + resultPathWithoutRevision);
                             }
                         } else {
-                            if (config.getRepo().existsNode(path)) {
-                                results.add(config.getRepo().getNode(path));
+                            if (getConfig().getRepo().existsNode(path)) {
+                                results.add(getConfig().getRepo().getNode(path));
                             } else {
-                                log.error("No such node '" + path + "'. Search index (Fulltext: '" + config.getFulltextSearchIndexFile() + "', Properties: '" + config.getPropertiesSearchIndexFile() + "') seems to be out of sync!");
+                                log.error("No such node '" + path + "'. Search index (Fulltext: '" + getConfig().getFulltextSearchIndexFile() + "', Properties: '" + getConfig().getPropertiesSearchIndexFile() + "') seems to be out of sync!");
                             }
                         }
                     }
@@ -91,13 +91,13 @@
             //TODO: this is not really nice re performance, it reads the index form the file-system for each search
             //it would be nice to initialize IndexSearcher at startup and reuse the IndexSearcher 
             //but in this case the IndexSearcher then uses the index as it was at startup and not reloading it when the index has changed at runtime            
-            org.apache.lucene.search.Searcher searcher = new IndexSearcher(config.getPropertiesSearchIndexFile().getAbsolutePath());
+            org.apache.lucene.search.Searcher searcher = new IndexSearcher(getConfig().getPropertiesSearchIndexFile().getAbsolutePath());
             if (searcher != null) {
                 try {
                     log.debug("Search property '" + pName + "': " + query);
 
                     String defaultField = pName;
-                    org.apache.lucene.queryParser.QueryParser queryParser = new org.apache.lucene.queryParser.QueryParser(defaultField, config.getPropertyAnalyzer());
+                    org.apache.lucene.queryParser.QueryParser queryParser = new org.apache.lucene.queryParser.QueryParser(defaultField, getConfig().getPropertyAnalyzer());
                     org.apache.lucene.search.Query luceneQuery = queryParser.parse(query);
 
                     org.apache.lucene.search.Hits hits = searcher.search(luceneQuery);
@@ -113,9 +113,9 @@
                                     //log.debug("This seems to be a revision: " + resultPath);
                                     String resultPathWithoutRevision = resultPath.substring(0, resultPath.lastIndexOf("#revision="));
                                     String revisionName = resultPath.substring(resultPath.lastIndexOf("#revision=") + 10);
-                                    if (config.getRepo().existsNode(resultPathWithoutRevision)) {
+                                    if (getConfig().getRepo().existsNode(resultPathWithoutRevision)) {
                                         try {
-                                            results.add(config.getRepo().getNode(resultPathWithoutRevision).getRevision(revisionName));
+                                            results.add(getConfig().getRepo().getNode(resultPathWithoutRevision).getRevision(revisionName));
                                         } catch(org.wyona.yarep.core.NoSuchRevisionException e) {
                                             log.error("Revision found within search index, but no such revision within repository: " + resultPathWithoutRevision + "#" + revisionName);
                                         }
@@ -123,7 +123,7 @@
                                         log.error("Node found within search index, but no such node within repository: " + resultPathWithoutRevision);
                                     }
                                 } else {
-                                    results.add(config.getRepo().getNode(resultPath));
+                                    results.add(getConfig().getRepo().getNode(resultPath));
                                 }
                             }
 
@@ -145,4 +145,12 @@
         }
         return null;
     }
+
+    public LuceneConfig getConfig() {
+        return config;
+    }
+
+    public void setConfig(LuceneConfig config) {
+        this.config = config;
+    }
 }


More information about the Yanel-development mailing list