 RAISE DEBUG 'version : %', (SELECT frapi_result -> 'version');
 
 
-RETURN QUERY SELECT * FROM frapi.ban_search_format(frapi_result);
+RETURN QUERY SELECT * FROM frapi.adresse_search_format(frapi_result);
 
 END
 $BODY$

    geom geometry(Point,4326)
);

CREATE OR REPLACE FUNCTION frapi.ban_search_format(raw_result jsonb)
  RETURNS SETOF frapi.ban_search AS
$BODY$
WITH result_array as (SELECT jsonb_array_elements_text( raw_result -> 'features')::jsonb f )

SELECT
(f #>> '{properties,id}')::text as ban_id,
(f #>> '{properties,type}')::text as ban_type,
(f #>> '{properties,score}')::numeric as ban_score,
(f #>> '{properties,housenumber}')::text as ban_housenumber,
(f #>> '{properties,name}')::text as ban_name,
(f #>> '{properties,postcode}')::text as ban_postcode,
(f #>> '{properties,citycode}')::text as ban_citycode,
(f #>> '{properties,city}')::text as ban_city,
(f #>> '{properties,context}')::text as ban_context,
(f #>> '{properties,label}')::text as ban_label,
ST_SetSRID(ST_GeomFromGeoJSON((f->'geometry')::text),4326)::geometry(Point,4326) as ban_geom
FROM result_array;
$BODY$
LANGUAGE sql VOLATILE
  COST 120;

-- Function: frapi.ban_search(text, integer, boolean, numeric, numeric, text, text, text)

-- DROP FUNCTION frapi.ban_search(text, integer, boolean, numeric, numeric, text, text, text);

CREATE OR REPLACE FUNCTION frapi.ban_search(q text, "limit" integer DEFAULT 1, autocomplete boolean DEFAULT true, lon numeric DEFAULT NULL::numeric, lat numeric DEFAULT NULL::numeric, type text DEFAULT NULL::text, postcode text DEFAULT NULL::text, citycode text DEFAULT NULL::text)
RETURNS SETOF frapi.ban_search AS
$BODY$
DECLARE
frapi_query text;

$BODY$
LANGUAGE plsh VOLATILE;

CREATE TYPE frapi.adresse_search AS
   (id text,
    type text,
    score numeric,
