Skip to content
Snippets Groups Projects
Commit 115ab1d1 authored by Antonin COQUET's avatar Antonin COQUET
Browse files

fix: update search of ES and max score to optimize

parent 92e20be4
No related branches found
No related tags found
3 merge requests!96release V1.10.0,!83Dev,!80Fix/elasticsearch optimize
......@@ -4,6 +4,7 @@ export interface StructureSearchResult {
hits: {
total: number;
hits: Array<{
_score: number;
_source: StructureSearchBody;
}>;
};
......
......@@ -4,6 +4,7 @@ import { structureDto } from '../dto/structure.dto';
import { StructureDocument } from '../schemas/structure.schema';
import { StructureSearchBody } from '../interfaces/structure-search-body.interface';
import { StructureSearchResult } from '../interfaces/structure-search-response.interface';
import { elementAt } from 'rxjs/operators';
@Injectable()
export class StructuresSearchService {
......@@ -65,14 +66,22 @@ export class StructuresSearchService {
query_string: {
analyze_wildcard: 'true',
query: searchString,
fields: ['structureName^5', 'structureType^5', 'address.street', 'address.commune^5', 'description'],
fields: ['structureName^5', 'structureType^5', 'address.commune^10', 'description'],
fuzziness: 'AUTO',
},
},
},
});
const hits = body.hits.hits;
return hits.map((item) => item._source);
const maxScore = Math.max.apply(
Math,
body.hits.hits.map(function (hit) {
return hit._score;
})
);
const sortedHits = body.hits.hits.filter(function (elem) {
return elem._score >= maxScore / 1.5;
});
return sortedHits.map((item) => item._source);
}
public async update(structure: structureDto, id: string): Promise<any> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment