You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2017/04/10 12:05:36 UTC

svn commit: r1790810 - /ofbiz/ofbiz-plugins/trunk/ecommerce/groovyScripts/content/Search.groovy

Author: jleroux
Date: Mon Apr 10 12:05:36 2017
New Revision: 1790810

URL: http://svn.apache.org/viewvc?rev=1790810&view=rev
Log:
Fixed: Ecommerce component showing error screen on searchContent from 
showcontenttree page
(OFBIZ-9309)

Steps to reproduce:
1.Go to Ecommerce component https://localhost:8443/ecommerce/control/main
2.Click on any of the Content from "Browse Content" section of left panel. 
  It will be directed to https://localhost:8443/ecommerce/control/showcontenttree?contentId=STORE_POLICIES&nodeTrailCsv=STORE_POLICIES
3. Click on Search, it directs to https://localhost:8443/ecommerce/control/searchContent?siteId=STORE_POLICIES
4. Screen renders with ScreenRenderingException

Problem:
1. "searchContent" request directs to "searchContent" screen in 
  ContentScreens.xml.
2. On searchContent screen, "/ecommerce/groovyScripts/content/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. Refer OFBIZ-9301 for detailed explanation.

Thanks: Aditya

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

Modified: ofbiz/ofbiz-plugins/trunk/ecommerce/groovyScripts/content/Search.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/ecommerce/groovyScripts/content/Search.groovy?rev=1790810&r1=1790809&r2=1790810&view=diff
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/ecommerce/groovyScripts/content/Search.groovy (original)
+++ ofbiz/ofbiz-plugins/trunk/ecommerce/groovyScripts/content/Search.groovy Mon Apr 10 12:05:36 2017
@@ -30,6 +30,7 @@ import org.apache.ofbiz.product.feature.
 import org.apache.lucene.search.*
 import org.apache.lucene.index.DirectoryReader
 import org.apache.lucene.store.Directory
+import org.apache.ofbiz.base.util.UtilProperties
 
 paramMap = UtilHttp.getParameterMap(request)
 queryLine = paramMap.queryLine.toString()
@@ -40,19 +41,20 @@ siteId = paramMap.siteId ?: "WebStoreCON
 featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(paramMap)
 //Debug.logInfo("in search, featureIdByType:" + featureIdByType, "")
 
-combQuery = new BooleanQuery()
-Directory directory = FSDirectory.open(new File(SearchWorker.getIndexPath("content")).toPath())
-DirectoryReader reader = DirectoryReader.open(directory)
+combQuery = new BooleanQuery.Builder()
 IndexSearcher searcher = null
 Analyzer analyzer = null
 
 try {
+    Directory directory = FSDirectory.open(new File(SearchWorker.getIndexPath("content")).toPath())
+    DirectoryReader reader = DirectoryReader.open(directory)
     searcher = new IndexSearcher(reader)
     analyzer = new StandardAnalyzer()
 } catch (java.io.FileNotFoundException e) {
-    Debug.logError(e, "Search.groovy")
-    request.setAttribute("errorMsgReq", "No index file exists.")
+    context.errorMessageList.add(UtilProperties.getMessage("ContentErrorUiLabels", "ContentSearchNotIndexed", locale))
+    return
 }
+
 termQuery = new TermQuery(new Term("site", siteId.toString()))
 combQuery.add(termQuery, BooleanClause.Occur.MUST)
 //Debug.logInfo("in search, termQuery:" + termQuery.toString(), "")
@@ -66,7 +68,7 @@ if (queryLine && analyzer) {
 }
 
 if (featureIdByType) {
-    featureQuery = new BooleanQuery()
+    featureQuery = new BooleanQuery.Builder()
     featuresRequired = BooleanClause.Occur.MUST
     if ("any".equals(paramMap.anyOrAll)) {
         featuresRequired = BooleanClause.Occur.SHOULD
@@ -79,13 +81,13 @@ if (featureIdByType) {
             //Debug.logInfo("in search searchFeature3, termQuery:" + termQuery.toString(), "")
         }
     }
-    combQuery.add(featureQuery, featuresRequired)
+    combQuery.add(featureQuery.build(), featuresRequired)
 }
 
 if (searcher) {
     Debug.logInfo("in search searchFeature3, combQuery:" + combQuery.toString(), "")
     TopScoreDocCollector collector = TopScoreDocCollector.create(100) //defaulting to 100 results
-    searcher.search(combQuery, collector)
+    searcher.search(combQuery.build(), collector)
     ScoreDoc[] hits = collector.topDocs().scoreDocs
     Debug.logInfo("in search, hits:" + collector.getTotalHits(), "")