diff --git a/dr-app/public/js/query.js b/dr-app/public/js/query.js index e88a5822..e43b9ab4 100644 --- a/dr-app/public/js/query.js +++ b/dr-app/public/js/query.js @@ -480,7 +480,7 @@ async function getPlaceSearchResults(pageNum, recordNum, parameters) { ?entity elastic:score ?score. ?entity a ?type; rdfs:label ?label; - OPTIONAL {?entity kwg-ont:quantifiedName ?quantifiedName. } + OPTIONAL { ?entity kwg-ont:quantifiedName ?quantifiedName. } values ?type {kwg-ont:AdministrativeRegion_2 kwg-ont:AdministrativeRegion_3} ?type rdfs:label ?typeLabel } order by desc(?score)`); @@ -896,7 +896,7 @@ async function getHazardSearchResults(pageNum, recordNum, parameters) { hazardEntites.push(row.entity.value.replace('http://stko-kwg.geog.ucsb.edu/lod/resource/','kwgr:')); } - let hazardAttributesQuery = `select distinct ?entity (group_concat(distinct ?type; separator = "||") as ?type) (group_concat(distinct ?typeLabel; separator = "||") as ?typeLabel) (group_concat(distinct ?place; separator = "||") as ?place) (group_concat(distinct ?placeLabel; separator = "||") as ?placeLabel) (group_concat(distinct ?placeQuantName; separator = "||") as ?placeQuantName) (group_concat(distinct ?time; separator = "||") as ?time) (group_concat(distinct ?startTimeLabel; separator = "||") as ?startTimeLabel) (group_concat(distinct ?endTimeLabel; separator = "||") as ?endTimeLabel) + let hazardAttributesQuery = `select distinct ?entity (group_concat(distinct ?placeQuantName; separator = "||") as ?placeQuantName) (group_concat(distinct ?placeLabel; separator = "||") as ?placeLabel) (group_concat(distinct ?type; separator = "||") as ?type) (group_concat(distinct ?typeLabel; separator = "||") as ?typeLabel) (group_concat(distinct ?place; separator = "||") as ?place) (group_concat(distinct ?time; separator = "||") as ?time) (group_concat(distinct ?startTimeLabel; separator = "||") as ?startTimeLabel) (group_concat(distinct ?endTimeLabel; separator = "||") as ?endTimeLabel) { ?entity rdf:type ?type; kwg-ont:hasTemporalScope|sosa:isFeatureOfInterestOf/sosa:phenomenonTime ?time. @@ -915,33 +915,29 @@ async function getHazardSearchResults(pageNum, recordNum, parameters) { time:inXSDDateTime|time:inXSDDate ?endTimeLabel. VALUES ?entity {${hazardEntites.join(' ')}} - } GROUP BY ?entity`; + } GROUP BY ?entity` ; queryResults = await query(hazardAttributesQuery); - - let counterRow = -1; - for (let row of queryResults) { - counterRow += 1; + queryResults.forEach(function(row, counterRow) { // If there isn't a quantified name use the regular label if (typeof row.placeQuantName === 'undefined') { // If there isn't a place name, use '' if (typeof row.placeLabel === 'undefined') { formattedResults[counterRow]['place_name'] = ''; } else { - formattedResults[counterRow]['place_name'] = row.placeLabel.value; + formattedResults[counterRow]['place_name'] = row.placeLabel.value.split('||')[0]; } } else { - formattedResults[counterRow]['place_name'] = row.placeQuantName.value; + formattedResults[counterRow]['place_name'] = row.placeQuantName.value.split('||')[0]; } formattedResults[counterRow]['hazard_type'] = row.type.value.split('||'); formattedResults[counterRow]['hazard_type_name'] = row.typeLabel.value.split('||'); - formattedResults[counterRow]['place'] = (typeof row.place === 'undefined') ? '' : row.place.value.split('||'); - formattedResults[counterRow]['place_name'] = formattedResults[counterRow]['place_name'].split('||'); + formattedResults[counterRow]['place'] = (typeof row.place === 'undefined') ? '' : row.place.value.split('||')[0]; formattedResults[counterRow]['start_date'] = row.time.value.split('||')[0]; formattedResults[counterRow]['start_date_name'] = row.startTimeLabel.value.split('||')[0]; formattedResults[counterRow]['end_date'] = row.time.value.split('||')[0]; formattedResults[counterRow]['end_date_name'] = row.endTimeLabel.value.split('||')[0]; - } + }) let countResults = await query(`select (count(*) as ?count) { ` + hazardQuery + ` LIMIT ` + recordNum*10 + `}`); return { 'count': countResults[0].count.value, 'record': formattedResults };