99 *
1010 */
1111
12+ var title_documentation = 'Plone Documentation' ;
1213
1314if ( ! Scorer ) {
1415 /**
@@ -74,14 +75,12 @@ var Search = {
7475
7576 init : function ( ) {
7677 var params = $ . getQueryParameters ( ) ;
78+ let doc_section = params . doc_section ? params . doc_section [ 0 ] : 'all' ;
79+ $ ( 'input[id="doc_section_' + doc_section + '"]' ) . prop ( "checked" , true )
7780 if ( params . q ) {
7881 var query = params . q [ 0 ] ;
7982 $ ( 'input[name="q"]' ) [ 0 ] . value = query ;
8083 $ ( 'input[name="q"]' ) [ 1 ] . value = query ;
81- if ( params . doc_section ) {
82- var doc_section = params . doc_section [ 0 ] ;
83- $ ( 'select[name="doc_section"]' ) [ 0 ] . value = doc_section ;
84- }
8584 this . performSearch ( query , doc_section ) ;
8685 }
8786 } ,
@@ -199,10 +198,6 @@ var Search = {
199198 }
200199 var highlightstring = '?highlight=' + $ . urlencode ( hlterms . join ( " " ) ) ;
201200
202- // console.debug('SEARCH: searching for:');
203- // console.info('required: ', searchterms);
204- // console.info('excluded: ', excluded);
205-
206201 // prepare search
207202 var terms = this . _index . terms ;
208203 var titleterms = this . _index . titleterms ;
@@ -237,7 +232,7 @@ var Search = {
237232
238233 // Enrich item with parent doc_section title
239234 for ( i = 0 ; i < results . length ; i ++ )
240- results [ i ] [ 6 ] = results [ i ] [ 6 ] || 'TODO Documentation title ' ;
235+ results [ i ] [ 6 ] = results [ i ] [ 6 ] || 'Plone Documentation' ;
241236
242237 // now sort the results by score (in opposite order of appearance, since the
243238 // display function below uses pop() to retrieve items) and then
@@ -257,8 +252,25 @@ var Search = {
257252 }
258253 } ) ;
259254
255+ function _getBreadcrumbs ( item , linkUrl ) {
256+ let parentTitles = item [ 6 ] ;
257+ let path = item [ 0 ] . split ( '/' )
258+ . slice ( 0 , - 1 ) ;
259+ path = path . map ( ( el , index ) => {
260+ return {
261+ "path" : path . slice ( 0 , index + 1 ) . join ( '/' ) ,
262+ "title" : parentTitles [ index ]
263+ }
264+ } )
265+ let markup = path
266+ . map ( ( el , idx ) => {
267+ return `<a href="/${ el . path } ">${ el . title } </a>`
268+ } )
269+ markup . push ( `<span class="lastbreadcrumb">${ item [ 1 ] } </span>` )
270+ return markup . join ( '<span class="pathseparator">></span>' ) ;
271+ }
260272
261- // print the results
273+ // Print the results.
262274 var resultCount = results . length ;
263275 function displayNextItem ( ) {
264276 // results left, load the summary and display it
@@ -283,11 +295,15 @@ var Search = {
283295 requestUrl = DOCUMENTATION_OPTIONS . URL_ROOT + item [ 0 ] + DOCUMENTATION_OPTIONS . FILE_SUFFIX ;
284296 linkUrl = item [ 0 ] + DOCUMENTATION_OPTIONS . LINK_SUFFIX ;
285297 }
286- listItem . append ( $ ( '<a/>' ) . attr ( 'href' ,
287- linkUrl +
288- highlightstring + item [ 2 ] ) . html ( item [ 1 ] ) ) ;
298+ let breadcrumbs = _getBreadcrumbs ( item , linkUrl ) ;
299+ breadcrumbs = $ ( "<div class='breadcrumbs'>" + breadcrumbs + "</div>" ) ;
300+ listItem . append ( breadcrumbs ) ;
301+ let headline = $ ( '<h3/>' ) ;
302+ headline . append ( $ ( '<a/>' ) . attr ( 'href' ,
303+ linkUrl +
304+ highlightstring + item [ 2 ] ) . html ( item [ 1 ] ) ) ;
289305
290- listItem . append ( $ ( '<span class="title_doc_section">' + item [ 6 ] + '</span>' ) ) ;
306+ listItem . append ( headline ) ;
291307
292308 if ( item [ 3 ] ) {
293309 listItem . append ( $ ( '<span> (' + item [ 3 ] + ')</span>' ) ) ;
@@ -321,9 +337,9 @@ var Search = {
321337 Search . stopPulse ( ) ;
322338 Search . title . text ( _ ( 'Search Results' ) ) ;
323339 if ( ! resultCount )
324- Search . status . text ( _ ( 'Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories .' ) ) ;
340+ Search . status . text ( _ ( 'Your search did not match any documents. Please make sure that all words are spelled correctly. Searching for multiple words only shows matches that contain all words .' ) ) ;
325341 else
326- Search . status . text ( _ ( 'Search finished, found %s page(s) matching the search query.' ) . replace ( '%s' , resultCount ) ) ;
342+ Search . status . text ( _ ( 'Found %s page(s) matching the search query.' ) . replace ( '%s' , resultCount ) ) ;
327343 Search . status . fadeIn ( 500 ) ;
328344 }
329345 }
@@ -344,7 +360,9 @@ var Search = {
344360 var results = [ ] ;
345361
346362 for ( var prefix in objects ) {
347- for ( var name in objects [ prefix ] ) {
363+ for ( var iMatch = 0 ; iMatch != objects [ prefix ] . length ; ++ iMatch ) {
364+ var match = objects [ prefix ] [ iMatch ] ;
365+ var name = match [ 4 ] ;
348366 var fullname = ( prefix ? prefix + '.' : '' ) + name ;
349367 var fullnameLower = fullname . toLowerCase ( )
350368 if ( fullnameLower . indexOf ( object ) > - 1 ) {
@@ -358,7 +376,6 @@ var Search = {
358376 } else if ( parts [ parts . length - 1 ] . indexOf ( object ) > - 1 ) {
359377 score += Scorer . objPartialMatch ;
360378 }
361- var match = objects [ prefix ] [ name ] ;
362379 var objname = objnames [ match [ 1 ] ] [ 2 ] ;
363380 var title = titles [ match [ 0 ] ] ;
364381 // If more than one term searched for, we require other words to be
@@ -496,19 +513,40 @@ var Search = {
496513 break ;
497514 }
498515 }
499-
500516 // if we have still a valid result we can add it to the result list
501517 if ( valid ) {
518+ /**
519+ * file: index
520+ * docnames: array of paths
521+ * titles: array of titles
522+ */
523+
502524 // select one (max) score for the file.
503525 // for better ranking, we should calculate ranking by using words statistics like basic tf-idf...
504526 var score = $u . max ( $u . map ( fileMap [ file ] , function ( w ) { return scoreMap [ file ] [ w ] } ) ) ;
505- function getParentTitle ( f ) {
506- let parentdocname = docnames [ f ] . split ( '/' ) [ 0 ] + '/index' ;
507- let parentID = docnames . indexOf ( parentdocname ) ;
508- let title = parentID === - 1 ? 'Plone Documentation' : titles [ parentID ] ;
509- return title
527+
528+ /**
529+ * Return array with titles of ancestors of file.
530+ * @param {number } idx - The index of the result item in global list of files
531+ * @returns array
532+ */
533+ function getParentTitles ( idx ) {
534+ let path = docnames [ idx ]
535+
536+ let foo = path . split ( '/' ) . slice ( 0 , - 1 ) ;
537+ foo = foo . map ( ( el , index ) => {
538+ return `${ foo . slice ( 0 , index + 1 ) . join ( '/' ) } /index`
539+ } )
540+
541+ let parentTitles = foo . map ( el => {
542+ let parentId = docnames . indexOf ( el ) ;
543+ let title = parentId === - 1 ? title_documentation : titles [ parentId ] ;
544+ return title
545+ } )
546+ return parentTitles
510547 }
511- results . push ( [ docnames [ file ] , titles [ file ] , '' , null , score , filenames [ file ] , getParentTitle ( file ) ] ) ;
548+
549+ results . push ( [ docnames [ file ] , titles [ file ] , '' , null , score , filenames [ file ] , getParentTitles ( file ) ] ) ;
512550 }
513551 }
514552 return results ;
@@ -544,10 +582,14 @@ var Search = {
544582
545583$ ( document ) . ready ( function ( ) {
546584 Search . init ( ) ;
547- if ( $ . trim ( $ ( ".topbar-contents .bd-toc" ) . html ( ) ) === "" ) {
548- $ ( ".topbar-contents .bd-toc" ) . css ( "visibility" , "hidden" ) ;
549- }
550- $ ( 'select[name="doc_section"]' ) . change ( function ( ) {
585+ $ ( '#q' ) . focus ( ) ;
586+ $ ( 'input[name="doc_section"]' ) . change ( function ( ) {
551587 this . form . submit ( ) ;
552588 } ) ;
589+
590+ function clearSearchField ( ) {
591+ $ ( '#q' ) . val ( '' ) ;
592+ this . form . submit ( ) ;
593+ }
594+ $ ( "button.clear_search" ) . on ( "click" , clearSearchField ) ;
553595} ) ;
0 commit comments