on master help sign in
Partial words searchable + all results displayed
5242e55francescanarea
static/scripts.js+20−24
@@ -128,16 +128,26 @@ function debounce(func, wait) {
128// maximum sum. If there are multiple maximas, then get the last one.
128// maximum sum. If there are multiple maximas, then get the last one.
129// Enclose the terms in <b>.
129// Enclose the terms in <b>.
130function makeTeaser(body, terms) {
130function makeTeaser(body, terms) {
131+ console.log("make teaser");
131 var TERM_WEIGHT = 40;
132 var TERM_WEIGHT = 40;
132 var NORMAL_WORD_WEIGHT = 2;
133 var NORMAL_WORD_WEIGHT = 2;
133 var FIRST_WORD_WEIGHT = 8;
134 var FIRST_WORD_WEIGHT = 8;
134 //var TEASER_MAX_WORDS = 17;
135 //var TEASER_MAX_WORDS = 17;
135 var TEASER_MAX_CHARS = 63;
136 var TEASER_MAX_CHARS = 63;
136
137
138+
137 var stemmedTerms = terms.map(function (w) {
139 var stemmedTerms = terms.map(function (w) {
138 return elasticlunr.stemmer(w.toLowerCase());
140 return elasticlunr.stemmer(w.toLowerCase());
139 });
141 });
140
142
143+ console.log(stemmedTerms);
144+ // create array with full word + partial Words (smallest fragment is 2 characters)
145+ // first iteration is full word, then next is subset of the original word
146+ /*var stemmedTerms = [];
147+ for (var i = terms[0].length; i>=2; i--) {
148+ stemmedTerms.push(terms[0].substring(0,i));
149+ }
150+ console.log(stemmedTerms);*/
141 var termFound = false;
151 var termFound = false;
142 var index = 0;
152 var index = 0;
143 var weighted = []; // contains elements of ["word", weight, index_in_document]
153 var weighted = []; // contains elements of ["word", weight, index_in_document]
@@ -238,35 +248,17 @@ function makeTeaser(body, terms) {
238}
248}
239
249
240function formatSearchResultTitle(path) {
250function formatSearchResultTitle(path) {
241−// console.log(path);
242 var pathArray = path.split( '/' );
251 var pathArray = path.split( '/' );
243− //console.log(pathArray);
252+
244− /*var slug = pathArray[1];
245−// console.log(slug);
246− var slugArray = slug.split( '/' );
247− var lastPartTitle = slugArray.splice(slugArray.length - 2, slugArray.length).join('');
248− var firstPartTitle = slugArray.join(' / ');
249−//console.log(lastPartTitle);
250−//console.log(firstPartTitle);
251−*/
252− var firstPartTitle = pathArray[3]; // first directory is in 4th element of path array
253+ // first directory is in 4th element of split path array
254+ var firstPartTitle = pathArray[3];
255+
253− var lastPartTitle = pathArray[pathArray.length-2]; // last directory is in 2nd to last element of array
256+ // last directory is in 2nd to last element of array
254− var fullTitle = firstPartTitle + '<span class="gray90">' + ' / ' + lastPartTitle + '</span>';
257+ var lastPartTitle = pathArray[pathArray.length-2].replace(/-/g,' ');
255− console.log(fullTitle);
256− return fullTitle;
257−/*
258− var pathArray = path.split( 'docs/' );
259−// console.log(pathArray);
260− var slug = pathArray[1];
261−// console.log(slug);
262− var slugArray = slug.split( '/' );
263− var lastPartTitle = slugArray.splice(slugArray.length - 2, slugArray.length).join('');
264− var firstPartTitle = slugArray.join(' / ');
265
258
266 var fullTitle = firstPartTitle + '<span class="gray90">' + ' / ' + lastPartTitle + '</span>';
259 var fullTitle = firstPartTitle + '<span class="gray90">' + ' / ' + lastPartTitle + '</span>';
267
260
268 return fullTitle;
261 return fullTitle;
269− */
270}
262}
271
263
272function formatSearchResultItem(item, terms) {
264function formatSearchResultItem(item, terms) {
@@ -284,6 +276,7 @@ function formatSearchResultItem(item, terms) {
284}
276}
285
277
286function initSearch() {
278function initSearch() {
279+ console.log("init search");
287 var searchInput = document.getElementById("search");
280 var searchInput = document.getElementById("search");
288
281
289 if (!searchInput) {
282 if (!searchInput) {
@@ -297,6 +290,7 @@ function initSearch() {
297
290
298 var options = {
291 var options = {
299 bool: "AND",
292 bool: "AND",
293+ expand: true,
300 fields: {
294 fields: {
301 title: {boost: 2},
295 title: {boost: 2},
302 body: {boost: 1},
296 body: {boost: 1},
@@ -348,6 +342,8 @@ function initSearch() {
348 return;
342 return;
349 }
343 }
350
344
345+ // change query in order to make partial words work
346+
351 var results = index.search(term, options).filter(function (r) {
347 var results = index.search(term, options).filter(function (r) {
352 return r.doc.body !== "";
348 return r.doc.body !== "";
353 });
349 });