|
102 | 102 | top5countries = '' |
103 | 103 | Benchmark.bm(7) do |x| |
104 | 104 | x.report("Loading Time: ") { |
105 | | - if (!canLoadFromCache('top5Countries')) |
106 | | - storeCacheData(get_top_5_countriesv2(), 'top5Countries') |
107 | | - top5countries = getCacheData('top5Countries') |
108 | | - else |
109 | | - top5countries = getCacheData('top5Countries') |
110 | | - end |
| 105 | + # if (!canLoadFromCache('top5Countries')) |
| 106 | + # storeCacheData(get_top_5_countriesv2(), 'top5Countries') |
| 107 | + # top5countries = getCacheData('top5Countries') |
| 108 | + # else |
| 109 | + # top5countries = getCacheData('top5Countries') |
| 110 | + # end |
| 111 | + #storeCacheData(get_top_5_countriesv2(), 'top5Countries') |
| 112 | + top5countries = get_top_5_countriesv2() #getCacheData('top5Countries') |
111 | 113 | #oipa v3.1 |
112 | 114 | } |
113 | 115 | end |
|
118 | 120 | # Example of setting up a cookie from server end |
119 | 121 | # response.set_cookie('my_cookie', 'value_of_cookie') |
120 | 122 | what_we_do = '' |
121 | | - if (!canLoadFromCache('what_we_do')) |
122 | | - ## logic |
123 | | - ## get budget data, then check if they fall within date range |
124 | | - ## do a summation of the budget amount within date range |
125 | | - ## pick dac5 sector code and then get the underlying high level sector code |
126 | | - ## if the sector is present, add the new budget info to this sector |
127 | | - ## Else create a new ref to the high level sector code and add |
128 | | - ## budget value starting from 0 |
129 | | - ## pick budget percentage for each dac5 sector code2 |
130 | | - ## calculate the budget amount against that perentage and add it to |
131 | | - ## the high level related sector code |
132 | | - newApiCall = settings.oipa_api_url + "activity?q=participating_org_ref:GB-GOV-* AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z]&fl=iati_identifier,budget_value,recipient_country_code,recipient_region_code,budget_period_start_iso_date,budget_period_end_iso_date,sector_code,sector_percentage,&rows=50000" |
| 123 | + newApiCall = settings.oipa_api_url + "activity?q=participating_org_ref:GB-GOV-* AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z]&fl=iati_identifier,budget_value,recipient_country_code,recipient_region_code,budget_period_start_iso_date,budget_period_end_iso_date,sector_code,sector_percentage,&rows=50000" |
| 124 | + pulledData = RestClient.get newApiCall |
| 125 | + what_we_do = high_level_sector_listv2(pulledData, 'top_five_sectors') |
| 126 | + # if (!canLoadFromCache('what_we_do')) |
| 127 | + # ## logic |
| 128 | + # ## get budget data, then check if they fall within date range |
| 129 | + # ## do a summation of the budget amount within date range |
| 130 | + # ## pick dac5 sector code and then get the underlying high level sector code |
| 131 | + # ## if the sector is present, add the new budget info to this sector |
| 132 | + # ## Else create a new ref to the high level sector code and add |
| 133 | + # ## budget value starting from 0 |
| 134 | + # ## pick budget percentage for each dac5 sector code2 |
| 135 | + # ## calculate the budget amount against that perentage and add it to |
| 136 | + # ## the high level related sector code |
| 137 | + # newApiCall = settings.oipa_api_url + "activity?q=participating_org_ref:GB-GOV-* AND reporting_org_ref:(#{settings.goverment_department_ids.gsub(","," OR ")}) AND budget_period_start_iso_date:[#{settings.current_first_day_of_financial_year}T00:00:00Z TO *] AND budget_period_end_iso_date:[* TO #{settings.current_last_day_of_financial_year}T00:00:00Z]&fl=iati_identifier,budget_value,recipient_country_code,recipient_region_code,budget_period_start_iso_date,budget_period_end_iso_date,sector_code,sector_percentage,&rows=50000" |
133 | 138 |
|
134 | | - pulledData = RestClient.get newApiCall |
135 | | - storeCacheData(high_level_sector_listv2(pulledData, 'top_five_sectors'), 'what_we_do') |
136 | | - what_we_do = getCacheData('what_we_do') |
137 | | - else |
138 | | - what_we_do = getCacheData('what_we_do') |
139 | | - end |
| 139 | + # pulledData = RestClient.get newApiCall |
| 140 | + # storeCacheData(high_level_sector_listv2(pulledData, 'top_five_sectors'), 'what_we_do') |
| 141 | + # what_we_do = getCacheData('what_we_do') |
| 142 | + # else |
| 143 | + # what_we_do = getCacheData('what_we_do') |
| 144 | + # end |
140 | 145 |
|
141 | 146 | whatWeDoTotal = what_we_do.first['budget'] |
142 | 147 | top5countries = top5countries.select{|i| i.has_key?('budget')} |
@@ -901,16 +906,16 @@ def getCacheData(fileName) |
901 | 906 | response = solrResponse(query, activityStatuses, 'F', 0, '', '') |
902 | 907 | ##Clean any unnecessary activity |
903 | 908 | ## TODO |
904 | | - elist = Oj.load(RestClient.get 'https://iati.fcdo.gov.uk/iati_files/elist.json') |
905 | | - if elist.length > 0 |
906 | | - tempResponseList = response['response']['docs'] |
907 | | - tempResponseList.each do |data| |
908 | | - if elist.include?(data['iati_identifier']) |
909 | | - tempResponseList.delete(data) |
910 | | - end |
911 | | - end |
912 | | - response['response']['docs'] = tempResponseList |
913 | | - end |
| 909 | + # elist = Oj.load(RestClient.get 'https://iati.fcdo.gov.uk/iati_files/elist.json') |
| 910 | + # if elist.length > 0 |
| 911 | + # tempResponseList = response['response']['docs'] |
| 912 | + # tempResponseList.each do |data| |
| 913 | + # if elist.include?(data['iati_identifier']) |
| 914 | + # tempResponseList.delete(data) |
| 915 | + # end |
| 916 | + # end |
| 917 | + # response['response']['docs'] = tempResponseList |
| 918 | + # end |
914 | 919 | ## |
915 | 920 | if(response['response']['numFound'].to_i > 0) |
916 | 921 | response['response'] = addTotalBudgetWithCurrency(response['response']) |
@@ -948,21 +953,21 @@ def getCacheData(fileName) |
948 | 953 | query = sanitize_input(params['query'],"newId") |
949 | 954 | isIncludeClosedProjects = sanitize_input(params['includeClosedProject'],"newId") |
950 | 955 | if(isIncludeClosedProjects.to_i != 1) |
951 | | - activityStatuses = 'AND activity_status_code:(2)' |
| 956 | + activityStatuses = '&fq=activity_status_code:(2)' |
952 | 957 | else |
953 | | - activityStatuses = 'AND activity_status_code:(2 OR 3 OR 4 OR 5)' |
954 | | - end |
955 | | - if(!query.start_with?("\"")) |
956 | | - tempQ = '"' + query + '"' |
957 | | - isInIdentifier = RestClient.get api_simple_log(settings.oipa_api_url + "activity?q=iati_identifier:#{tempQ}&fl=iati_identifier&rows=1") |
958 | | - isInTitle = RestClient.get api_simple_log(settings.oipa_api_url + "activity?q=title_narrative_text:#{tempQ}&fl=iati_identifier&rows=1") |
959 | | - checkInID = Oj.load(isInIdentifier) |
960 | | - checkInTitle = Oj.load(isInTitle) |
961 | | - if(checkInID['response']['numFound'].to_i == 1 || checkInTitle['response']['numFound'].to_i == 1) |
962 | | - query = tempQ |
963 | | - else |
964 | | - end |
| 958 | + activityStatuses = '&fq=activity_status_code:(2 OR 3 OR 4 OR 5)' |
965 | 959 | end |
| 960 | + # if(!query.start_with?("\"")) |
| 961 | + # tempQ = '"' + query + '"' |
| 962 | + # isInIdentifier = RestClient.get api_simple_log(settings.oipa_api_url + "activity?q=iati_identifier:#{tempQ}&fl=iati_identifier&rows=1") |
| 963 | + # isInTitle = RestClient.get api_simple_log(settings.oipa_api_url + "activity?q=title_narrative_text:#{tempQ}&fl=iati_identifier&rows=1") |
| 964 | + # checkInID = Oj.load(isInIdentifier) |
| 965 | + # checkInTitle = Oj.load(isInTitle) |
| 966 | + # if(checkInID['response']['numFound'].to_i == 1 || checkInTitle['response']['numFound'].to_i == 1) |
| 967 | + # query = tempQ |
| 968 | + # else |
| 969 | + # end |
| 970 | + # end |
966 | 971 | filters = prepareFilters(query.to_s, 'F') |
967 | 972 | response = solrResponse(query, activityStatuses, 'F', 0, '', '') |
968 | 973 | if(response['response']['numFound'].to_i > 0) |
@@ -1005,14 +1010,80 @@ def getCacheData(fileName) |
1005 | 1010 | } |
1006 | 1011 | end |
1007 | 1012 |
|
| 1013 | +# post '/search_p/?' do |
| 1014 | +# #query = params['query'] |
| 1015 | +# query = sanitize_input(params['query'],"newId") |
| 1016 | +# isIncludeClosedProjects = sanitize_input(params['includeClosedProject'],"newId") |
| 1017 | +# if(isIncludeClosedProjects.to_i != 1) |
| 1018 | +# activityStatuses = 'AND activity_status_code:(2)' |
| 1019 | +# else |
| 1020 | +# activityStatuses = 'AND activity_status_code:(2 OR 3 OR 4 OR 5)' |
| 1021 | +# end |
| 1022 | +# if(!query.start_with?("\"")) |
| 1023 | +# tempQ = '"' + query + '"' |
| 1024 | +# isInIdentifier = RestClient.get api_simple_log(settings.oipa_api_url + "activity?q=iati_identifier:#{tempQ}&fl=iati_identifier&rows=1") |
| 1025 | +# isInTitle = RestClient.get api_simple_log(settings.oipa_api_url + "activity?q=title_narrative_text:#{tempQ}&fl=iati_identifier&rows=1") |
| 1026 | +# checkInID = Oj.load(isInIdentifier) |
| 1027 | +# checkInTitle = Oj.load(isInTitle) |
| 1028 | +# if(checkInID['response']['numFound'].to_i == 1 || checkInTitle['response']['numFound'].to_i == 1) |
| 1029 | +# query = tempQ |
| 1030 | +# else |
| 1031 | +# end |
| 1032 | +# end |
| 1033 | +# filters = prepareFilters(query.to_s, 'F') |
| 1034 | +# response = solrResponse(query, activityStatuses, 'F', 0, '', '') |
| 1035 | +# if(response['response']['numFound'].to_i > 0) |
| 1036 | +# ##Clean any unnecessary activity |
| 1037 | +# ## TODO |
| 1038 | +# elist = Oj.load(RestClient.get 'https://iati.fcdo.gov.uk/iati_files/elist.json') |
| 1039 | +# if elist.length > 0 |
| 1040 | +# tempResponseList = response['response']['docs'] |
| 1041 | +# tempResponseList.each do |data| |
| 1042 | +# if elist.include?(data['iati_identifier']) |
| 1043 | +# tempResponseList.delete(data) |
| 1044 | +# end |
| 1045 | +# end |
| 1046 | +# response['response']['docs'] = tempResponseList |
| 1047 | +# end |
| 1048 | +# ## |
| 1049 | +# response['response'] = addTotalBudgetWithCurrency(response['response']) |
| 1050 | +# response = addHighlightingToFTSTerms(response) |
| 1051 | +# end |
| 1052 | +# settings.devtracker_page_title = 'Search Results For : ' + query |
| 1053 | +# didYouMeanQuery = sanitize_input(params['query'],"a") |
| 1054 | +# #didYouMeanData = generate_did_you_mean_data(didYouMeanQuery,'2') |
| 1055 | +# #erb :'search/solrSearch', |
| 1056 | +# erb :'search/solrTemplate', |
| 1057 | +# :layout => :'layouts/layout', |
| 1058 | +# :locals => |
| 1059 | +# { |
| 1060 | +# oipa_api_url: settings.oipa_api_url, |
| 1061 | +# query: query, |
| 1062 | +# filters: filters, |
| 1063 | +# response: response['response'], |
| 1064 | +# solrConfig: Oj.load(File.read('data/solr-config.json')), |
| 1065 | +# activityStatus: Oj.load(File.read('data/activity_status.json')), |
| 1066 | +# searchType: 'F', |
| 1067 | +# breadcrumbURL: '', |
| 1068 | +# breadcrumbText: '', |
| 1069 | +# fcdoCountryBudgets: nil,#didYouMeanData['dfidCountryBudgets'], |
| 1070 | +# fcdoRegionBudgets: nil,#didYouMeanData['dfidRegionBudgets'], |
| 1071 | +# isIncludeClosedProjects: isIncludeClosedProjects |
| 1072 | +# } |
| 1073 | +# end |
| 1074 | + |
1008 | 1075 | post '/solr-response' do |
1009 | 1076 | query = sanitize_input(params['data']['query'],"newId") |
| 1077 | + searchType = sanitize_input(params['data']['queryType'],"newId") |
1010 | 1078 | if params['data']['filters'].strip.length > 1 |
1011 | | - filters = 'AND ' + sanitize_input(params['data']['filters'],"newId") |
| 1079 | + if searchType == 'F' |
| 1080 | + filters = '&fq=' + sanitize_input(params['data']['filters'],"newId").gsub(/\band\b/, " &fq= ") |
| 1081 | + else |
| 1082 | + filters = 'AND ' + sanitize_input(params['data']['filters'],"newId") |
| 1083 | + end |
1012 | 1084 | else |
1013 | 1085 | filters = '' |
1014 | 1086 | end |
1015 | | - searchType = sanitize_input(params['data']['queryType'],"newId") |
1016 | 1087 | startPage = sanitize_input(params['data']['page'],"newId") |
1017 | 1088 | response = solrResponse(query, filters, searchType, startPage, sanitize_input(params['data']['dateRange'],"newId"), sanitize_input(params['data']['sortType'],"newId")) |
1018 | 1089 | if searchType == 'F' |
|
0 commit comments