Improved: Update Solr/Lucene to 7.1.0 [CVE-2017-9803] [CVE-2017-12629].
(OFBIZ-9835) There were two security vulnerabilities and it was recommended to upgrade to 7.1.0 asap. The update removed the deprecated setBoost functionality during index time. I have removed it completely to be able to update to 7.1.0. A new indexing and query strategy has to be implemented here. Might be follow-up work in the future. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk@1812790 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+3
-3
@@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
dependencies {
|
||||
pluginLibsCompile 'org.apache.lucene:lucene-core:6.6.0'
|
||||
pluginLibsCompile 'org.apache.lucene:lucene-queryparser:6.6.0'
|
||||
pluginLibsCompile 'org.apache.lucene:lucene-analyzers-common:6.6.0'
|
||||
pluginLibsCompile 'org.apache.lucene:lucene-core:7.1.0'
|
||||
pluginLibsCompile 'org.apache.lucene:lucene-queryparser:7.1.0'
|
||||
pluginLibsCompile 'org.apache.lucene:lucene-analyzers-common:7.1.0'
|
||||
}
|
||||
@@ -81,11 +81,11 @@ public class ProductDocument implements LuceneDocument {
|
||||
|
||||
// Product Fields
|
||||
doc.add(new StringField("productId", productId, Field.Store.YES));
|
||||
this.addTextFieldByWeight(doc, "productName", product.getString("productName"), "index.weight.Product.productName", 0, false, "fullText", delegator);
|
||||
this.addTextFieldByWeight(doc, "internalName", product.getString("internalName"), "index.weight.Product.internalName", 0, false, "fullText", delegator);
|
||||
this.addTextFieldByWeight(doc, "brandName", product.getString("brandName"), "index.weight.Product.brandName", 0, false, "fullText", delegator);
|
||||
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);
|
||||
this.addTextField(doc, "productName", product.getString("productName"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "internalName", product.getString("internalName"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "brandName", product.getString("brandName"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "description", product.getString("description"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "longDescription", product.getString("longDescription"), false, "fullText", delegator);
|
||||
doc.add(new LongPoint("introductionDate", quantizeTimestampToDays(product.getTimestamp("introductionDate"))));
|
||||
nextReIndex = this.checkSetNextReIndex(product.getTimestamp("introductionDate"), nextReIndex);
|
||||
doc.add(new LongPoint("salesDiscontinuationDate", quantizeTimestampToDays(product.getTimestamp("salesDiscontinuationDate"))));
|
||||
@@ -113,9 +113,9 @@ public class ProductDocument implements LuceneDocument {
|
||||
doc.add(new StringField("productFeatureId", productFeatureAndAppl.getString("productFeatureId"), Field.Store.NO));
|
||||
doc.add(new StringField("productFeatureCategoryId", productFeatureAndAppl.getString("productFeatureCategoryId"), Field.Store.NO));
|
||||
doc.add(new StringField("productFeatureTypeId", productFeatureAndAppl.getString("productFeatureTypeId"), Field.Store.NO));
|
||||
this.addTextFieldByWeight(doc, "featureDescription", productFeatureAndAppl.getString("description"), "index.weight.ProductFeatureAndAppl.description", 0, false, "fullText", delegator);
|
||||
this.addTextFieldByWeight(doc, "featureAbbreviation", productFeatureAndAppl.getString("abbrev"), "index.weight.ProductFeatureAndAppl.abbrev", 0, false, "fullText", delegator);
|
||||
this.addTextFieldByWeight(doc, "featureCode", productFeatureAndAppl.getString("idCode"), "index.weight.ProductFeatureAndAppl.idCode", 0, false, "fullText", delegator);
|
||||
this.addTextField(doc, "featureDescription", productFeatureAndAppl.getString("description"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "featureAbbreviation", productFeatureAndAppl.getString("abbrev"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "featureCode", productFeatureAndAppl.getString("idCode"), false, "fullText", delegator);
|
||||
// Get the ProductFeatureGroupIds
|
||||
List<GenericValue> productFeatureGroupAppls = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureId", productFeatureAndAppl.get("productFeatureId")).queryList();
|
||||
productFeatureGroupAppls = this.filterByThruDate(productFeatureGroupAppls);
|
||||
@@ -140,8 +140,8 @@ public class ProductDocument implements LuceneDocument {
|
||||
|
||||
List<GenericValue> productAttributes = EntityQuery.use(delegator).from("ProductAttribute").where("productId", productId).queryList();
|
||||
for (GenericValue productAttribute: productAttributes) {
|
||||
this.addTextFieldByWeight(doc, "attributeName", productAttribute.getString("attrName"), "index.weight.ProductAttribute.attrName", 0, false, "fullText", delegator);
|
||||
this.addTextFieldByWeight(doc, "attributeValue", productAttribute.getString("attrValue"), "index.weight.ProductAttribute.attrValue", 0, false, "fullText", delegator);
|
||||
this.addTextField(doc, "attributeName", productAttribute.getString("attrName"), false, "fullText", delegator);
|
||||
this.addTextField(doc, "attributeValue", productAttribute.getString("attrValue"), false, "fullText", delegator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ProductDocument implements LuceneDocument {
|
||||
String idValue = goodIdentification.getString("idValue");
|
||||
doc.add(new StringField("goodIdentificationTypeId", goodIdentificationTypeId, Field.Store.NO));
|
||||
doc.add(new StringField(goodIdentificationTypeId + "_GoodIdentification", idValue, Field.Store.NO));
|
||||
this.addTextFieldByWeight(doc, "identificationValue", idValue, "index.weight.GoodIdentification.idValue", 0, false, "fullText", delegator);
|
||||
this.addTextField(doc, "identificationValue", idValue, false, "fullText", delegator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class ProductDocument implements LuceneDocument {
|
||||
} else if (thruDate != null) {
|
||||
nextReIndex = this.checkSetNextReIndex(thruDate, nextReIndex);
|
||||
}
|
||||
this.addTextFieldByWeight(doc, "variantProductId", variantProductAssoc.getString("productIdTo"), "index.weight.Variant.Product.productId", 0, false, "fullText", delegator);
|
||||
this.addTextField(doc, "variantProductId", variantProductAssoc.getString("productIdTo"), false, "fullText", delegator);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public class ProductDocument implements LuceneDocument {
|
||||
try {
|
||||
Map<String, Object> drContext = UtilMisc.<String, Object>toMap("product", product);
|
||||
String contentText = DataResourceWorker.renderDataResourceAsText(null, delegator, productContentAndInfo.getString("dataResourceId"), drContext, null, null, false);
|
||||
this.addTextFieldByWeight(doc, "content", contentText, null, weight, false, "fullText", delegator);
|
||||
this.addTextField(doc, "content", contentText, false, "fullText", delegator);
|
||||
} catch (IOException e1) {
|
||||
Debug.logError(e1, "Error getting content text to index", module);
|
||||
} catch (GeneralException e1) {
|
||||
@@ -279,26 +279,10 @@ public class ProductDocument implements LuceneDocument {
|
||||
}
|
||||
|
||||
// An attempt to boost/weight values in a similar manner to what OFBiz product search does.
|
||||
private void addTextFieldByWeight(Document doc, String fieldName, String value, String property, int defaultWeight, boolean store, String fullTextFieldName, Delegator delegator) {
|
||||
private void addTextField(Document doc, String fieldName, String value, boolean store, String fullTextFieldName, Delegator delegator) {
|
||||
if (fieldName == null) return;
|
||||
|
||||
float weight = 0;
|
||||
if (property != null) {
|
||||
try {
|
||||
weight = EntityUtilProperties.getPropertyAsFloat("prodsearch", property, 0).floatValue();
|
||||
} catch (Exception e) {
|
||||
Debug.logWarning("Could not parse weight number: " + e.toString(), module);
|
||||
}
|
||||
} else if (defaultWeight > 0) {
|
||||
weight = defaultWeight;
|
||||
}
|
||||
if (weight == 0 && !store) {
|
||||
return;
|
||||
}
|
||||
Field field = new TextField(fieldName, checkValue(value), (store? Field.Store.YES: Field.Store.NO));
|
||||
if (weight > 0 && weight != 1) {
|
||||
field.setBoost(weight);
|
||||
}
|
||||
doc.add(field);
|
||||
if (fullTextFieldName != null) {
|
||||
doc.add(new TextField(fullTextFieldName, checkValue(value), Field.Store.NO));
|
||||
|
||||
@@ -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_6_0;
|
||||
private static final Version LUCENE_VERSION = Version.LUCENE_7_1_0;
|
||||
|
||||
private SearchWorker() {}
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
dependencies {
|
||||
pluginLibsCompile 'org.apache.solr:solr-core:6.6.0'
|
||||
pluginLibsCompile 'org.apache.solr:solr-core:7.1.0'
|
||||
pluginLibsCompile 'com.google.guava:guava:20.0'
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ public final class SolrUtil {
|
||||
httpLogin.setConfig(requestConfig);
|
||||
CloseableHttpResponse loginResponse = httpClient.execute(httpLogin, httpContext);
|
||||
loginResponse.close();
|
||||
return new HttpSolrClient(solrUrl + "/" + solrIndexName, httpClient);
|
||||
return new HttpSolrClient.Builder(solrUrl + "/" + solrIndexName).withHttpClient(httpClient).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
package org.apache.ofbiz.solr.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.jasper.tagplugins.jstl.core.Remove;
|
||||
import org.apache.ofbiz.base.util.UtilMisc;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.entity.GenericValue;
|
||||
import org.apache.ofbiz.entity.util.EntityQuery;
|
||||
import org.apache.ofbiz.service.ServiceUtil;
|
||||
import org.apache.ofbiz.service.testtools.OFBizTestCase;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.common.SolrDocument;
|
||||
import org.apache.solr.common.SolrDocumentList;
|
||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
|
||||
public class SolrTests extends OFBizTestCase {
|
||||
|
||||
protected GenericValue userLogin = null;
|
||||
private Map<String, Object> context;
|
||||
private Map<String, Object> emptyContext = new HashMap<String, Object>();
|
||||
private Map<String, Object> response;
|
||||
private String validTestProductId = "GZ-1006";
|
||||
private String validTestProductId_2 = "GZ-1005";
|
||||
private String invalidTestProductId = validTestProductId + validTestProductId;
|
||||
|
||||
public SolrTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", "system").queryOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void testAddProductToIndex() throws Exception {
|
||||
|
||||
GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", validTestProductId), false);
|
||||
|
||||
Map<String, Object> ctx = new HashMap<String, Object>();
|
||||
ctx.put("instance", product);
|
||||
|
||||
Map<String, Object> resp = dispatcher.runSync("addToSolr", ctx);
|
||||
assertTrue("Could not init search index", ServiceUtil.isSuccess(resp));
|
||||
|
||||
Map<String, Object> sctx = new HashMap<String, Object>();
|
||||
sctx.put("productCategoryId", "102");
|
||||
|
||||
Map<String, Object> sresp = dispatcher.runSync("solrProductsSearch", sctx);
|
||||
assertTrue("Could not query search index", ServiceUtil.isSuccess(sresp));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testAddToSolrIndex() throws Exception{
|
||||
context = new HashMap<>();
|
||||
context.put("productId", validTestProductId);
|
||||
response = dispatcher.runSync("addToSolrIndex", context);
|
||||
assertTrue("Could not add Product to Index", ServiceUtil.isSuccess(
|
||||
response));
|
||||
}
|
||||
|
||||
public void testAddToSolrIndex_invalidProduct() throws Exception {
|
||||
context = new HashMap<>();
|
||||
context.put("productId", invalidTestProductId);
|
||||
response = dispatcher.runSync("addToSolrIndex", context);
|
||||
assertTrue("Could not test the addition of an invalid product to the Solr index", ServiceUtil.isSuccess(
|
||||
response));
|
||||
}
|
||||
|
||||
public void testAddListToSolrIndex() throws Exception {
|
||||
List<Map<String, Object>> products = new ArrayList<>();
|
||||
Map<String, Object> product_1 = new HashMap<>();
|
||||
Map<String, Object> product_2 = new HashMap<>();
|
||||
GenericValue validTestProduct = delegator.findOne("Product", UtilMisc.toMap("productId", validTestProductId), false);
|
||||
GenericValue validTestProduct_2 = delegator.findOne("Product", UtilMisc.toMap("productId", validTestProductId_2), false);
|
||||
|
||||
product_1.put("productId", validTestProduct);
|
||||
product_2.put("productId", validTestProduct_2);
|
||||
|
||||
products.add(product_1);
|
||||
products.add(product_2);
|
||||
context = new HashMap<>();
|
||||
context.put("fieldList", products);
|
||||
|
||||
response = dispatcher.runSync("addListToSolrIndex", context);
|
||||
assertTrue("Could not add products to index", ServiceUtil.isSuccess(response));
|
||||
|
||||
}
|
||||
|
||||
public void testAddListToSolrIndex_invalidProducts() throws Exception {
|
||||
List<Map<String, Object>> products = new ArrayList<>();
|
||||
Map<String, Object> product_1 = new HashMap<>();
|
||||
Map<String, Object> product_2 = new HashMap<>();
|
||||
GenericValue testProduct = delegator.findOne("Product", UtilMisc.toMap("productId", validTestProductId), false);
|
||||
GenericValue testProduct_2 = delegator.findOne("Product", UtilMisc.toMap("productId", validTestProductId_2), false);
|
||||
|
||||
testProduct.replace("productId", invalidTestProductId);
|
||||
testProduct.replace("productId", invalidTestProductId);
|
||||
|
||||
product_1.put("productId", testProduct);
|
||||
product_2.put("productId", testProduct_2);
|
||||
|
||||
products.add(product_1);
|
||||
products.add(product_2);
|
||||
context = new HashMap<>();
|
||||
context.put("fieldList", products);
|
||||
|
||||
response = dispatcher.runSync("addListToSolrIndex", context);
|
||||
assertTrue("Could not test adding invalid products to index", ServiceUtil.isSuccess(response));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<entity-engine-xml>
|
||||
|
||||
|
||||
</entity-engine-xml>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<test-suite suite-name="solrtests"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
|
||||
|
||||
<test-case case-name="solr-tests-data-load">
|
||||
<entity-xml action="load" entity-xml-url="component://solr/testdef/data/SolrTestsData.xml"/>
|
||||
</test-case>
|
||||
|
||||
<test-case case-name="solr-tests"><junit-test-suite class-name="org.apache.ofbiz.solr.test.SolrTests"/></test-case>
|
||||
|
||||
</test-suite>
|
||||
Reference in New Issue
Block a user