Search: move limit responsability to the constructor, merge similar results

This commit is contained in:
Pieter Vander Vennet 2024-08-27 23:56:54 +02:00
parent cdc1e05499
commit 6468e33d66
7 changed files with 62 additions and 23 deletions

View file

@ -95,8 +95,8 @@ export default class LocalElementSearch implements GeocodingProvider {
const listed: Store<IntermediateResult[]> = Stores.concat(partials).map(l => l.flatMap(x => x))
return listed.mapD(results => {
results.sort((a, b) => (a.physicalDistance + a.levehnsteinD * 25) - (b.physicalDistance + b.levehnsteinD * 25))
if (this._limit || options?.limit) {
results = results.slice(0, Math.min(this._limit ?? options?.limit, options?.limit ?? this._limit))
if (this._limit) {
results = results.slice(0, this._limit)
}
return results.map(entry => {
const [osm_type, osm_id] = entry.feature.properties.id.split("/")