From 37d7c585fc1e8d5a365785641e4e49101da45575 Mon Sep 17 00:00:00 2001 From: Shi Jinghai Date: Wed, 10 May 2017 23:58:31 +0000 Subject: [PATCH] Fixed: Update Apache Solr/Lucene to release 6.2.1 OFBIZ-8316 Updated Lucene from 6.2.1 to 6.5.1 and the point fields generated by Lucene are ok now for Solr component. Thanks: Cao Pengan for the patch and Jacques, Michael for the comments and reviews. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk@1794770 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/build.gradle | 6 +++--- lucene/groovyScripts/content/Search.groovy | 14 ++++++-------- lucene/groovyScripts/content/SearchProducts.groovy | 11 ++++++++--- .../ofbiz/content/search/ProductDocument.java | 12 ++++++------ .../apache/ofbiz/content/search/SearchWorker.java | 4 ++-- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lucene/build.gradle b/lucene/build.gradle index 4fd6e9ccd..a1c226923 100644 --- a/lucene/build.gradle +++ b/lucene/build.gradle @@ -17,7 +17,7 @@ * under the License. */ dependencies { - pluginLibsCompile 'org.apache.lucene:lucene-core:6.2.1' - pluginLibsCompile 'org.apache.lucene:lucene-queryparser:6.2.1' - pluginLibsCompile 'org.apache.lucene:lucene-analyzers-common:6.2.1' + pluginLibsCompile 'org.apache.lucene:lucene-core:6.5.1' + pluginLibsCompile 'org.apache.lucene:lucene-queryparser:6.5.1' + pluginLibsCompile 'org.apache.lucene:lucene-analyzers-common:6.5.1' } \ No newline at end of file diff --git a/lucene/groovyScripts/content/Search.groovy b/lucene/groovyScripts/content/Search.groovy index 1e7056793..35b0beec2 100644 --- a/lucene/groovyScripts/content/Search.groovy +++ b/lucene/groovyScripts/content/Search.groovy @@ -22,15 +22,13 @@ import org.apache.lucene.document.Document 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 @@ -41,7 +39,7 @@ searchFeature3 = (String) parameters.SEARCH_FEAT3 featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(UtilHttp.getParameterMap(request)) -combQuery = new BooleanQuery.Builder() +combQuery = new BooleanQuery() try { DirectoryReader reader = DirectoryReader.open(FSDirectory.open(new File(SearchWorker.getIndexPath("content")).toPath())) @@ -66,7 +64,7 @@ if (queryLine || siteId) { } if (searchFeature1 || searchFeature2 || searchFeature3 || !featureIdByType.isEmpty()) { - featureQuery = new BooleanQuery.Builder() + featureQuery = new BooleanQuery() featuresRequired = BooleanClause.Occur.MUST if ("any".equals(parameters.any_or_all)) { featuresRequired = BooleanClause.Occur.SHOULD @@ -92,12 +90,12 @@ if (searchFeature1 || searchFeature2 || searchFeature3 || !featureIdByType.isEmp termQuery = new TermQuery(new Term("feature", value)) featureQuery.add(termQuery, featuresRequired) } - combQuery.add(featureQuery.build(), featuresRequired) + combQuery.add(featureQuery, featuresRequired) } } if (searcher) { TopScoreDocCollector collector = TopScoreDocCollector.create(100) //defaulting to 100 results - searcher.search(combQuery.build(), collector) + searcher.search(combQuery, collector) ScoreDoc[] hits = collector.topDocs().scoreDocs contentList = [] as ArrayList diff --git a/lucene/groovyScripts/content/SearchProducts.groovy b/lucene/groovyScripts/content/SearchProducts.groovy index cfabb8d7a..6ae4a9c81 100644 --- a/lucene/groovyScripts/content/SearchProducts.groovy +++ b/lucene/groovyScripts/content/SearchProducts.groovy @@ -25,11 +25,16 @@ import org.apache.lucene.document.Document import org.apache.lucene.index.DirectoryReader import org.apache.lucene.queryparser.classic.ParseException import org.apache.lucene.queryparser.classic.QueryParser -import org.apache.lucene.search.* +import org.apache.lucene.search.BooleanClause +import org.apache.lucene.search.BooleanQuery +import org.apache.lucene.search.IndexSearcher +import org.apache.lucene.search.Query +import org.apache.lucene.search.ScoreDoc +import org.apache.lucene.search.TopScoreDocCollector import org.apache.lucene.store.FSDirectory if (parameters.luceneQuery) { - combQuery = new BooleanQuery.Builder() + Query combQuery = new BooleanQuery() IndexSearcher searcher WhitespaceAnalyzer analyzer try { @@ -53,7 +58,7 @@ if (parameters.luceneQuery) { combQuery.add(query, BooleanClause.Occur.MUST) TopScoreDocCollector collector = TopScoreDocCollector.create(100) // defaulting to 100 results - searcher.search(combQuery.build(), collector) + searcher.search(combQuery, collector) ScoreDoc[] hits = collector.topDocs().scoreDocs productList = [] hits.each { hit -> diff --git a/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java b/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java index d24279c94..8ea4df969 100644 --- a/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java +++ b/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java @@ -87,13 +87,13 @@ public class ProductDocument implements LuceneDocument { this.addTextFieldByWeight(doc, "description", product.getString("description"), "index.weight.Product.description", 0, false, "fullText", delegator); this.addTextFieldByWeight(doc, "longDescription", product.getString("longDescription"), "index.weight.Product.longDescription", 0, false, "fullText", delegator); // OFBiz-8316, the LongPoint should be reused when updating to Solr 6.4.1 or later - doc.add(new StringField("introductionDate", String.valueOf(quantizeTimestampToDays(product.getTimestamp("introductionDate"))), Field.Store.NO)); -// doc.add(new LongPoint("introductionDate", quantizeTimestampToDays(product.getTimestamp("introductionDate")))); +// doc.add(new StringField("introductionDate", String.valueOf(quantizeTimestampToDays(product.getTimestamp("introductionDate"))), Field.Store.NO)); + doc.add(new LongPoint("introductionDate", quantizeTimestampToDays(product.getTimestamp("introductionDate")))); nextReIndex = this.checkSetNextReIndex(product.getTimestamp("introductionDate"), nextReIndex); // OFBiz-8316, the LongPoint should be reused when updating to Solr 6.4.1 or later // doc.add(new LongField("salesDiscontinuationDate", quantizeTimestampToDays(product.getTimestamp("salesDiscontinuationDate")), Field.Store.NO)); - doc.add(new StringField("salesDiscontinuationDate", String.valueOf(quantizeTimestampToDays(product.getTimestamp("salesDiscontinuationDate"))), Field.Store.NO)); -// doc.add(new LongPoint("salesDiscontinuationDate", quantizeTimestampToDays(product.getTimestamp("salesDiscontinuationDate")))); +// doc.add(new StringField("salesDiscontinuationDate", String.valueOf(quantizeTimestampToDays(product.getTimestamp("salesDiscontinuationDate"))), Field.Store.NO)); + doc.add(new LongPoint("salesDiscontinuationDate", quantizeTimestampToDays(product.getTimestamp("salesDiscontinuationDate")))); nextReIndex = this.checkSetNextReIndex(product.getTimestamp("salesDiscontinuationDate"), nextReIndex); doc.add(new StringField("isVariant", product.get("isVariant") != null && product.getBoolean("isVariant") ? "true" : "false", Field.Store.NO)); @@ -252,8 +252,8 @@ public class ProductDocument implements LuceneDocument { fieldNameSb.append("_price"); // OFBiz-8316, the DoublePoint should be reused when updating to Solr 6.4.1 or later // doc.add(new DoubleField(fieldNameSb.toString(), productPrice.getDouble("price"), Field.Store.NO)); - doc.add(new StringField(fieldNameSb.toString(), String.valueOf(productPrice.getDouble("price")), Field.Store.NO)); -// doc.add(new DoublePoint(fieldNameSb.toString(), productPrice.getDouble("price"))); +// doc.add(new StringField(fieldNameSb.toString(), String.valueOf(productPrice.getDouble("price")), Field.Store.NO)); + doc.add(new DoublePoint(fieldNameSb.toString(), productPrice.getDouble("price"))); } // Index ProductSuppliers diff --git a/lucene/src/main/java/org/apache/ofbiz/content/search/SearchWorker.java b/lucene/src/main/java/org/apache/ofbiz/content/search/SearchWorker.java index 5f5388305..3ad05a65d 100644 --- a/lucene/src/main/java/org/apache/ofbiz/content/search/SearchWorker.java +++ b/lucene/src/main/java/org/apache/ofbiz/content/search/SearchWorker.java @@ -41,7 +41,7 @@ public final class SearchWorker { public static final String module = SearchWorker.class.getName(); - private static final Version LUCENE_VERSION = Version.LUCENE_6_2_1; + private static final Version LUCENE_VERSION = Version.LUCENE_6_5_1; private SearchWorker() {} @@ -68,7 +68,7 @@ public final class SearchWorker { public static String getIndexPath(String path) { String basePath = UtilProperties.getPropertyValue("lucene", "defaultIndex", "index"); - return (UtilValidate.isNotEmpty(path)? basePath + "/" + path: basePath); + return (UtilValidate.isNotEmpty(path)? basePath + "/" + path + "/index" : basePath); } public static void indexContentList(LocalDispatcher dispatcher, Delegator delegator, List idList) throws Exception {