diff --git a/src/js/vendor/page-search.js b/src/js/vendor/page-search.js index 0ac4a5e..ffc1179 100644 --- a/src/js/vendor/page-search.js +++ b/src/js/vendor/page-search.js @@ -12,34 +12,6 @@ let lastRenderArgs - const transformItems = (items) => { - return items.map((item) => { - let label = Object.keys(item.hierarchy).reduce((acc, key) => { - const highlight = item._highlightResult.hierarchy[key] - if (highlight && highlight.matchLevel !== 'none') { - return item._highlightResult.hierarchy[key] - } - return acc - }, '') - if (!label) { - label = Object.keys(item.hierarchy).reduce((acc, key) => { - const highlight = item._highlightResult.hierarchy[key] - if (highlight) { - return item._highlightResult.hierarchy[key] - } - return acc - }, '') - } - return { - ...item, - _highlightResult: { - ...item._highlightResult, - label: label, - }, - } - }) - } - const infiniteHits = instantsearch.connectors.connectInfiniteHits((renderArgs, isFirstRender) => { const { hits, showMore, widgetParams } = renderArgs const { container } = widgetParams @@ -51,7 +23,7 @@ container.appendChild(sentinel) return } - const _hits = transformItems(hits) + const _hits = [...hits] if (container.querySelector('#page-showmore')) { container.removeChild(container.querySelector('#page-showmore')) } @@ -72,6 +44,7 @@ .map((hit) => { let content = '' let breadcrumbs = '' + let label = '' if (hit.content) { content = `

@@ -90,10 +63,20 @@ ` } + label = Object.keys(hit.hierarchy) + .map((key, index) => { + if (index > 0 && hit) { + return instantsearch.highlight({ hit: hit, attribute: 'hierarchy.' + key }) + } + return null + }) + .filter((item) => !!item) + .join(' - ') + return `

  • - ${instantsearch.highlight({ hit: hit, attribute: 'label' })} + ${label}
    ${breadcrumbs} ${content} diff --git a/src/js/vendor/search.bundle.js b/src/js/vendor/search.bundle.js index 54cfadd..c12843a 100644 --- a/src/js/vendor/search.bundle.js +++ b/src/js/vendor/search.bundle.js @@ -70,16 +70,16 @@ .join(' > ')} ` } - - label = Object.keys(hit._highlightResult.hierarchy) + label = Object.keys(hit.hierarchy) .map((key, index) => { - if (index > 0) { + if (index > 0 && hit) { return instantsearch.highlight({ hit: hit, attribute: 'hierarchy.' + key }) } return null }) .filter((item) => !!item) .join(' - ') + console.log(label) return `