From eacadc7935c253bae5c8f88e5b955aa349465fcf Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 11 Sep 2019 15:39:04 +0100 Subject: [PATCH] feat(search): show talk and publication abstracts in results Instead of their page bodies which are often empty. Close #1253 --- assets/js/academic-search.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/js/academic-search.js b/assets/js/academic-search.js index 4b262c3e..9b9ef001 100644 --- a/assets/js/academic-search.js +++ b/assets/js/academic-search.js @@ -84,10 +84,18 @@ function searchAcademic(query, fuse) { // Parse search results. function parseResults(query, results) { $.each( results, function(key, value) { - let content = value.item.content; + let content_key = value.item.section; + let content = ""; let snippet = ""; let snippetHighlights = []; + // Show abstract in results for content types where the abstract is often the primary content. + if (["publication", "talk"].includes(content_key)) { + content = value.item.summary; + } else { + content = value.item.content; + } + if ( fuseOptions.tokenize ) { snippetHighlights.push(query); } else { @@ -102,14 +110,13 @@ function parseResults(query, results) { } if (snippet.length < 1) { - snippet += content.substring(0, summaryLength*2); + snippet += value.item.summary; // Alternative fallback: `content.substring(0, summaryLength*2);` } // Load template. - var template = $('#search-hit-fuse-template').html(); + let template = $('#search-hit-fuse-template').html(); // Localize content types. - let content_key = value.item.section; if (content_key in content_type) { content_key = content_type[content_key]; }