svn commit: r1790664 - /ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1790664 - /ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy

jleroux@apache.org
Author: jleroux
Date: Sat Apr  8 08:26:19 2017
New Revision: 1790664

URL: http://svn.apache.org/viewvc?rev=1790664&view=rev
Log:
Fixed: CMS shows error screen on clicking Find button
(OFBIZ-9301)

Steps to regenerate :
1. Log in to Content component
2. Go to the CMS tab or directly go to  
        https://localhost:8443/content/control/CMSContentFind
3. Click on "Find" submenu or directly go to
        https://localhost:8443/content/control/AdminSearch
4. Screen renders with ScreenRenderingException

Problem:
1. "AdminSearch" request directs to "AdminSearch" screen in LuceneScreens.xml.
2. On AdminSearch screen, "Search.groovy" script prepares and hits a search
        query to Lucene.
3. "BooleanQuery" class is used to match documents with other boolean query
        combinations.
4. BooleanQuery object is initialised with Its default constructor.
5. With Lucene 5.4.0, this constructor is deprecated.
        OFBiz migrated to Lucene 6.3.1: OFBIZ-8316

Solution:
From Lucene 5.4.0 default constructor is deprecated and a new inner class
Builder is created for queries.

jleroux: I sorted the imports by hand, and added missing parenthesis at .build

Thanks: Aditya

Modified:
    ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy

Modified: ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy?rev=1790664&r1=1790663&r2=1790664&view=diff
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy (original)
+++ ofbiz/ofbiz-plugins/trunk/lucene/groovyScripts/content/Search.groovy Sat Apr  8 08:26:19 2017
@@ -22,13 +22,15 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.index.Term
 import org.apache.lucene.queryparser.classic.QueryParser
 import org.apache.lucene.store.FSDirectory
+import org.apache.lucene.search.*
+import org.apache.lucene.index.DirectoryReader
+
 import org.apache.ofbiz.base.util.UtilHttp
 import org.apache.ofbiz.content.search.SearchWorker
 import org.apache.ofbiz.product.feature.ParametricSearch
-import org.apache.lucene.search.*
-import org.apache.lucene.index.DirectoryReader
 import org.apache.ofbiz.base.util.UtilProperties
 
+
 queryLine = parameters.queryLine
 
 siteId = parameters.lcSiteId
@@ -39,7 +41,7 @@ searchFeature3 = (String) parameters.SEA
 
 featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(UtilHttp.getParameterMap(request))
 
-combQuery = new BooleanQuery()
+combQuery = new BooleanQuery.Builder()
 
 try {
     DirectoryReader reader = DirectoryReader.open(FSDirectory.open(new File(SearchWorker.getIndexPath("content")).toPath()))
@@ -64,7 +66,7 @@ if (queryLine || siteId) {
 }
 
 if (searchFeature1 || searchFeature2 || searchFeature3 || !featureIdByType.isEmpty()) {
-    featureQuery = new BooleanQuery()
+    featureQuery = new BooleanQuery.Builder()
     featuresRequired = BooleanClause.Occur.MUST
     if ("any".equals(parameters.any_or_all)) {
         featuresRequired = BooleanClause.Occur.SHOULD
@@ -90,12 +92,12 @@ if (searchFeature1 || searchFeature2 ||
             termQuery = new TermQuery(new Term("feature", value))
             featureQuery.add(termQuery, featuresRequired)
         }
-    combQuery.add(featureQuery, featuresRequired)
+    combQuery.add(featureQuery.build(), featuresRequired)
     }
 }
 if (searcher) {
     TopScoreDocCollector collector = TopScoreDocCollector.create(100) //defaulting to 100 results
-    searcher.search(combQuery, collector)
+    searcher.search(combQuery.build(), collector)
     ScoreDoc[] hits = collector.topDocs().scoreDocs
 
     contentList = [] as ArrayList