Overview
We've switched to using dismax as our default search handler in Feature Pack 6. If you're on an earlier feature pack, and would like to use dismax, you can follow the below steps to inject a dismax query into the search sent to solr:
SearchSetup.jspf
SearchSetup.jspf contains the getData tag. This is where you will inject the dismax query. Find the getData tag and add a custom parameter name. In this example, we use 'customExpr'. Whatever custom parameter name you choose, the same parameter name must be used in the get-data-config.xml. Parameter will be added in red:
<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType" var="catalogNavigationView"
expressionBuilder="${navigationView}" scope="request" varShowVerb="showCatalogNavigationView"
maxItems="${pageSize}" recordSetStartNumber="${WCParam.beginIndex}" scope="request">
<wcf:param name="searchProfile" value="${searchProfile}" />
<wcf:param name="searchTerm" value="${newSearchTerm}" />
<wcf:param name="intentSearchTerm" value="${intentSearchTerm}" />
<wcf:param name="searchType" value="${searchType}" />
<wcf:param name="searchSource" value="${WCParam.searchSource}" />
<wcf:param name="metaData" value="${WCParam.metaData}" />
<wcf:param name="orderBy" value="${WCParam.orderBy}" />
<wcf:param name="facet" value="${WCParam.facet}" />
<wcf:param name="advancedFacetList" value="${newAdvancedFacetList}"/>
<wcf:param name="categoryId" value="${currentCategoryId}" />
<wcf:param name="filterTerm" value="${newFilterTerm}" />
<wcf:param name="filterType" value="${WCParam.filterType}" />
<wcf:param name="filterFacet" value="${WCParam.filterFacet}" />
<wcf:param name="manufacturer" value="${newManufacturer}" />
<c:if test="${!empty newSearchTerm}">
<wcf:param name="customExpr" value="_query_:\"{!dismax ps=5 qf='longDescription name^8 catentry_id^1.5 mfPartNumber_ntk^10.0 mfName_ntk^2 xf_CategoryPath^1.4 parentCatgroup_id_search sequence' pf='longDescription name^8 catentry_id^1.5 mfPartNumber_ntk^10.0 mfName_ntk^2 xf_CategoryPath^1.4'} ${newSearchTerm} \"" />
</c:if>
<wcf:param name="minPrice" value="${WCParam.minPrice}" />
<wcf:param name="maxPrice" value="${WCParam.maxPrice}" />
<wcf:contextData name="storeId" data="${WCParam.storeId}" />
<wcf:contextData name="catalogId" data="${WCParam.catalogId}" />
</wcf:getData>
This is just a sample dismax query; I've added some parameters such as phrase slop and boosting different fields just to give an idea of how you can configure your dismax query. You can read about different dismax query parameters here: http://wiki.apache.org/solr/ExtendedDisMax
Notice we're only injecting the query in the case that 'newSearchTerm' is not empty (if test="${!empty). Dismax only works if you have a term to search against; it's not needed for normal catalog navigation (ie clicking on a category).
get-data-config.xml
Modify the getCatalogNavigationView expression builder, adding in your custom parameter from the getData tag above into the 'wcf.search.expr' parameter:
<expression-builder>
<name>getCatalogNavigationView</name>
<data-type-name>CatalogNavigationView</data-type-name>
<expression-template>{_wcf.ap='$accessProfile$';_wcf.search.profile='$searchProfile$';_wcf.search.term='$searchTerm$';_wcf.search.intent.term='$intentSearchTerm$';_wcf.search.originalterm='$originalSearchTerm$';_wcf.search.category='$categoryId$';_wcf.search.type='$searchType$';_wcf.search.exclude.term='$filterTerm$';_wcf.search.exclude.type='$filterType$';_wcf.search.manufacturer='$manufacturer$';_wcf.search.price.minimum='$minPrice$';_wcf.search.price.maximum='$maxPrice$';_wcf.search.facet='$facet$';_wcf.search.advanced.facet='$advancedFacetList$';_wcf.search.exclude.facet='$filterFacet$';_wcf.search.sort='$orderBy$';_wcf.search.expr='$customExpr$';_wcf.search.meta='$metaData$';_wcf.search.source='$searchSource$'}/CatalogNavigationView</expression-template>
<param>
...
You'll also need to create a default value in the modified expression builder for customExpr. This prevents a null value from being passed in.
<param>
<name>accessProfile</name>
<value>IBM_Store_CatalogEntrySearch</value>
</param>
<param>
<name>searchType</name>
<value>0</value>
</param>
<param>
<name>searchSource</name>
<value>O</value>
</param>
<param>
<name>customExpr</name>
<value>""</value>
</param>
<param>
<name>searchProfile</name>
<value>IBM_findCatalogEntryByNameAndShortDescription</value>
</param>
</expression-builder>
Optional: modify your wc-search.xml
With the above modification, you can effectively search some fields twice, once with the standard query parser, and again with the dismax query parser. The results are OR'd together, so it doesn't break anything, but you as well only search the fields in dismax once you've set this up.
Locate the search profile being used, and remove fields you no longer need to search from the 'query' section of the search profile. For example if you are dismax searching on name & shortdescription you’ll remove the following:
<_config:profile name="Custom_findCatalogEntryByNameAndShortDescription"
extends="IBM_findCatalogEntryByName">
<_config:query inherits="false">
<_config:provider classname="com.ibm.commerce.catalog.facade.server.services.search.expression.solr.SolrSearchByCustomExpressionProvider"/>
...
<_config:field name="name" /> <-----------remove
<_config:field name="defaultSearch" />
<_config:field name="shortDescription"/> <--------------- remove
</_config:query>
Make sure to add in the 'CustomerExpressionProvider' plus any additional providers you want to use into the custom profile.
To use the new search profile you'll need to modify searchSetup.jspf to point to the new profile. Before the getData tag:
<c:set var="searchProfile" value="Custom_findCatalogEntryByNameAndShortDescription" scope="request"/>
You’re done! That wasn’t too bad, was it?
Don’t forget to restart your Commerce server so the changes in the configuration files can be applied.
Note: This customization does not make use of STAs and search rules.