@@ -112,6 +112,7 @@ function makeTeaser(body, terms) {
112112 var NORMAL_WORD_WEIGHT = 2;
113113 var FIRST_WORD_WEIGHT = 8;
114114 var TEASER_MAX_WORDS = 17;
115+ var TEASER_MAX_CHARS = 63;
115116
116117 var stemmedTerms = terms.map(function (w) {
117118 return elasticlunr.stemmer(w.toLowerCase());
@@ -153,7 +154,16 @@ function makeTeaser(body, terms) {
153154 }
154155
155156 var windowWeights = [];
156− var windowSize = Math.min(weighted.length, TEASER_MAX_WORDS);
157+ var windowSize = 0;
158+
159+ var sumChars = 0;
160+ for (var i = 0; i < weighted.length; i++) {
161+ sumChars += weighted[i][0].length;
162+ if (sumChars <= TEASER_MAX_CHARS) {
163+ windowSize++;
164+ }
165+ }
166+
157167 // We add a window with all the weights first
158168 var curSum = 0;
159169 for (var i = 0; i < windowSize; i++) {
@@ -205,10 +215,21 @@ function makeTeaser(body, terms) {
205215 return teaser.join("");
206216}
207217
218+/*function trimTeaser(teaser) {
219+ var maxLength = 63; // maximum number of characters to extract
220+ var string = teaser;
221+ var trimmedString = teaser.substr(0, maxLength); //trim the string to the maximum length
222+ trimmedString = trimmedString.substr(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" "))) //re-trim if we are in the middle of a word
223+}*/
224+
225+function trimTeaserTitle() {
226+ //
227+}
228+
208229function formatSearchResultItem(item, terms) {
209230 var li = document.createElement("li");
210231 li.classList.add("search-results__item");
211− li.innerHTML = `<a href="${item.ref}">${item.doc.title}</a>`;
232+ li.innerHTML = `<a href="${item.ref}">${item.ref}</a>`;
212233 li.innerHTML += `<div class="search-results__teaser">${makeTeaser(item.doc.body, terms)}</div>`;
213234 return li;
214235}