File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -371,10 +371,26 @@ def addHighlightingToFTSTerms(response)
371371 if highlightedTexts . has_key? ( r [ 'id' ] . to_s )
372372 if !highlightedTexts [ r [ 'id' ] ] . empty?
373373 firstElement = highlightedTexts [ r [ 'id' ] . to_s ] . first
374+ firstElement [ 1 ] = firstElement [ 1 ] . reject { |k | k . to_s == '' }
374375 matchedText = firstElement [ 1 ] . first . to_s
375- startingTextIndex = matchedText . index ( '<em>' )
376- if startingTextIndex > 15
377- matchedText = matchedText [ ( startingTextIndex -15 ) , matchedText . length ]
376+ begin
377+ startingTextIndex = matchedText . index ( '<em>' )
378+ rescue
379+ startingTextIndex = -1
380+ end
381+ begin
382+ if startingTextIndex > 15
383+ matchedText = matchedText [ ( startingTextIndex -15 ) , matchedText . length ]
384+ end
385+ rescue
386+ puts 'stuck!'
387+ puts matchedText
388+ puts '-=-=-=-=-=-='
389+ puts firstElement
390+ puts 'xx---xx--xx---'
391+ puts matchedText . index ( '<em>' )
392+ puts startingTextIndex
393+ puts '------'
378394 end
379395 endingTextIndex = matchedText . index ( '</em>' ) #length is 7. found at spot 2+5.
380396 if matchedText . length > endingTextIndex + 5 + 12
Original file line number Diff line number Diff line change 644644 var highlightedVal = '' ;
645645 if ( result . hasOwnProperty ( 'highlightedKey' ) ) {
646646 highlightedKey = result . highlightedKey ;
647- highlightedVal = result . highlightedValue [ 0 ] ;
647+ highlightedVal = result . highlightedValue ;
648648 }
649649 if ( result . reporting_org_narrative [ 0 ] != 'UK - Department for International Development (DFID)' ) {
650650 var reporting_org = result . reporting_org_narrative [ 0 ] ;
653653 var reporting_org = 'UK - Foreign, Commonwealth and Development Office' ;
654654 }
655655 if ( typeof result . description_narrative === 'undefined' ) {
656- prepareContainer = prepareContainer + '<div class="app-search-result"><h3 class="govuk-heading-s app-search-result-title"><a href="/projects/' + encodeURIComponent ( result . iati_identifier ) . toString ( ) + '/summary" class="govuk-link--no-visited-state">' + result . title_narrative_first + '</a></h3><p class="govuk-body-s app-search-result-department">' + reporting_org + '</p><span class="text-highlighting" style="color: grey"><p>Found a match in field: ' + highlightedKey + '</p></span><p class="govuk-body-s description">' + 'No description available' + '</p><div class="app-search-result-info"><div><span class="govuk-body-s app-search-result-info__title">Programme Id</span><span class="govuk-body-s app-search-result-info__value">' + result . iati_identifier + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Start date</span><span class="govuk-body-s app-search-result-info__value"> ' + startDate . getFullYear ( ) + '-' + ( startDate . getMonth ( ) + 1 ) + '-' + startDate . getDate ( ) + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Activity status</span><span class="govuk-body-s app-search-result-info__value">' + activityStatus [ parseInt ( result . activity_status_code ) - 1 ] . name + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Total budget</span><span class="govuk-body-s app-search-result-info__value">' + result . totalBudgetWithCurrency + '</span></div></div></div>' ;
656+ prepareContainer = prepareContainer + '<div class="app-search-result"><h3 class="govuk-heading-s app-search-result-title"><a href="/projects/' + encodeURIComponent ( result . iati_identifier ) . toString ( ) + '/summary" class="govuk-link--no-visited-state">' + result . title_narrative_first + '</a></h3><p class="govuk-body-s app-search-result-department">' + reporting_org + '</p><span class="text-highlighting" style="color: grey"><p>Found a match in field: ' + highlightedKey + ' <span>' + highlightedVal + '</span></p></span><p class="govuk-body-s description">' + 'No description available' + '</p><div class="app-search-result-info"><div><span class="govuk-body-s app-search-result-info__title">Programme Id</span><span class="govuk-body-s app-search-result-info__value">' + result . iati_identifier + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Start date</span><span class="govuk-body-s app-search-result-info__value"> ' + startDate . getFullYear ( ) + '-' + ( startDate . getMonth ( ) + 1 ) + '-' + startDate . getDate ( ) + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Activity status</span><span class="govuk-body-s app-search-result-info__value">' + activityStatus [ parseInt ( result . activity_status_code ) - 1 ] . name + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Total budget</span><span class="govuk-body-s app-search-result-info__value">' + result . totalBudgetWithCurrency + '</span></div></div></div>' ;
657657 }
658658 else {
659- prepareContainer = prepareContainer + '<div class="app-search-result"><h3 class="govuk-heading-s app-search-result-title"><a href="/projects/' + encodeURIComponent ( result . iati_identifier ) . toString ( ) + '/summary" class="govuk-link--no-visited-state">' + result . title_narrative_first + '</a></h3><p class="govuk-body-s app-search-result-department">' + reporting_org + '</p><span class="text-highlighting" style="color: grey"><p>Found a match in field: ' + highlightedKey + '</p></span><p class="govuk-body-s description">' + result . description_narrative [ 0 ] + '</p><div class="app-search-result-info"><div><span class="govuk-body-s app-search-result-info__title">Programme Id</span><span class="govuk-body-s app-search-result-info__value">' + result . iati_identifier + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Start date</span><span class="govuk-body-s app-search-result-info__value"> ' + startDate . getFullYear ( ) + '-' + ( startDate . getMonth ( ) + 1 ) + '-' + startDate . getDate ( ) + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Activity status</span><span class="govuk-body-s app-search-result-info__value">' + activityStatus [ parseInt ( result . activity_status_code ) - 1 ] . name + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Total budget</span><span class="govuk-body-s app-search-result-info__value">' + result . totalBudgetWithCurrency + '</span></div></div></div>' ;
659+ prepareContainer = prepareContainer + '<div class="app-search-result"><h3 class="govuk-heading-s app-search-result-title"><a href="/projects/' + encodeURIComponent ( result . iati_identifier ) . toString ( ) + '/summary" class="govuk-link--no-visited-state">' + result . title_narrative_first + '</a></h3><p class="govuk-body-s app-search-result-department">' + reporting_org + '</p><span class="text-highlighting" style="color: grey"><p>Found a match in field: ' + highlightedKey + ' <span>' + highlightedVal + '</span></p></span><p class="govuk-body-s description">' + result . description_narrative [ 0 ] + '</p><div class="app-search-result-info"><div><span class="govuk-body-s app-search-result-info__title">Programme Id</span><span class="govuk-body-s app-search-result-info__value">' + result . iati_identifier + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Start date</span><span class="govuk-body-s app-search-result-info__value"> ' + startDate . getFullYear ( ) + '-' + ( startDate . getMonth ( ) + 1 ) + '-' + startDate . getDate ( ) + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Activity status</span><span class="govuk-body-s app-search-result-info__value">' + activityStatus [ parseInt ( result . activity_status_code ) - 1 ] . name + '</span></div><div><span class="govuk-body-s app-search-result-info__title">Total budget</span><span class="govuk-body-s app-search-result-info__value">' + result . totalBudgetWithCurrency + '</span></div></div></div>' ;
660660 }
661661 } )
662662 $ ( '#response-container' ) . html ( prepareContainer ) ;
You can’t perform that action at this time.
0 commit comments