Author: jleroux
Date: Sun Apr 17 11:08:13 2016 New Revision: 1739578 URL: http://svn.apache.org/viewvc?rev=1739578&view=rev Log: Reverts r1739557 was ------------------------------------------------------------------------ "Applied fix from trunk for revision: 1730320" ------------------------------------------------------------------------ r1730320 | shijh | 2016-02-14 12:59:59 +0100 (dim. 14 févr. 2016) | 1 ligne Refs OFBIZ-6715 Solr rebuild problem ------------------------------------------------------------------------ For some reasons tests does not pass, I did not check why Added: ofbiz/branches/release15.12/specialpurpose/solr/webapp/solr/WEB-INF/lib/httpmime-4.4.1.jar - copied unchanged from r1739556, ofbiz/branches/release15.12/specialpurpose/solr/webapp/solr/WEB-INF/lib/httpmime-4.4.1.jar Removed: ofbiz/branches/release15.12/specialpurpose/solr/lib/runtime/httpmime-4.4.1.jar Modified: ofbiz/branches/release15.12/ (props changed) ofbiz/branches/release15.12/specialpurpose/solr/config/solrconfig.properties ofbiz/branches/release15.12/specialpurpose/solr/home/solrdefault/conf/schema.xml ofbiz/branches/release15.12/specialpurpose/solr/servicedef/solrservices.xml ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrProductSearch.java ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java Propchange: ofbiz/branches/release15.12/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sun Apr 17 11:08:13 2016 @@ -9,4 +9,4 @@ /ofbiz/branches/json-integration-refactoring:1634077-1635900 /ofbiz/branches/multitenant20100310:921280-927264 /ofbiz/branches/release13.07:1547657 -/ofbiz/trunk:1722712,1723007,1723248,1724402,1724411,1724566,1724689,1724763,1724916,1724918,1724925,1724930,1724940,1724943,1724946,1724951,1724957,1724975,1724978,1725006,1725217,1725257,1725561,1725574,1726388,1726486,1726493,1726828,1728398,1728411,1729005,1729078,1729609,1729809,1730035,1730320,1730456,1730735-1730736,1730747,1730758,1730882,1730889,1731382,1731396,1732454,1732570,1732721,1733951,1733956,1734246,1734269,1734276,1734912,1734918,1735021,1735244,1735385,1735398,1735569,1735731,1735734,1735750,1735753,1735756,1735759,1735773,1736083,1736087,1736272,1736434,1736628,1736851,1736854,1736890,1737156,1737440,1738235,1738303,1738407,1738902,1739438,1739448,1739571 +/ofbiz/trunk:1722712,1723007,1723248,1724402,1724411,1724566,1724689,1724763,1724916,1724918,1724925,1724930,1724940,1724943,1724946,1724951,1724957,1724975,1724978,1725006,1725217,1725257,1725561,1725574,1726388,1726486,1726493,1726828,1728398,1728411,1729005,1729078,1729609,1729809,1730035,1730456,1730735-1730736,1730747,1730758,1730882,1730889,1731382,1731396,1732454,1732570,1732721,1733951,1733956,1734246,1734269,1734276,1734912,1734918,1735021,1735244,1735385,1735398,1735569,1735731,1735734,1735750,1735753,1735756,1735759,1735773,1736083,1736087,1736272,1736434,1736628,1736851,1736854,1736890,1737156,1737440,1738235,1738303,1738407,1738902,1739438,1739448,1739571 Modified: ofbiz/branches/release15.12/specialpurpose/solr/config/solrconfig.properties URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/config/solrconfig.properties?rev=1739578&r1=1739577&r2=1739578&view=diff ============================================================================== --- ofbiz/branches/release15.12/specialpurpose/solr/config/solrconfig.properties (original) +++ ofbiz/branches/release15.12/specialpurpose/solr/config/solrconfig.properties Sun Apr 17 11:08:13 2016 @@ -19,7 +19,7 @@ # Solr configuration for custom OFBiz solr modules # Webapp access details -solr.webapp.protocol=https +solr.webapp.protocol=http solr.webapp.domainName=localhost # By default, port is same as OFBiz server, but can be overridden here. solr.webapp.portOverride= @@ -33,15 +33,4 @@ solr.eca.enabled=false # If true, connection errors during ECAs/SECAs are treated as warnings/failures rather than errors. # If false, connection errors are treated as errors, and parent transactions are aborted. -solr.eca.treatConnectErrorNonFatal=true - -# The username and password of a solr client to CRUD an index -solr.client.username=admin -solr.client.password=ofbiz - -# Socket and connection timeout of a solr client -solr.client.socket.timeout= -solr.client.connection.timeout= - -# If true, trust self signed certification, default is false. -solr.client.trust.selfsigned.cert=true +solr.eca.treatConnectErrorNonFatal=true \ No newline at end of file Modified: ofbiz/branches/release15.12/specialpurpose/solr/home/solrdefault/conf/schema.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/home/solrdefault/conf/schema.xml?rev=1739578&r1=1739577&r2=1739578&view=diff ============================================================================== --- ofbiz/branches/release15.12/specialpurpose/solr/home/solrdefault/conf/schema.xml (original) +++ ofbiz/branches/release15.12/specialpurpose/solr/home/solrdefault/conf/schema.xml Sun Apr 17 11:08:13 2016 @@ -45,7 +45,7 @@ that avoids logging every request --> -<schema name="products" version="1.5"> +<schema name="example" version="1.5"> <!-- attribute "name" is the name of this schema and is only used for display purposes. version="x.y" is Solr's version number for the schema syntax and semantics. It should not normally be changed by applications. @@ -127,27 +127,20 @@ in a compatible way. Any analysis applied to the <uniqueKey> should _not_ produce multiple tokens --> - <!-- <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> --> + <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> - <field name="productId" type="string" indexed="true" stored="true" required="true" multiValued="false" /> - - <field name="sku" type="text_general" indexed="true" stored="true"/> - <field name="internalName" type="text_general" indexed="true" stored="true" multiValued="true"/> - <field name="alphaNameSort" type="alphaOnlySort" indexed="true" stored="false"/> + <field name="sku" type="text_en_splitting_tight" indexed="true" stored="true" omitNorms="true"/> + <field name="name" type="text_general" indexed="true" stored="true"/> <field name="manu" type="text_general" indexed="true" stored="true" omitNorms="true"/> <field name="cat" type="string" indexed="true" stored="true" multiValued="true"/> - <field name="catalog" type="string" indexed="true" stored="true" multiValued="true"/> <field name="features" type="text_general" indexed="true" stored="true" multiValued="true"/> - <field name="attributes" type="text_general" indexed="true" stored="true" multiValued="true"/> + <field name="includes" type="text_general" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" /> + <field name="weight" type="float" indexed="true" stored="true"/> - <field name="listPrice" type="float" indexed="true" stored="true"/> - <field name="defaultPrice" type="float" indexed="true" stored="true"/> + <field name="price" type="float" indexed="true" stored="true"/> <field name="popularity" type="int" indexed="true" stored="true" /> - <field name="inStock" type="int" indexed="true" stored="true" /> - <field name="isVirtual" type="boolean" indexed="true" stored="true" /> - <field name="isDigital" type="boolean" indexed="true" stored="true" /> - <field name="isPhysical" type="boolean" indexed="true" stored="true" /> - + <field name="inStock" type="boolean" indexed="true" stored="true" /> + <field name="store" type="location" indexed="true" stored="true"/> <!-- Common metadata fields, named specifically to match up with @@ -159,27 +152,18 @@ "resourcename": From SolrCell request param resource.name --> <field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/> - <field name="title_i18n_en" type="text_general" indexed="true" stored="true" multiValued="true"/> - <field name="title_i18n_de" type="text_general" indexed="true" stored="true" multiValued="true"/> - <field name="title_i18n_fr" type="text_general" indexed="true" stored="true" multiValued="true"/> <field name="subject" type="text_general" indexed="true" stored="true"/> <field name="description" type="text_general" indexed="true" stored="true"/> - <field name="description_i18n_en" type="text_general" indexed="true" stored="true"/> - <field name="description_i18n_de" type="text_general" indexed="true" stored="true"/> - <field name="description_i18n_fr" type="text_general" indexed="true" stored="true"/> - <field name="longdescription" type="text_general" indexed="true" stored="true"/> - <field name="longdescription_i18n_en" type="text_general" indexed="true" stored="true"/> - <field name="longdescription_i18n_de" type="text_general" indexed="true" stored="true"/> - <field name="longdescription_i18n_fr" type="text_general" indexed="true" stored="true"/> <field name="comments" type="text_general" indexed="true" stored="true"/> <field name="author" type="text_general" indexed="true" stored="true"/> <field name="keywords" type="text_general" indexed="true" stored="true"/> + <field name="category" type="text_general" indexed="true" stored="true"/> + <field name="resourcename" type="text_general" indexed="true" stored="true"/> + <field name="url" type="text_general" indexed="true" stored="true"/> <field name="content_type" type="string" indexed="true" stored="true" multiValued="true"/> <field name="last_modified" type="date" indexed="true" stored="true"/> <field name="links" type="string" indexed="true" stored="true" multiValued="true"/> - <field name="smallImage" type="text_general" indexed="true" stored="true"/> - <field name="mediumImage" type="text_general" indexed="true" stored="true"/> - <field name="largeImage" type="text_general" indexed="true" stored="true"/> + <field name="_src_" type="string" indexed="false" stored="true"/> <!-- Main body of document extracted by SolrCell. NOTE: This field is not indexed by default, since it is also copied to "text" @@ -271,7 +255,7 @@ <!-- Field to use to determine and enforce document uniqueness. Unless this field is marked with required="false", it will be a required field --> - <uniqueKey>productId</uniqueKey> + <uniqueKey>id</uniqueKey> <!-- DEPRECATED: The defaultSearchField is consulted by various query parsers when parsing a query string that isn't explicit about the field. Machine (non-user) @@ -293,15 +277,28 @@ or to add multiple fields to the same field for easier/faster searching. --> <copyField source="cat" dest="text"/> - <copyField source="internalName" dest="text"/> + <copyField source="name" dest="text"/> <copyField source="manu" dest="text"/> <copyField source="features" dest="text"/> - <copyField source="attributes" dest="text"/> - <copyField source="*_i18n_en" dest="text" /> - <copyField source="*_i18n_de" dest="text" /> - <copyField source="*_i18n_fr" dest="text" /> + <copyField source="includes" dest="text"/> <copyField source="manu" dest="manu_exact"/> + <!-- Copy the price into a currency enabled field (default USD) --> + <copyField source="price" dest="price_c"/> + + <!-- Text fields from SolrCell to search by default in our catch-all field --> + <copyField source="title" dest="text"/> + <copyField source="author" dest="text"/> + <copyField source="description" dest="text"/> + <copyField source="keywords" dest="text"/> + <copyField source="content" dest="text"/> + <copyField source="content_type" dest="text"/> + <copyField source="resourcename" dest="text"/> + <copyField source="url" dest="text"/> + + <!-- Create a string version of author for faceting --> + <copyField source="author" dest="author_s"/> + <!-- Above, multiple source fields are copied to the [text] field. Another way to map multiple source fields to the same destination field is to use the dynamic field syntax. Modified: ofbiz/branches/release15.12/specialpurpose/solr/servicedef/solrservices.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/servicedef/solrservices.xml?rev=1739578&r1=1739577&r2=1739578&view=diff ============================================================================== --- ofbiz/branches/release15.12/specialpurpose/solr/servicedef/solrservices.xml (original) +++ ofbiz/branches/release15.12/specialpurpose/solr/servicedef/solrservices.xml Sun Apr 17 11:08:13 2016 @@ -24,13 +24,20 @@ under the License. <description>Content Component Services</description> <vendor>OFBiz</vendor> + <!-- Test Case --> + <service name="SolrProductSearch" engine="java" + transaction-timeout="72000" + location="org.ofbiz.solr.SolrProductSearch" + invoke="SolrProductSearch" debug="true" validate="true"> + <description>First Test with Solr</description> + </service> + <!-- Rebuild the Solr Tree --> <service name="rebuildSolrIndex" engine="java" transaction-timeout="72000" location="org.ofbiz.solr.SolrProductSearch" invoke="rebuildSolrIndex" debug="true" validate="true"> <description>rebuild SOLR Index</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" name="treatConnectErrorNonFatal" optional="true" type="Boolean" default-value="false" /> </service> @@ -41,7 +48,6 @@ under the License. invoke="addToSolr" debug="true" validate="true"> <description>Adds product to solr, with product denoted by productId field in instance attribute - intended for use with ECAs/SECAs</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" name="instance" optional="false" type="org.ofbiz.entity.GenericValue" /> </service> @@ -50,7 +56,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="addToSolrIndex" debug="true" validate="true"> <description>Add a Product to Solr Index</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" name="treatConnectErrorNonFatal" optional="true" type="Boolean" /> <attribute mode="IN" name="productId" optional="false" type="String" /> <attribute mode="IN" name="sku" optional="true" type="String" /> @@ -83,7 +88,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="addListToSolrIndex" debug="true" validate="true"> <description>Add a List of Products to Solr Index and flush after all have been added</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" name="treatConnectErrorNonFatal" optional="true" type="Boolean" /> <attribute mode="IN" name="fieldList" optional="false" type="List" /> <attribute mode="OUT" name="errorType" optional="true" type="String" /> @@ -95,7 +99,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="productsSearch" debug="true" validate="true"> <description>Run a query on Solr and return the results</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" optional="false" name="productCategoryId" type="String"/> <attribute mode="IN" optional="true" name="viewSize" type="String"/> <attribute mode="IN" optional="true" name="viewIndex" type="String"/> @@ -112,7 +115,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="keywordSearch" debug="true" validate="true"> <description>Run a query on Solr and return the results</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" optional="false" name="query" type="String"/> <attribute mode="IN" optional="true" name="viewSize" type="String"/> <attribute mode="IN" optional="true" name="viewIndex" type="String"/> @@ -137,7 +139,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="runSolrQuery" debug="true" validate="true"> <description>Run a query on Solr and return the results</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" optional="false" name="query" type="String"/> <attribute mode="IN" optional="true" name="viewSize" type="Integer"/> <attribute mode="IN" optional="true" name="viewIndex" type="Integer"/> @@ -157,7 +158,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="getAvailableCategories" debug="true" validate="true"> <description>Run a query on Solr and return the results</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" optional="true" name="productCategoryId" type="String"/> <attribute mode="IN" optional="true" name="productId" type="String"/> <attribute mode="IN" optional="true" name="catalogId" type="String"/> @@ -173,7 +173,6 @@ under the License. location="org.ofbiz.solr.SolrProductSearch" invoke="getSideDeepCategories" debug="true" validate="true"> <description>Run a query on Solr and return the results</description> - <attribute mode="IN" name="indexName" optional="false" type="String"/> <attribute mode="IN" optional="true" name="productCategoryId" type="String"/> <attribute mode="IN" optional="true" name="catalogId" type="String"/> <attribute name="numFound" type="Long" mode="OUT" optional="false"/> Modified: ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrProductSearch.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrProductSearch.java?rev=1739578&r1=1739577&r2=1739578&view=diff ============================================================================== --- ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrProductSearch.java (original) +++ ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrProductSearch.java Sun Apr 17 11:08:13 2016 @@ -62,6 +62,7 @@ public abstract class SolrProductSearch public static final String module = SolrProductSearch.class.getName(); + /** * Adds product to solr, with product denoted by productId field in instance attribute * - intended for use with ECAs/SECAs. @@ -72,7 +73,6 @@ public abstract class SolrProductSearch Delegator delegator = dctx.getDelegator(); GenericValue productInstance = (GenericValue) context.get("instance"); String productId = (String) productInstance.get("productId"); - String solrIndexName = (String) context.get("indexName"); if (SolrUtil.isSolrEcaEnabled()) { // Debug.logVerbose("Solr: addToSolr: Running indexing for productId '" + productId + "'", module); @@ -80,7 +80,6 @@ public abstract class SolrProductSearch GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false); Map<String, Object> dispatchContext = ProductUtil.getProductContent(product, dctx, context); dispatchContext.put("treatConnectErrorNonFatal", SolrUtil.isEcaTreatConnectErrorNonFatal()); - dispatchContext.put("indexName", solrIndexName); Map<String, Object> runResult = dispatcher.runSync("addToSolrIndex", dispatchContext); String runMsg = ServiceUtil.getErrorMessage(runResult); if (UtilValidate.isEmpty(runMsg)) { @@ -115,14 +114,13 @@ public abstract class SolrProductSearch HttpSolrClient client = null; Map<String, Object> result; String productId = (String) context.get("productId"); - String solrIndexName = (String) context.get("indexName"); // connectErrorNonFatal is a necessary option because in some cases it may be considered normal that solr server is unavailable; // don't want to return error and abort transactions in these cases. Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal"); try { Debug.logInfo("Solr: Generating and indexing document for productId '" + productId + "'", module); - client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName); + client = new HttpSolrClient(SolrUtil.solrUrl); //Debug.log(server.ping().toString()); // Construct Documents @@ -187,7 +185,6 @@ public abstract class SolrProductSearch * This is faster than reflushing the index each time. */ public static Map<String, Object> addListToSolrIndex(DispatchContext dctx, Map<String, Object> context) throws GenericEntityException { - String solrIndexName = (String) context.get("indexName"); HttpSolrClient client = null; Map<String, Object> result; Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal"); @@ -207,7 +204,7 @@ public abstract class SolrProductSearch docs.add(doc1); } // push Documents to server - client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName); + client = new HttpSolrClient(SolrUtil.solrUrl); client.add(docs); client.commit(); @@ -261,10 +258,9 @@ public abstract class SolrProductSearch public static Map<String, Object> runSolrQuery(DispatchContext dctx, Map<String, Object> context) { // get Connection HttpSolrClient client = null; - String solrIndexName = (String) context.get("indexName"); Map<String, Object> result; try { - client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName); + client = new HttpSolrClient(SolrUtil.solrUrl); // create Query Object SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery((String) context.get("query")); @@ -367,7 +363,6 @@ public abstract class SolrProductSearch public static Map<String, Object> productsSearch(DispatchContext dctx, Map<String, Object> context) { Map<String, Object> result; LocalDispatcher dispatcher = dctx.getDispatcher(); - String solrIndexName = (String) context.get("indexName"); try { Map<String, Object> dispatchMap = new HashMap<String, Object>(); @@ -386,7 +381,6 @@ public abstract class SolrProductSearch dispatchMap.put("facet", false); dispatchMap.put("spellcheck", true); dispatchMap.put("highlight", true); - dispatchMap.put("indexName", solrIndexName); Map<String, Object> searchResult = dispatcher.runSync("runSolrQuery", dispatchMap); QueryResponse queryResult = (QueryResponse) searchResult.get("queryResult"); result = ServiceUtil.returnSuccess(); @@ -409,7 +403,6 @@ public abstract class SolrProductSearch public static Map<String, Object> keywordSearch(DispatchContext dctx, Map<String, Object> context) { Map<String, Object> result; LocalDispatcher dispatcher = dctx.getDispatcher(); - String solrIndexName = (String) context.get("indexName"); try { if (context.get("query") == null || context.get("query").equals("")) @@ -425,8 +418,6 @@ public abstract class SolrProductSearch if (context.get("queryFilter") != null) dispatchMap.put("queryFilter", context.get("queryFilter")); dispatchMap.put("spellcheck", true); - dispatchMap.put("indexName", solrIndexName); - Map<String, Object> searchResult = dispatcher.runSync("runSolrQuery", dispatchMap); QueryResponse queryResult = (QueryResponse) searchResult.get("queryResult"); @@ -488,7 +479,6 @@ public abstract class SolrProductSearch */ public static Map<String, Object> getAvailableCategories(DispatchContext dctx, Map<String, Object> context) { Map<String, Object> result; - String solrIndexName = (String) context.get("indexName"); try { boolean displayProducts = false; if (UtilValidate.isNotEmpty(context.get("displayProducts"))) @@ -504,9 +494,10 @@ public abstract class SolrProductSearch if (UtilValidate.isNotEmpty(context.get("catalogId"))) catalogId = (String) context.get("catalogId"); + //String productCategoryId = (String) context.get("productCategoryId") != null ? CategoryUtil.getCategoryNameWithTrail((String) context.get("productCategoryId"), dctx): null; String productCategoryId = (String) context.get("productCategoryId") != null ? CategoryUtil.getCategoryNameWithTrail((String) context.get("productCategoryId"),dctx) : null; - Debug.logInfo("productCategoryId " + productCategoryId, module); - Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, productCategoryId, (String) context.get("productId"), displayProducts, viewIndex, viewSize, solrIndexName); + Debug.logInfo("productCategoryId "+productCategoryId, module); + Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, productCategoryId, (String) context.get("productId"), displayProducts, viewIndex, viewSize); QueryResponse cat = (QueryResponse) query.get("rows"); result = ServiceUtil.returnSuccess(); @@ -517,7 +508,7 @@ public abstract class SolrProductSearch FacetField field = (FacetField) catIterator.next(); List<Count> catL = (List<Count>) field.getValues(); if (catL != null) { - // Debug.logInfo("FacetFields = " + catL, module); + // log.info("FacetFields = "+catL); for (Iterator<Count> catIter = catL.iterator(); catIter.hasNext();) { FacetField.Count f = (FacetField.Count) catIter.next(); if (f.getCount() > 0) { @@ -526,7 +517,7 @@ public abstract class SolrProductSearch } result.put("categories", categories); result.put("numFound", cat.getResults().getNumFound()); - // Debug.logInfo("The returned map is this:" + result, module); + // log.info("The returned map is this:"+result); } } } catch (Exception e) { @@ -542,7 +533,6 @@ public abstract class SolrProductSearch */ public static Map<String, Object> getSideDeepCategories(DispatchContext dctx, Map<String, Object> context) { Map<String, Object> result; - String solrIndexName = (String) context.get("indexName"); try { String catalogId = null; if (UtilValidate.isNotEmpty(context.get("catalogId"))) @@ -566,7 +556,7 @@ public abstract class SolrProductSearch int level = Integer.parseInt(categoryPathArray[0]); String facetQuery = CategoryUtil.getFacetFilterForCategory(categoryPath, dctx); //Debug.logInfo("categoryPath: "+categoryPath + " facetQuery: "+facetQuery,module); - Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, categoryPath, null, facetQuery, false, 0, 0, solrIndexName); + Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, categoryPath, null, facetQuery,false, 0, 0); QueryResponse cat = (QueryResponse) query.get("rows"); List<Map<String, Object>> categories = new ArrayList<Map<String, Object>>(); @@ -622,13 +612,12 @@ public abstract class SolrProductSearch GenericDelegator delegator = (GenericDelegator) dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); - Locale locale = (Locale) context.get("locale"); - String solrIndexName = (String) context.get("indexName"); + Locale locale = new Locale("de_DE"); Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal"); try { - client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName); + client = new HttpSolrClient(SolrUtil.solrUrl); // now lets fetch all products List<Map<String, Object>> solrDocs = new ArrayList<Map<String, Object>>(); @@ -653,7 +642,7 @@ public abstract class SolrProductSearch // THis adds all products to the Index (instantly) Map<String, Object> runResult = dispatcher.runSync("addListToSolrIndex", UtilMisc.toMap("fieldList", solrDocs, "userLogin", userLogin, - "locale", locale, "indexName", solrIndexName, "treatConnectErrorNonFatal", treatConnectErrorNonFatal)); + "locale", locale, "treatConnectErrorNonFatal", treatConnectErrorNonFatal)); String runMsg = ServiceUtil.getErrorMessage(runResult); if (UtilValidate.isEmpty(runMsg)) { Modified: ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java?rev=1739578&r1=1739577&r2=1739578&view=diff ============================================================================== --- ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java (original) +++ ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java Sun Apr 17 11:08:13 2016 @@ -18,26 +18,12 @@ *******************************************************************************/ package org.ofbiz.solr; -import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import javax.net.ssl.SSLContext; - -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.ssl.SSLContexts; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrRequest.METHOD; import org.apache.solr.client.solrj.impl.HttpSolrClient; @@ -47,7 +33,6 @@ import org.ofbiz.base.component.Componen import org.ofbiz.base.component.ComponentConfig.WebappInfo; import org.ofbiz.base.component.ComponentException; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.FileUtil; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -56,7 +41,7 @@ import org.ofbiz.entity.GenericEntityExc /** * Solr utility class. */ -public final class SolrUtil { +public abstract class SolrUtil { public static final String module = SolrUtil.class.getName(); private static String[] solrProdAttribute = { "productId", "internalName", "manu", "size", "smallImage", "mediumImage", "largeImage", "listPrice", "defaultPrice", "inStock", "isVirtual" }; @@ -64,27 +49,7 @@ public final class SolrUtil { public static final String solrConfigName = "solrconfig.properties"; public static final String solrUrl = makeSolrWebappUrl(); - protected static final String socketTimeoutString = UtilProperties.getPropertyValue(solrConfigName, "solr.client.socket.timeout"); - - protected static final String connectionTimeoutString = UtilProperties.getPropertyValue(solrConfigName, "solr.client.connection.timeout"); - - protected static final String clientUsername = UtilProperties.getPropertyValue(solrConfigName, "solr.client.username"); - - protected static final String clientPassword = UtilProperties.getPropertyValue(solrConfigName, "solr.client.password"); - - protected static final Integer socketTimeout = getSocketTimeout(); - - protected static final Integer connectionTimeout = getConnectionTimeout(); - - protected static final String trustSelfSignedCertString = UtilProperties.getPropertyValue(solrConfigName, "solr.client.trust.selfsigned.cert", "false"); - - protected static final boolean trustSelfSignedCert = getTrustSelfSignedCert(); - - protected SolrUtil() { - // empty constructor - } - - public static String makeSolrWebappUrl() { + public static String makeSolrWebappUrl() { final String solrWebappProtocol = UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.protocol"); final String solrWebappDomainName = UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.domainName"); final String solrWebappPath = UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.path"); @@ -93,42 +58,14 @@ public final class SolrUtil { String solrPort; if (UtilValidate.isNotEmpty(solrWebappPortOverride)) { solrPort = solrWebappPortOverride; - } else { + } + else { solrPort = UtilProperties.getPropertyValue("url", ("https".equals(solrWebappProtocol) ? "port.https" : "port.http")); } return solrWebappProtocol + "://" + solrWebappDomainName + ":" + solrPort + solrWebappPath; } - private static Integer getSocketTimeout() { - if (UtilValidate.isNotEmpty(socketTimeoutString)) { - try { - return Integer.parseInt(socketTimeoutString); - } catch (Exception e) { - return null; - } - } - return null; - } - - private static Integer getConnectionTimeout() { - if (UtilValidate.isNotEmpty(connectionTimeoutString)) { - try { - return Integer.parseInt(connectionTimeoutString); - } catch (Exception e) { - return null; - } - } - return null; - } - - private static boolean getTrustSelfSignedCert() { - if ("true".equals(trustSelfSignedCertString)) { - return true; - } - return false; - } - public static boolean isSolrEcaEnabled() { Boolean ecaEnabled = null; String sysProp = System.getProperty("ofbiz.solr.eca.enabled"); @@ -244,18 +181,18 @@ public final class SolrUtil { return doc1; } - public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, boolean displayproducts, int viewIndex, int viewSize, String solrIndexName) { - return categoriesAvailable(catalogId, categoryId, productId, null, displayproducts, viewIndex, viewSize, solrIndexName); + public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, boolean displayproducts, int viewIndex, int viewSize) { + return categoriesAvailable(catalogId,categoryId,productId,null,displayproducts,viewIndex,viewSize); } - public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, String facetPrefix, boolean displayproducts, int viewIndex, int viewSize, String solrIndexName) { + public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, String facetPrefix, boolean displayproducts, int viewIndex, int viewSize) { // create the data model Map<String, Object> result = new HashMap<String, Object>(); HttpSolrClient client = null; QueryResponse returnMap = new QueryResponse(); try { // do the basic query - client = getInstance().getHttpSolrClient(solrIndexName); + client = new HttpSolrClient(solrUrl); // create Query Object String query = "inStock[1 TO *]"; if (categoryId != null) @@ -298,68 +235,4 @@ public final class SolrUtil { return result; } - private CloseableHttpClient getAllowAllHttpClient() { - try { - // Trust own CA and all self-signed certs - SSLContext sslContext = SSLContexts.custom() - .loadTrustMaterial(FileUtil.getFile("component://base/config/ofbizssl.jks"), "changeit".toCharArray(), - new TrustSelfSignedStrategy()) - .build(); - // No host name verifier - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - sslContext, - NoopHostnameVerifier.INSTANCE); - CloseableHttpClient httpClient = HttpClients.custom() - .setSSLSocketFactory(sslsf) - .build(); - return httpClient; - } catch (Exception e) { - return HttpClients.createDefault(); - } - } - - public static SolrUtil getInstance() { - return new SolrUtil(); - } - - public HttpSolrClient getHttpSolrClient(String solrIndexName) throws ClientProtocolException, IOException { - HttpClientContext httpContext = HttpClientContext.create(); - - CloseableHttpClient httpClient = null; - if (trustSelfSignedCert) { - httpClient = getAllowAllHttpClient(); - } else { - httpClient = HttpClients.createDefault(); - } - - RequestConfig requestConfig = null; - if (UtilValidate.isNotEmpty(socketTimeout) && UtilValidate.isNotEmpty(connectionTimeout)) { - requestConfig = RequestConfig.custom() - .setSocketTimeout(socketTimeout) - .setConnectTimeout(connectionTimeout) - .setRedirectsEnabled(true) - .build(); - } else if (UtilValidate.isNotEmpty(socketTimeout)) { - requestConfig = RequestConfig.custom() - .setSocketTimeout(socketTimeout) - .setRedirectsEnabled(true) - .build(); - } else if (UtilValidate.isNotEmpty(connectionTimeout)) { - requestConfig = RequestConfig.custom() - .setConnectTimeout(connectionTimeout) - .setRedirectsEnabled(true) - .build(); - } else { - requestConfig = RequestConfig.custom() - .setRedirectsEnabled(true) - .build(); - } - - HttpGet httpLogin = new HttpGet(solrUrl + "/control/login?USERNAME=" + clientUsername + "&PASSWORD=" + clientPassword); - httpLogin.setConfig(requestConfig); - CloseableHttpResponse loginResponse = httpClient.execute(httpLogin, httpContext); - loginResponse.close(); - return new HttpSolrClient(solrUrl + "/" + solrIndexName, httpClient); - } - } |
Free forum by Nabble | Edit this page |