Monday, April 16, 2018

Solr Search Customization by introducing a new facet in Websphere Commerce

schema.xml 

This file defines the schema fields and data type of the fields.This file also defines the SOLR field settings. Searchable,sortable SOLR fields are defined here.

Go to the below folder
<WCDE>\search\solr\home\MC_<master_catalog_id>\en_US\CatalogEntry\conf.

Open the file schema.xml in a text editor.

Search for the string “Catentry's basic attributes”. This will bring you to the section of the file where the index fields are defined.

The first block of index fields represent data from the CATENTRY table. Since the field1 value is also stored in the CATENTRY table, you need to add the new index field here.

 At the bottom of the CATENTRY fields add the line:

<!--    Catentry's basic attributes: map to table CATENTRY   -->
<field name="catentry_id" type="string" indexed="true" stored="true" required="true" multiValued="false"/>
<field name="member_id" type="long" indexed="true" stored="true" multiValued="false"/>
<field name="mfName" type="wc_text" indexed="true" stored="true"  multiValued="false"/>
<field name="buyable" type="int" indexed="true" stored="true" multiValued="false"/>
<field name="field1" type="long" indexed="true" stored="true" multiValued="false"/>

Next we  will update the queries that are used to populate the Solr index from the WebSphere Commerce database tables. Each query needs to retrieve the data stored in field1 of the CATENTRY table.

wc-data-config.xml 

This file contains queries for getting data from preprocess tables (regular WC tables if necessary)to populate the search index. The query results are mapped to SOLR fields in this file. Open the file wc-data-config.xml.

(<WCDE>\search\solr\home\MC_<master_catalog_id>\en_US\CatalogEntry\conf)

The wc-data-config.xml file loads catalog entry data in three separate parts. Product data is loaded first. This is followed by bundle data and finally all other catalog entry types. For each of the three sections there is a query for populating the full index and another query for delta updates. For each section (product, bundle and other), you need to update the two queries and then add a new field element to assign the data from the WebSphere Commerce database to the field1 field in the Solr index. All together there are nine updates you need to make to this file.

Update the product queries and assignment.

1) Search for the string buyable from the top of the file. This is another column in the CATENTRY table that is already included in the query.
2) The first place you find the string is in the main product query. Add CATENTRY.FIELD1 to the SELECT statement immediately following CATENTRY.BUYABLE. Your updated query should look like the screen capture below.

query="SELECT CATENTRY.CATENTRY_ID,CATENTRY.MEMBER_ID,CATENTRY.CATENTTYPE_ID,CATENTRY.PARTNUMBER,CATENTRY.MFPARTNUMBER,CATENTRY.MFNAME, CATENTRY.BUYABLE,CATENTRY.FIELD1,STORECENT.STOREENT_ID

Search for buyable again. The second place you find the string is the delta index query. Make the same update to this query as you did to the previous one.

deltaImportQuery="SELECT CATENTRY.CATENTRY_ID,CATENTRY.MEMBER_ID,CATENTRY.CATENTTYPE_ID,CATENTRY.PARTNUMBER,CATENTRY.MFPARTNUMBER,CATENTRY.MFNAME, CATENTRY.BUYABLE,CATENTRY.FIELD1,STORECENT.STOREENT_ID,

Search for buyable once more. This brings you to the section where the data retrieved from the WebSphere Commerce database is assigned to the Solr index fields. Add an element under buyable to map the FIELD1 database column to the field1 index field. Your updated file should look like the screen capture below.

<field column="CATENTRY_ID" name="catentry_id" />
<field column="MEMBER_ID" name="member_id" />
<field column="PARTNUMBER" name="partNumber" />
<field column="MFNAME" name="mfName" />
<field column="BUYABLE" name="buyable" />
<field column="FIELD1" name="field1" />
                                                                                                                                                                 
Do the steps done for products for  bundles  if required

Make field1 a product facet by making entries in SRCHATTR, SRCHATTRPROP tables

Update the SRCHATTR table. Each row in this table represents the logical name of a catalog attribute that is defined in the search schema.

Enter the SQL below to add field1 to the table. You can use any available primary key, the value 101 is used here as an example. The value of ‘0’ for INDEXSCOPE indicates that this is a site-wide field.

insert into SRCHATTR (srchattr_id, indexscope, indextype, identifier)values (101, '0', 'CatalogEntry','_cat.Field1');

Update the SRCHATTRPROP table. This table stores information about which fields are defined as facets.

insert into SRCHATTRPROP (srchattr_id, propertyname, propertyvalue) values (101,'facet','field1');

JSP Related Changes for displaying facet in Store

Add the facet to the storefront  so that the Madisons storefront to display the facet data in the left sidebar.

Navigate to Stores>WebContent>Madisons>Snippets>ReusableObjects and open the file SearchFacetsDisplay.jspf. This JSP fragment loops through the available global facets and includes another JSP fragment to display each facet’s data. You will create the new JSP fragment for field1 in a later step.

Add a new test into the <c:choose> block to look for the field1 facet and include its display JSP fragment. You can copy one of the existing <c:when> blocks and update it to match the screen capture below.

<c:when test=”${facetField.value eq ‘field1’}”>
 <%@ include file=”../../ Field1FacetDisplay.jspf”%>
 <c:set var=”f” value=”$(f+1}”/>
</when>

Navigate to Stores > WebContent > Madisons > Snippets > Search.
Make a copy of the file  BrandFacetDisplay.jspf and call the new file Field1FacetDisplay.jspf.

Open Field1FacetDisplay.jspf. Remove   the below line starts with

<span class =left_sidebar_header”> <fmt:message key="SEARCH_FACET_MANUFACTURER" bundle="${storeText}"/></span>
Add the below line
<span class =left_sidebar_header”> Shopper points</span>

Management Center changes

1.Login into Management Center
2.Select the Madisons store.
3.Expand the master catalog and select the Coffee Tables category to display the catalog entries list.
4.Select catalog entry
5.Choose configure columns
6.Select field1,and assign some value so that it will come in facets
7.Do the same for other catalog entries