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 git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk@1790810 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -30,6 +30,7 @@ import org.apache.ofbiz.product.feature.ParametricSearch
|
||||
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 ?: "WebStoreCONTENT"
|
||||
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(), "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user