You are on page 1of 7

hybris Solr Tips

Debug Solr Query sent


In HAC http://localhost:9001/hac/platform/log4j

Set log level in DEBUG for

DefaultFacetSearchStrategy
DefaultSolrFieldSearchFacadeStrategy
LegacyFacetSearchStrategy
DefaultSolrQueryConverter
DefaultFacetSearchService (raw query)

In HMC http://localhost:9001/hmc/hybris

Add following listener in Indexed Type setting: solrQueryDebuggingListener


DEBUG [hybrisHTTP31] [DefaultSolrQueryConverter] FIELDS :
(allCategories_string_mv:501_2) OR (*:*) OR (code_string:(31^1000000.0))
DEBUG [hybrisHTTP31] [LegacyFacetSearchStrategy] Solr Query:
q=(allCategories_string_mv:501_2) OR (*:*) OR (code_string:(31^1000000.0))
&group=true&group.field=baseProduct_string&group.limit=-1&group.
facet=false&group.ngroups=true&spellcheck=true&spellcheck.
dictionary=fr&spellcheck.collate=true&spellcheck.q=&fq=(((catalogId:"
jacadi-frProductCatalog") AND (catalogVersion:Online)))&fq=
(((approvalStatus_string:APPROVED) AND (approvalStatus_string:APPROVED)))
&start=0&rows=60&facet=true&facet.field={!ex=fk0}color_string&facet.field=
{!ex=fk2}size_string&facet.field={!ex=fk1}gender_fr_string&sort=score desc,
priceValue_eur_double asc,score desc&facet.mincount=1&facet.
limit=500&facet.sort=count&debugQuery=true
DEBUG [hybrisHTTP31] [LegacyFacetSearchStrategy] Processing solr search
result post-processor : class de.hybris.platform.solrfacetsearch.reporting.
processors.SaveResultDataPostProcessor
INFO [hybrisHTTP31] [SolrQueryDebuggingListener] Raw Query:
(allCategories_string_mv:501_2) OR (*:*) OR (code_string:(31^1000000.0))
INFO [hybrisHTTP31] [SolrQueryDebuggingListener] Parsed Solr Query:
allCategories_string_mv:501_2 MatchAllDocsQuery(*:*) code_string:
31^1000000.0
INFO [hybrisHTTP31] [SolrQueryDebuggingListener] Filter Queries:
[(((catalogId:"jacadi-frProductCatalog") AND (catalogVersion:Online))),
(((approvalStatus_string:APPROVED) AND (approvalStatus_string:APPROVED)))]
INFO [hybrisHTTP31] [SolrQueryDebuggingListener] Solr Query explanation:
{jacadi-frProductCatalog/Online/31=
1000002.0 = sum of:
1.0 = weight(allCategories_string_mv:501_2 in 78) [], result of:
1.0 = fieldWeight in 78, product of:

Debug Solr Response


Add the following code
*core-spring.xml
<alias name="debugSolrSearchResultPostProcessors" alias="
solrSearchResultPostProcessors" />
<util:list id="debugSolrSearchResultPostProcessors">
<!-- Trace query in hybris/log/solrstats/stats.log-->
<bean class="de.hybris.platform.solrfacetsearch.reporting.processors.
SaveResultDataPostProcessor">
<property name="solrReportingService" ref="solrReportingService" />
<property name="enableCollectingStatistics" value="${solrStats.
enableCollectingStatistics}" />
</bean>
<!-- Trace response in stdout/log4j -->
<bean class="ps.hybris.platform.solrfacetsearch.processors.
DebugResultDataPostProcessor" />
</util:list>

DebugResultDataPostProcessor.java
// Display raw Solr result for debugging
public class DebugResultDataPostProcessor implements
SolrResultPostProcessor
{
private final static Logger LOG = Logger.getLogger
(DebugResultDataPostProcessor.class);
@Override
public SearchResult process(final SearchResult solrSearchResult)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Solr Result: " + solrSearchResult.getSolrObject().
toString());
}
return solrSearchResult;
}
}

In HAC http://localhost:9001/hac/platform/log4j

Set log level in DEBUG for

DebugResultDataPostProcessor
DEBUG [hybrisHTTP8] [DebugResultDataPostProcessor] Solr Result:
{responseHeader={status=0,...},response={numFound=6,start=0,docs=
[SolrDocument{id=electronicsProductCatalog/Online/1432722,
pk=8796106489857, catalogId=electronicsProductCatalog,
catalogVersion=Online, Resolution, 80_string=1280
x 720, manufacturerAID_string=GSC-K80HE, autosuggest=[1432722, Toshiba,
4026203537095], autosuggest_de=[1432722, Toshiba, 4026203537095, Hand-
Camcorder, Katalog
öffnen, Kameras, Gigashot K80H], autosuggest_en=[1432722, Toshiba,
4026203537095, Hand-held Camcorders, Open Catalogue, Cameras, Gigashot
K80H], autosuggest_fr=
[1432722, Toshiba, 4026203537095], autosuggest_ja=[1432722, Toshiba,
4026203537095, , , , Gigashot K80H],...

Debug Solr Indexation


In HAC http://localhost:9001/hac/platform/log4j

Set log level in DEBUG for

AbstractIndexStrategy
DefaultIndexerService
DefaultSolrCoresService
DefaultIndexerStrategy
DefaultSolrDocumentFactory / solrIndexThreadLogger

INFO [hybrisHTTP14] [SolrIndexerOperationWizard] Start solr indexing


cronjob.
INFO [hybrisHTTP14] [SolrIndexerOperationWizard] Perform cronjob with
code: 000000RS
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Start rebuilding index
of indexer. Configuration = electronicsIndex
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Performing UPDATE
operation for: electronicsIndex
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Using
UpdateIndexStrategyindexing strategy.
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [DefaultSolrCoresService] Persisting index
record for Product
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [DefaultSolrCoresService] Index Core Record
already exists (index_name : null)
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Operation Record
Persisted : \n clusterId =0\n,threadId = 72\nmode = UPDATE\nstatus =
RUNNING\nstart = Tue Sep 27 16:17:13 CEST 2016\nfinish = null\nRecord
= [core:master_electronics_Product, index_name:electronics_Product,
server_mode:EMBEDDED]
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Used
FlexibleSearchQuerySpec : class de.hybris.platform.solrfacetsearch.config.
impl.IndexTypeFSQSpec
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Query: SELECT DISTINCT
tbl.pk, tbl.code FROM (
{{
SELECT DISTINCT {p:PK} AS pk, {p:code} AS code
FROM {Product AS p LEFT JOIN CustomerReview AS cr ON {cr:product}=
{p:PK} }
WHERE {p:varianttype} IS NULL AND ({p:modifiedtime} >= ?
lastIndexTime OR {cr:modifiedtime} >= ?lastIndexTime)
}}
UNION
{{
SELECT {p:PK} AS pk, {p:code} AS code FROM {Product AS p} WHERE
{p:code} IN (
{{
SELECT DISTINCT {sl:productCode} FROM {StockLevel AS sl}
WHERE {sl:modifiedtime} >= ?lastIndexTime
}}
)
}}
) tbl ORDER BY tbl.code
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Number of items: 0,
count query time: 0.0 sec
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] Update attempt of
Index Operation Record : null
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [DefaultSolrCoresService] Persisting index
record for Product
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [DefaultSolrCoresService] Index Core Record
already exists (index_name : null)
DEBUG [000000RS::de.hybris.platform.servicelayer.internal.jalo.
ServicelayerJob] (000000RS) [AbstractIndexStrategy] UPDATE operation
finished: Tue Sep 27 16:17:13 CEST 2016 Total time = 0.021 s.

Search autocomplete in accelerator

JavaScript call chains


master.tag
<template:javaScript/>
javaScript.tag
js.tag
<script type="text/javascript"
src="${commonResourcePath}/js/acc.autocomplete.js"></script>

<UiExperience>/cms/searchboxcomponent.jsp
component.minCharactersBeforeRequest (component CMS setting)
component.waitTimeBeforeRequest (component CMS setting)
js-site-search-input -> acc.autocomplete.js
GET /search/autocomplete/${component.id} => GET /yacceleratorstorefront
/search/autocomplete/SearchBox
SearchPageController.getAutocompleteSuggestions()

Test JavaScript call


curl -k https://electronics.local:9002/yacceleratorstorefront/search/autocomplete/SearchBox?term=“pan"

{"suggestions":[{"term":"pantalon"}],"products":[{"availableForPickup":
null,"volumePricesFlag":...]}

Trace in Solr log

hybris/log/solr/instances/default/solr.log
[master_electronics_Product_default] webapp=/solr path=/suggest params=
{q=pan&spellcheck.q=pan&qt=/suggest&spellcheck.
dictionary=en&wt=javabin&version=2} status=0 QTime=0
[master_electronics_Product_default] webapp=/solr path=/select params={...
collate=true} hits=179 status=0 QTime=7

OOTB, spellcheck.dictionary=en is built, but it is not reachable... And that seems not to be an issue for suggestion feature. However a ticket has
been opened to clean this setting: ECP-2063 - Clean the Solr autocompleting setting/code Resolved
solrconfig.xml
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">default</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.collate">true</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>

You might also like