-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autocomplete): focus point distance filter
This change uses an extra filter clause that takes into account a focus point (if used) and the input text length to filter out very far away street and adress records, improving performance. Replaces #1215
- Loading branch information
1 parent
6c5db8d
commit 17e2275
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const _ = require('lodash'); | ||
|
||
const config = require('pelias-config'); | ||
const type_mapping = require('../../helper/type_mapping'); | ||
|
||
module.exports = function( vs ) { | ||
|
||
if ( !vs.isset('input:name') || | ||
!vs.isset('centroid:field') || | ||
!vs.isset('focus:point:lat') || | ||
!vs.isset('focus:point:lon') ) { | ||
return null; | ||
} | ||
|
||
const text_length = vs.var('input:name').get().length; | ||
|
||
if (text_length > 8) { | ||
return null; | ||
} | ||
|
||
const all_layers_except_address_and_street = _.without(type_mapping.layers, 'address', 'street'); | ||
|
||
const length_to_distance_mapping = { | ||
1: '100km', | ||
2: '200km', | ||
3: '400km', | ||
4: '600km', | ||
5: '900km', | ||
6: '1200km', | ||
7: '1600km', | ||
8: '2000km' | ||
}; | ||
|
||
const query = { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: [{ | ||
terms: { | ||
layer: all_layers_except_address_and_street | ||
} | ||
},{ | ||
geo_distance: { | ||
distance: length_to_distance_mapping[text_length], | ||
distance_type: 'plane', | ||
[vs.var('centroid:field')]: { | ||
lat: vs.var('focus:point:lat'), | ||
lon: vs.var('focus:point:lon') | ||
} | ||
} | ||
}] | ||
} | ||
}; | ||
|
||
return query; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters