Faceted search is the dynamic clustering of items or search results into
categories that let users drill into search results (or even skip
searching entirely) by any value in any field. Each facet displayed also
shows the number of hits within the search that match that category.
Users can then “drill down” by applying specific contstraints to the
search results. Faceted search is also called faceted browsing, faceted
navigation, guided navigation and sometimes parametric search.
One of the common customization scenario is to introduce custom attributes as facets. The following should guide a developer through the process:
Important SOLR Configuration Files
Location : <WCDE>\search\solr\home\MC_<master_catalog_id>\en_US\CatalogEntry\conf
1. schema.xml
Introduce a child element "field" for the element "fields" for CATENTRY.FIELD1.
Place it at the end of the attributes under "Catentry's basic attributes" for logical grouping
<fields>
<!--
Catentry's basic attributes: map to table CATENTRY
-->
<field name="catentry_id" type="long" indexed="true" stored="true" required="true" multiValued="false"/>
.
.
<field name="catenttype_id_ntk_cs" type="wc_keywordText" indexed="true" stored="true" multiValued="false"/>
<field name="field1" type="long" indexed="true" stored="true" multiValued="false"/>
where ,
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
multiValued: true if this field may contain multiple values per document
2. wc-data-config.xml
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.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), we 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.
The modified file can be downloaded from here. Search "FIELD1" in the downloaded file to know the modifications required.
Important Database Tables
SRCHATTR
SQL updates required
insert into srchattr (srchattr_id, indexscope, indextype, identifier) values ((select max(srchattr_id)+1 from srchattr ) , '0', 'CatalogEntry','_cat.Field1');
insert into srchattrprop (srchattr_id, propertyname, propertyvalue)
values ((select max(srchattr_id) from srchattr ),'facet','field1');
Here , propertyvalue ' field1' is the name specified in the schema.xml
Also, srchattr_id should match in both the above queries
Code File Changes
1. SearchFacetsDisplay.jspf
Location : /Stores/WebContent/Madisons/Snippets/ReusableObjects/
This JSP fragment loops through the available global facets and includes another JSP fragment to display each facet’s data.We will introduce code to display the facet data for field1 in the left sidebar.
Search for the below <c:otherwise> tag and introdule the below code before the tag:
<c:when test="${facetField.value eq 'field1'}">
<%@ include file="../../Snippets/Search/Field1FacetDisplay.jspf" %>
<c:set var="f" value="${f + 1}" />
</c:when>
We will create "Field1FacetDisplay.jspf" in the next step.
2. Field1FacetDisplay.jspf
Download the file from here and place it in the location "/Stores/WebContent/Madisons/Snippets/Search/".
Republish and Test!
Demo Video
Coming shortly
One of the common customization scenario is to introduce custom attributes as facets. The following should guide a developer through the process:
Important SOLR Configuration Files
Location : <WCDE>\search\solr\home\MC_<master_catalog_id>\en_US\CatalogEntry\conf
1. schema.xml
Introduce a child element "field" for the element "fields" for CATENTRY.FIELD1.
Place it at the end of the attributes under "Catentry's basic attributes" for logical grouping
<fields>
<!--
Catentry's basic attributes: map to table CATENTRY
-->
<field name="catentry_id" type="long" indexed="true" stored="true" required="true" multiValued="false"/>
.
.
<field name="catenttype_id_ntk_cs" type="wc_keywordText" indexed="true" stored="true" multiValued="false"/>
<field name="field1" type="long" indexed="true" stored="true" multiValued="false"/>
where ,
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
multiValued: true if this field may contain multiple values per document
2. wc-data-config.xml
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.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), we 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.
The modified file can be downloaded from here. Search "FIELD1" in the downloaded file to know the modifications required.
Important Database Tables
SRCHATTR
SQL updates required
insert into srchattr (srchattr_id, indexscope, indextype, identifier) values ((select max(srchattr_id)+1 from srchattr ) , '0', 'CatalogEntry','_cat.Field1');
insert into srchattrprop (srchattr_id, propertyname, propertyvalue)
values ((select max(srchattr_id) from srchattr ),'facet','field1');
Here , propertyvalue ' field1' is the name specified in the schema.xml
Also, srchattr_id should match in both the above queries
Code File Changes
1. SearchFacetsDisplay.jspf
Location : /Stores/WebContent/Madisons/Snippets/ReusableObjects/
This JSP fragment loops through the available global facets and includes another JSP fragment to display each facet’s data.We will introduce code to display the facet data for field1 in the left sidebar.
Search for the below <c:otherwise> tag and introdule the below code before the tag:
<c:when test="${facetField.value eq 'field1'}">
<%@ include file="../../Snippets/Search/Field1FacetDisplay.jspf" %>
<c:set var="f" value="${f + 1}" />
</c:when>
We will create "Field1FacetDisplay.jspf" in the next step.
2. Field1FacetDisplay.jspf
Download the file from here and place it in the location "/Stores/WebContent/Madisons/Snippets/Search/".
Republish and Test!
Demo Video
Coming shortly
Thanks for wonderfull blog on very vast topic. You made alot easier to understand.
ReplyDelete