diff --git a/data/OGDs.json b/data/OGDs.json index a81835a5..07a23801 100644 --- a/data/OGDs.json +++ b/data/OGDs.json @@ -78,5 +78,15 @@ { "identifiers":"GB-GOV-15", "name": "Department for International Trade" + }, + "DSIT": + { + "identifiers":"GB-GOV-26", + "name": "Department of Science, Innovation and Technology" + }, + "DESNZ": + { + "identifiers":"GB-GOV-25", + "name": "Department for Energy, Security and Net Zero" } } \ No newline at end of file diff --git a/data/custom-codes/ogds.json b/data/custom-codes/ogds.json index 59c6842a..179519cf 100644 --- a/data/custom-codes/ogds.json +++ b/data/custom-codes/ogds.json @@ -58,5 +58,13 @@ "gb-gov-15": { "name": "Department for International Trade" + }, + "gb-gov-26": + { + "name": "Department of Science, Innovation and Technology" + }, + "gb-gov-25": + { + "name": "Department for Energy, Security and Net Zero" } } \ No newline at end of file diff --git a/data/odas.json b/data/odas.json index 5c0787d7..a0729e9d 100644 --- a/data/odas.json +++ b/data/odas.json @@ -3,87 +3,76 @@ [ { "name":"Foreign, Commonwealth and Development Office", - "year":"2021", - "value": 8308, - "percentage": 72.3, + "year":"2023", + "value": 9491, + "percentage": 61.90, "shortName": "FCDO", "note": "This figure is calculated by summing the those for the recently combined Department for International Development (DFID) and Foreign and Commonwealth Office (FCO) to reflect the new department. The source data describes these institutions separately." } ], - "BEIS": - [ - { - "name":"Department for Business, Energy and Industrial Strategy", - "year":"2021", - "value": 929, - "percentage": 8.1, - "shortName": "BEIS", - "note": "" - } - ], "HO": [ { "name":"Home Office", - "year":"2021", - "value": 915, - "percentage": 8.0, + "year":"2023", + "value": 2954, + "percentage": 19.30, "shortName": "Home Office", "note": "" } ], - "CSSF": + "DH": [ { - "name":"Conflict, Stability and Security Fund", - "year":"2021", - "value": 430, - "percentage": 3.7, - "shortName": "CSSF", + "name":"Department of Health and Social Care", + "year":"2023", + "value": 535, + "percentage": 3.50, + "shortName": "DoH", "note": "" } ], - "DH": + "MHCLG": [ { - "name":"Department of Health and Social Care", - "year":"2021", - "value": 223, - "percentage": 1.9, - "shortName": "DoH", + "name":"Ministry of Housing, Communities and Local Government", + "year":"2023", + "value": 466, + "percentage": 3.00, + "shortName": "MHCLG", "note": "" } ], - "CO": + "DESNZ": [ { - "name":"Cabinet Office", - "year":"2021", - "value": 108, - "percentage": 0.9, - "shortName": "CO", + "name":"Department for Energy Security and Net Zero", + "year":"2023", + "value": 440, + "percentage": 2.90, + "shortName": "DESNZ", "note": "" } ], - "DEFRA": + "CSSF": [ { - "name":"Department for Environment Food and Rural Affairs", - "year":"2021", - "value": 76, - "percentage": 0.7, - "shortName": "DEFRA", + "name":"UK Integrated Security Fund", + "year":"2023", + "value": 326, + "percentage": 2.10, + "shortName": "CSSF", "note": "" } ], - "PF": + "DWP": [ { - "name":"Cross-Government Prosperity Fund", - "year":"2021", - "value": 53, - "percentage": 0.5, - "shortName": "CGPF", + "name":"Department for Work and Pensions", + "year":"2023", + "value": 257, + "percentage": 1.70, + "shortName": "DWP", "note": "" } ], @@ -91,54 +80,76 @@ [ { "name":"Department for Education", - "year":"2021", - "value": 18, - "percentage": 0.2, + "year":"2023", + "value": 169, + "percentage": 1.10, "shortName": "DoE", "note": "" } ], - "DWP": + "DSIT": [ { - "name":"Department for Work and Pensions", - "year":"2021", - "value": 9, - "percentage": 0.1, - "shortName": "DWP", + "name":"Department for Science, Innovation and Technology", + "year":"2023", + "value": 167, + "percentage": 1.10, + "shortName": "DSIT", + "note": "" + } + ], + "DEFRA": + [ + { + "name":"Department for Environment Food and Rural Affairs", + "year":"2023", + "value": 165, + "percentage": 1.10, + "shortName": "DEFRA", + "note": "" + } + ], + "HMRC": + [ + { + "name":"HM Revenue and Customs", + "year":"2023", + "value": 34, + "percentage": 0.20, + "shortName": "HMRC", "note": "" } ], "DCMS": [ { - "name":"Department for Culture, Media and Sports", - "year":"2021", - "value": 7, + "name":"Department for Culture, Media and Sport", + "year":"2023", + "value": 10, "percentage": 0.1, "shortName": "DCMS", "note": "" } ], - "MOD": + "ONS": [ { - "name":"Ministry of Defence", - "year":"2021", - "value": 5, + "name":"Office for National Statistics", + "year":"2023", + "value": 4, "percentage": 0.0, - "shortName": "MOD", + "shortName": "ONS", "note": "" } ], - "HMRC": + "MOD": [ { - "name":"HM Revenue and Customs", - "year":"2021", - "value": 3, + "name":"Ministry of Defence", + "year":"2023", + "value": 4, "percentage": 0.0, - "shortName": "HMRC", + "shortName": "MOD", "note": "" } ], @@ -146,21 +157,43 @@ [ { "name":"HM Treasury", - "year":"2021", - "value": 2, + "year":"2023", + "value": 4, "percentage": 0.0, "shortName": "HMT", "note": "" } ], - "ONS": + "BEIS": [ { - "name":"Office for National Statistics", - "year":"2021", - "value": 2, - "percentage": 0.0, - "shortName": "ONS", + "name":"Department for Business, Energy and Industrial Strategy", + "year":"2023", + "value": 0, + "percentage": 0, + "shortName": "BEIS", + "note": "" + } + ], + "CO": + [ + { + "name":"Cabinet Office", + "year":"2023", + "value": 0, + "percentage": 0, + "shortName": "CO", + "note": "" + } + ], + "PF": + [ + { + "name":"Cross-Government Prosperity Fund", + "year":"2023", + "value": 0, + "percentage": 0, + "shortName": "CGPF", "note": "" } ], @@ -168,8 +201,8 @@ [ { "name":"Department of International Trade", - "year":"2021", - "value": 0.4, + "year":"2023", + "value": 0, "percentage": 0.0, "shortName": "DIT", "note": "" diff --git a/data/participatingOrgList.json b/data/participatingOrgList.json index c99d1f9d..89c85ae0 100644 --- a/data/participatingOrgList.json +++ b/data/participatingOrgList.json @@ -1264,7 +1264,7 @@ "Name": "Department for Business, Innovation and Skills" }, { "Code": "GB-GOV-12", - "Name": "Department for Culture, Media and Sports" + "Name": "Department for Culture, Media and Sport" }, { "Code": "GB-GOV-2", "Name": "HM Treasury" diff --git a/data/solr-config.json b/data/solr-config.json index 7217b053..082776b1 100644 --- a/data/solr-config.json +++ b/data/solr-config.json @@ -1,6 +1,6 @@ { "APILink": "https://fcdo.iati.cloud/", - "DefaultFieldsToReturn": "iati_identifier, reporting_org_ref, reporting_org_narrative, title_narrative_first, title_narrative, description_narrative, activity_date_iso_date, activity_date_start_actual, activity_date_end_planned, activity_status_code, humanitarian, tag_code, tag, child_aggregation_*, activity_plus_child_aggregation*, activity_aggregation_*, default_currency, activity_date_start_common_f, activity_date_end_common_f, activity_date_start_common, activity_date_end_common", + "DefaultFieldsToReturn": "id, iati_identifier, reporting_org_ref, reporting_org_narrative, title_narrative_first, title_narrative, description_narrative, activity_date_iso_date, activity_date_start_actual, activity_date_end_planned, activity_status_code, humanitarian, tag_code, tag, child_aggregation_*, activity_plus_child_aggregation*, activity_aggregation_*, default_currency, activity_date_start_common_f, activity_date_end_common_f, activity_date_start_common, activity_date_end_common", "DefaultFieldsToSearch": [ "title_narrative", @@ -37,7 +37,7 @@ { "title": "Activity Status", "field": "activity_status_code", - "url": "search/activity/?facet=on&facet.field=activity_status_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=activity_status_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "data/mappingSolrFilters/activity_status.json", "defaultValue": "2", "isFieldTypeString": "0" @@ -45,7 +45,7 @@ { "title": "Government Department(s)", "field": "reporting_org_ref", - "url": "search/activity/?facet=on&facet.field=reporting_org_ref&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=reporting_org_ref&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "data/custom-codes/ogds.json", "defaultValue": "", "isFieldTypeString": "1" @@ -53,7 +53,7 @@ { "title": "Tags", "field": "tag_code", - "url": "search/activity/?facet=on&facet.field=tag_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=tag_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "data/custom-codes/policy-priorities.json", "defaultValue": "", "isFieldTypeString": "1" @@ -61,7 +61,7 @@ { "title": "Sectors", "field": "sector_code", - "url": "search/activity/?facet=on&facet.field=sector_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=sector_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "sectorHierarchies.json", "defaultValue": "", "isFieldTypeString": "0" @@ -69,7 +69,7 @@ { "title": "Participating Orgs", "field": "participating_org_ref", - "url": "search/activity/?facet=on&facet.field=participating_org_ref&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND participating_org_role:4 AND ", + "url": "search/activity/?facet=on&facet.field=participating_org_ref&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND participating_org_role:4 AND ", "mappingFile": "iati_publishers_list.json", "defaultValue": "", "isFieldTypeString": "1" @@ -77,7 +77,7 @@ { "title": "Activity Dates", "field": "activity_date_iso_date", - "url": "search/activity/?facet=on&facet.field=activity_date_iso_date&facet.limit=-1&facet.mincount=1&q=participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=activity_date_iso_date&facet.limit=-1&facet.mincount=1&q=participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "", "defaultValue": "", "isFieldTypeString": "1" @@ -85,7 +85,7 @@ { "title": "Benefiting Countries", "field": "recipient_country_code", - "url": "search/activity/?facet=on&facet.field=recipient_country_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=recipient_country_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "data/country-codes/country_codes.json", "defaultValue": "", "isFieldTypeString": "1" @@ -93,7 +93,7 @@ { "title": "Benefiting Regions", "field": "recipient_region_code", - "url": "search/activity/?facet=on&facet.field=recipient_region_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=recipient_region_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "data/regionCodes.json", "defaultValue": "", "isFieldTypeString": "1" @@ -101,7 +101,7 @@ { "title": "Document Categories", "field": "document_link_category_code", - "url": "search/activity/?facet=on&facet.field=document_link_category_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "search/activity/?facet=on&facet.field=document_link_category_code&facet.limit=-1&facet.mincount=1&q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "mappingFile": "data/custom-codes/DocumentCategory.json", "defaultValue": "", "isFieldTypeString": "1" @@ -111,7 +111,7 @@ { "F": { - "url": "/search/activity/?q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "/search/activity/?hl=on&hl.requireFieldMatch=true&hl.fl=title_narrative,title_narrative_first,description_narrative,iati_identifier,transaction_description_narrative,reporting_org_ref,recipient_country_name,document_link_title_narrative_text,transaction,reporting_org_narrative,participating_org_narrative&q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", "fieldDependency": "", "comments": "This search category is related to the free text search of DevTracker" }, @@ -127,7 +127,7 @@ }, "O": { - "url": "/search/activity/?q=hierarchy:1 AND participating_org_ref:GB-GOV-* AND ", + "url": "/search/activity/?q=hierarchy:1 AND participating_org_ref:(GB-GOV-* OR GB-COH-*) AND ", "fieldDependency": "reporting_org_ref" }, "S": @@ -163,5 +163,19 @@ "projects": [ ] + }, + "HumanReadableTerms": + { + "title_narrative": "Title", + "description_narrative": "Description", + "title_narrative_first": "Title", + "iati_identifier": "Programme Id", + "transaction_description_narrative": "Transaction Description", + "reporting_org_ref": "Reporting Organisation Id", + "recipient_country_name": "Recipient Country Name", + "document_link_title_narrative_text": "Document Title", + "transaction": "Transaction", + "reporting_org_narrative": "Reporting Organisation Title", + "participating_org_narrative": "Participating Organisation Title" } } diff --git a/devtracker.rb b/devtracker.rb index 5a784dcb..a8b6247b 100644 --- a/devtracker.rb +++ b/devtracker.rb @@ -80,7 +80,7 @@ set :current_first_day_of_financial_year, first_day_of_financial_year(DateTime.now) set :current_last_day_of_financial_year, last_day_of_financial_year(DateTime.now) -set :goverment_department_ids, 'GB-GOV-15,GB-GOV-9,GB-GOV-6,GB-GOV-2,GB-GOV-1,GB-1,GB-GOV-3,GB-GOV-13,GB-GOV-7,GB-6,GB-10,GB-GOV-10,GB-9,GB-GOV-8,GB-GOV-5,GB-GOV-12,GB-COH-RC000346,GB-COH-03877777,GB-GOV-24' +set :goverment_department_ids, 'GB-GOV-25,GB-GOV-26,GB-GOV-15,GB-GOV-9,GB-GOV-6,GB-GOV-2,GB-GOV-1,GB-1,GB-GOV-3,GB-GOV-13,GB-GOV-7,GB-6,GB-10,GB-GOV-10,GB-9,GB-GOV-8,GB-GOV-5,GB-GOV-12,GB-COH-RC000346,GB-COH-03877777,GB-GOV-24' #set :goverment_department_ids, 'GB-GOV-1,GB-1' set :google_recaptcha_publicKey, ENV["GOOGLE_PUBLIC_KEY"] set :google_recaptcha_privateKey, ENV["GOOGLE_PRIVATE_KEY"] @@ -879,7 +879,8 @@ def getCacheData(fileName) if (!params['query']) query= '' filters = [] - response = + response = {} + response['response'] = { 'numFound' => -1, 'docs' => [] @@ -893,8 +894,9 @@ def getCacheData(fileName) activityStatuses = 'AND activity_status_code:(2)' filters = prepareFilters(query.to_s, 'F') response = solrResponse(query, activityStatuses, 'F', 0, '', '') - if(response['numFound'].to_i > 0) - response = addTotalBudgetWithCurrency(response) + if(response['response']['numFound'].to_i > 0) + response['response'] = addTotalBudgetWithCurrency(response['response']) + response = addHighlightingToFTSTerms(response) end settings.devtracker_page_title = 'Search Results For : ' + query didYouMeanQuery = sanitize_input(params['query'],"a") @@ -907,7 +909,7 @@ def getCacheData(fileName) oipa_api_url: settings.oipa_api_url, query: query, filters: filters, - response: response, + response: response['response'], solrConfig: Oj.load(File.read('data/solr-config.json')), activityStatus: Oj.load(File.read('data/activity_status.json')), searchType: 'F', @@ -934,8 +936,9 @@ def getCacheData(fileName) end filters = prepareFilters(query.to_s, 'F') response = solrResponse(query, activityStatuses, 'F', 0, '', '') - if(response['numFound'].to_i > 0) - response = addTotalBudgetWithCurrency(response) + if(response['response']['numFound'].to_i > 0) + response['response'] = addTotalBudgetWithCurrency(response['response']) + response = addHighlightingToFTSTerms(response) end settings.devtracker_page_title = 'Search Results For : ' + query didYouMeanQuery = sanitize_input(params['query'],"a") @@ -948,7 +951,7 @@ def getCacheData(fileName) oipa_api_url: settings.oipa_api_url, query: query, filters: filters, - response: response, + response: response['response'], solrConfig: Oj.load(File.read('data/solr-config.json')), activityStatus: Oj.load(File.read('data/activity_status.json')), searchType: 'F', @@ -970,8 +973,16 @@ def getCacheData(fileName) searchType = sanitize_input(params['data']['queryType'],"newId") startPage = sanitize_input(params['data']['page'],"newId") response = solrResponse(query, filters, searchType, startPage, sanitize_input(params['data']['dateRange'],"newId"), sanitize_input(params['data']['sortType'],"newId")) - if(response['numFound'].to_i > 0) - response = addTotalBudgetWithCurrency(response) + if searchType == 'F' + if(response['response']['numFound'].to_i > 0) + response['response'] = addTotalBudgetWithCurrency(response['response']) + response = addHighlightingToFTSTerms(response) + response = response['response'] + end + else + if(response['numFound'].to_i > 0) + response = addTotalBudgetWithCurrency(response) + end end json :output => response end diff --git a/helpers/solr_helper.rb b/helpers/solr_helper.rb index 0ac5d70d..7c52b2d7 100644 --- a/helpers/solr_helper.rb +++ b/helpers/solr_helper.rb @@ -110,7 +110,6 @@ def filterDriver(filter, apiUrl, mappingFileUrl) reportingOrgs = response['facet_counts']['facet_fields'][filter] reportingOrgs.each_with_index do |value, index| if index.even? - puts value if(mappedOGDs.has_key?(value)) begin finalData.push(populateKeyVal(mappedOGDs[value]['name'], value)) @@ -230,8 +229,9 @@ def solrResponse(query, filters, queryType, startPage, dateRange, sortType) mainQueryString = mainQueryString + '&sort=' + sortType end # Get response based on the API responses + puts apiLink + queryCategory['url'] + mainQueryString +'&rows='+solrConfig['PageSize'].to_s+'&fl='+solrConfig['DefaultFieldsToReturn']+'&start='+startPage.to_s response = Oj.load(RestClient.get api_simple_log(apiLink + queryCategory['url'] + mainQueryString +'&rows='+solrConfig['PageSize'].to_s+'&fl='+solrConfig['DefaultFieldsToReturn']+'&start='+startPage.to_s)) - response['response'] + response elsif(queryType == 'R') queryCategory = solrConfig['QueryCategories'][queryType] preparedFilters = filters @@ -248,7 +248,6 @@ def solrResponse(query, filters, queryType, startPage, dateRange, sortType) if(sortType != '') mainQueryString = mainQueryString + '&sort=' + sortType end - puts apiLink + queryCategory['url'] + mainQueryString +'&rows='+solrConfig['PageSize'].to_s+'&fl='+solrConfig['DefaultFieldsToReturn']+'&start='+startPage.to_s response = Oj.load(RestClient.get api_simple_log(apiLink + queryCategory['url'] + mainQueryString +'&rows='+solrConfig['PageSize'].to_s+'&fl='+solrConfig['DefaultFieldsToReturn']+'&start='+startPage.to_s)) response['response'] elsif(queryType == 'S') @@ -267,6 +266,7 @@ def solrResponse(query, filters, queryType, startPage, dateRange, sortType) if(sortType != '') mainQueryString = mainQueryString + '&sort=' + sortType end + puts apiLink + queryCategory['url'] + mainQueryString +'&rows='+solrConfig['PageSize'].to_s+'&fl='+solrConfig['DefaultFieldsToReturn']+'&start='+startPage.to_s response = Oj.load(RestClient.get api_simple_log(apiLink + queryCategory['url'] + mainQueryString +'&rows='+solrConfig['PageSize'].to_s+'&fl='+solrConfig['DefaultFieldsToReturn']+'&start='+startPage.to_s)) response['response'] end @@ -363,4 +363,56 @@ def addTotalBudgetWithCurrency(response) end response end + + def addHighlightingToFTSTerms(response) + solrConfig = Oj.load(File.read('data/solr-config.json')) + hrt = solrConfig['HumanReadableTerms'] + highlightedTexts = response['highlighting'] + response['response']['docs'].each do |r| + if highlightedTexts.has_key?(r['id'].to_s) + if !highlightedTexts[r['id']].empty? + firstElement = highlightedTexts[r['id'].to_s].first + firstElement[1] = firstElement[1].reject{|k| k.to_s == ''} + matchedText = firstElement[1].first.to_s + matchedText = process_string(matchedText) + key = firstElement[0] + val = '... ' + matchedText + ' ....' + r['highlightedKey'] = hrt[key] + r['highlightedValue'] = val + end + end + end + response + end + + def process_string(input) + # Find the index of the tag + em_start = input.index("") + em_end = input.index("") + "".length + + # Handle if tags are not found + return "" if em_start.nil? || em_end.nil? + + # Split the string into words + words = input.split + + # 1. Get the first string with one or two words before "" + # Find the index of the word containing "" + em_word_index = words.index { |word| word.include?("") } + + # Take one or two words before the "" + first_string = words[[0, em_word_index - 2].max..em_word_index - 1].join(" ") + + # 2. Extract the substring inside tags + em_string = input[em_start...em_end] + + # 3. Get two or three words after "" + after_em_index = words.index { |word| word.include?("") } + 1 + last_string = words[after_em_index, 3].join(" ") + + # Combine all three parts together + final_string = [first_string, em_string, last_string].join(" ") + + return final_string + end end \ No newline at end of file diff --git a/views/department/department.html.erb b/views/department/department.html.erb index 331e81bb..fbdd62ba 100644 --- a/views/department/department.html.erb +++ b/views/department/department.html.erb @@ -76,7 +76,7 @@ title: Development Tracker - + + @@ -121,7 +132,7 @@ title: Development Tracker <% end %>
-

Source: Statistics on International Development +

Source: Statistics on International Development 2023 diff --git a/views/index.html.erb b/views/index.html.erb index efa0ac5a..ada1f2d7 100644 --- a/views/index.html.erb +++ b/views/index.html.erb @@ -165,10 +165,10 @@ layout: cw_landing

Top 10 departments

-

UK ODA spend by government department

+

UK ODA spend by government department (Source, Statistics on International Development 2023)

<% odas.each do |oda| %>
- <%if oda[0]=='PF' || oda[0]=='CSSF' %> + <%if oda[0]=='PF' || oda[0]=='CSSF' || oda[0]=='MHCLG' || oda[0]=='HMRC' %> <%= oda[1][0]["name"] %> diff --git a/views/search/solrTemplate.html.erb b/views/search/solrTemplate.html.erb index 1a25729b..def4f7fb 100644 --- a/views/search/solrTemplate.html.erb +++ b/views/search/solrTemplate.html.erb @@ -226,7 +226,14 @@ <%=item['reporting_org_narrative'].first%> <%end%>

- + <%if item.has_key?('highlightedKey')%> + + <%begin%> +

Found a match in field: <%=item['highlightedKey']%> - <%=item['highlightedValue']%>

+ <%rescue%> + <%end%> +
+ <%end%>

<%begin%> <%=item['description_narrative'].first%> @@ -633,6 +640,12 @@ var prepareContainer = ''; $.each(response.output.docs,function(i, result){ var startDate = new Date(result.activity_date_start_common); + var highlightedKey = ''; + var highlightedVal = ''; + if (result.hasOwnProperty('highlightedKey')) { + highlightedKey = result.highlightedKey; + highlightedVal = result.highlightedValue; + } if (result.reporting_org_narrative[0] != 'UK - Department for International Development (DFID)') { var reporting_org = result.reporting_org_narrative[0]; } @@ -640,10 +653,10 @@ var reporting_org = 'UK - Foreign, Commonwealth and Development Office'; } if(typeof result.description_narrative === 'undefined'){ - prepareContainer = prepareContainer + '

' + result.title_narrative_first + '

' + reporting_org + '

' + 'No description available' + '

Programme Id' + result.iati_identifier + '
Start date ' + startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate() + '
Activity status' + activityStatus[parseInt(result.activity_status_code) - 1].name + '
Total budget'+result.totalBudgetWithCurrency+'
'; + prepareContainer = prepareContainer + '

' + result.title_narrative_first + '

' + reporting_org + '

Found a match in field: '+highlightedKey+' - '+highlightedVal+'

' + 'No description available' + '

Programme Id' + result.iati_identifier + '
Start date ' + startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate() + '
Activity status' + activityStatus[parseInt(result.activity_status_code) - 1].name + '
Total budget'+result.totalBudgetWithCurrency+'
'; } else{ - prepareContainer = prepareContainer + '

' + result.title_narrative_first + '

' + reporting_org + '

' + result.description_narrative[0] + '

Programme Id' + result.iati_identifier + '
Start date ' + startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate() + '
Activity status' + activityStatus[parseInt(result.activity_status_code) - 1].name + '
Total budget'+result.totalBudgetWithCurrency+'
'; + prepareContainer = prepareContainer + '

' + result.title_narrative_first + '

' + reporting_org + '

Found a match in field: '+highlightedKey+' - '+highlightedVal+'

' + result.description_narrative[0] + '

Programme Id' + result.iati_identifier + '
Start date ' + startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate() + '
Activity status' + activityStatus[parseInt(result.activity_status_code) - 1].name + '
Total budget'+result.totalBudgetWithCurrency+'
'; } }) $('#response-container').html(prepareContainer);