@@ -165,7 +165,7 @@ const aggregationsToResult = (aggs) => {
165165
166166export const getTemplateSearchResults = ( query , options = { } ) => {
167167 const body = getTemplateSearchResultsBody ( query , options )
168- return fetchTemplateSearchResults ( body , templateHitsToResult ) . then (
168+ return fetchTemplateSearchResults ( query , templateHitsToResult ) . then (
169169 ( searchResults ) => {
170170 if ( Config . useResourceTemplateFixtures ) {
171171 const newResults = searchResults . results . filter (
@@ -243,11 +243,10 @@ const fetchTemplateSearchResults = async (body, hitsToResultFunc) => {
243243 }
244244 }
245245
246- const url = `${ Config . searchHost } ${ Config . templateSearchPath } `
246+ const url = `${ Config . searchHost } ${ Config . templateSearchPath } ? ${ body } `
247247 return fetch ( url , {
248- method : "POST " ,
248+ method : "GET " ,
249249 headers : { "Content-Type" : "application/json" } ,
250- body : JSON . stringify ( body ) ,
251250 } )
252251 . then ( ( resp ) => {
253252 if ( resp . status >= 300 ) {
@@ -267,7 +266,7 @@ const fetchTemplateSearchResults = async (body, hitsToResultFunc) => {
267266 error : json . error . reason || json . error ,
268267 }
269268 }
270- return hitsToResultFunc ( json . hits )
269+ return hitsToResultFunc ( json . results )
271270 } )
272271 . catch ( ( err ) => ( {
273272 totalHits : 0 ,
@@ -276,9 +275,46 @@ const fetchTemplateSearchResults = async (body, hitsToResultFunc) => {
276275 } ) )
277276}
278277
278+ const templateModFromBlueCore = ( hit ) => {
279+ // Formats Blue Core Template Result for editor's expectations
280+ let resourceAuthor = "Unknown"
281+ let resourceId = "Unknown"
282+ let resourceDate = "Unknown"
283+ let resourceLabel = "Unknown"
284+ let resourceRemark = ""
285+ let resourceURI = "Unknown"
286+ hit . data . map ( ( row ) => {
287+ if ( row [ "@id" ] === hit . uri ) {
288+ resourceAuthor =
289+ row [ "http://sinopia.io/vocabulary/hasAuthor" ] [ 0 ] [ "@value" ]
290+ resourceDate = row [ "http://sinopia.io/vocabulary/hasDate" ] [ 0 ] [ "@value" ]
291+ resourceLabel =
292+ row [ "http://www.w3.org/2000/01/rdf-schema#label" ] [ 0 ] [ "@value" ]
293+ resourceId =
294+ row [ "http://sinopia.io/vocabulary/hasResourceId" ] [ 0 ] [ "@value" ]
295+ resourceURI = row [ "http://sinopia.io/vocabulary/hasClass" ] [ 0 ] [ "@id" ]
296+ resourceRemark = row [ "http://sinopia.io/vocabulary/hasRemark" ]
297+ ? row [ "http://sinopia.io/vocabulary/hasRemark" ] [ 0 ] [ "@value" ]
298+ : ""
299+ }
300+ } )
301+ const bcURI = `${ Config . sinopiaApiBase } /resources/${ hit . id } `
302+ return {
303+ author : resourceAuthor ,
304+ date : resourceDate ,
305+ group : "blue core" , // hardcoded for now
306+ id : resourceId ,
307+ originalURI : hit . uri ,
308+ remark : resourceRemark ,
309+ resourceLabel : resourceLabel ,
310+ resourceURI : resourceURI ,
311+ uri : bcURI ,
312+ }
313+ }
314+
279315const templateHitsToResult = ( hits ) => ( {
280- totalHits : hits . total . value ,
281- results : hits . hits . map ( ( row ) => row . _source ) ,
316+ totalHits : hits . length ,
317+ results : hits . map ( ( row ) => templateModFromBlueCore ( row ) ) ,
282318} )
283319
284320const templateLookupToResult = ( hits ) => ( {
0 commit comments