Skip to content
Snippets Groups Projects
Commit c4811fb2 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat: add address search for structure registration

parent b09c65d4
Branches
Tags
3 merge requests!27Recette,!26Dev,!18Feat/address search
......@@ -63,6 +63,11 @@ export class StructuresController {
return data.reduce((a, b) => [...a, ...b]);
}
@Post('address')
public async searchAddress(@Body() data: { searchQuery: string }) {
return await this.structureService.searchAddress(data);
}
@Get(':id')
public async find(@Param('id') id: number) {
return this.structureService.findOne(id);
......
......@@ -125,6 +125,64 @@ export class StructuresService {
return false;
}
/**
* Search structure address based on data search WS
*/
public async searchAddress(data: { searchQuery: string }): Promise<AxiosResponse<any>> {
const req = 'https://data.grandlyon.com/api/elasticsearch/_search';
const queryString = data.searchQuery.replace(/\s/g, ' AND ');
const params = {
from: 0,
size: 30,
_source: ['data-fr'],
query: {
bool: {
filter: {
term: {
'metadata-fr.geonet:info.uuid.keyword': '4cb035de-6ac3-4763-94d8-4c19b1d19607',
},
},
must: [
{
query_string: {
query: queryString,
default_field: '*',
analyzer: 'my_search_analyzer',
fuzziness: 'AUTO',
minimum_should_match: '90%',
},
},
],
},
},
sort: [
{
'data-fr.properties.commune_str.sort': {
order: 'asc',
unmapped_type: 'string',
},
},
],
};
return new Promise((resolve, reject) => {
this.httpService
.request({
url: req,
method: 'GET',
headers: { 'Content-Type': 'application/json' },
data: params,
})
.subscribe(
(reply) => {
return resolve(reply.data);
},
(err) => {
Logger.error(`Request error: ${err.config.url}`, 'StructureService - search');
}
);
});
}
/**
* Count every value occurence of a given key
* @param key structure key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment