@@ -2,8 +2,11 @@ import { SearchContext, GeoSearchContext } from '../../types'
22import { getDistanceInMeter , middleGeoPoints } from '../../utils/geographic'
33
44export function adaptGeoPointsRules (
5- geoSearchContext : GeoSearchContext
5+ geoSearchContext ? : GeoSearchContext
66) : { filter ?: string ; sort ?: string } | undefined {
7+ if ( ! geoSearchContext ) {
8+ return undefined
9+ }
710 const {
811 insideBoundingBox,
912 aroundLatLng,
@@ -17,8 +20,9 @@ export function adaptGeoPointsRules(
1720 if ( aroundLatLng ) {
1821 middlePoint = aroundLatLng
1922 }
20- if ( aroundRadius || minimumAroundRadius ) {
21- radius = aroundRadius
23+ if ( aroundRadius != null || minimumAroundRadius != null ) {
24+ if ( aroundRadius != null ) radius = aroundRadius
25+ else radius = minimumAroundRadius
2226 }
2327
2428 // If insideBoundingBox is provided it takes precedent over all other options
@@ -35,7 +39,7 @@ export function adaptGeoPointsRules(
3539 middlePoint = middleGeoPoints ( lat1 , lng1 , lat2 , lng2 )
3640 }
3741
38- if ( middlePoint && radius ) {
42+ if ( middlePoint != null && radius != null ) {
3943 const [ lat3 , lng3 ] = middlePoint . split ( ',' )
4044
4145 // check if radius is big enough
@@ -44,7 +48,7 @@ export function adaptGeoPointsRules(
4448 const sort = `_geoPoint(${ lat3 } , ${ lng3 } ):asc`
4549
4650 return { filter, sort }
47- } else if ( middlePoint ) {
51+ } else if ( middlePoint != null ) {
4852 const [ lat3 , lng3 ] = middlePoint . split ( ',' )
4953 const sort = `_geoPoint(${ lat3 } , ${ lng3 } ):asc`
5054 return { sort }
@@ -67,7 +71,6 @@ export function createGeoSearchContext(
6771 } = searchContext
6872
6973 if ( aroundLatLng ) {
70- // only filter
7174 geoContext . aroundLatLng = aroundLatLng
7275 }
7376
@@ -84,7 +87,7 @@ export function createGeoSearchContext(
8487 See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264` )
8588 }
8689
87- if ( minimumAroundRadius && aroundLatLng ) {
90+ if ( minimumAroundRadius ) {
8891 geoContext . minimumAroundRadius = minimumAroundRadius
8992 }
9093
@@ -93,7 +96,9 @@ export function createGeoSearchContext(
9396 }
9497 // TODO: issue
9598 if ( insidePolygon ) {
96- geoContext . insidePolygon = insidePolygon
99+ console . warn (
100+ `instant-meilisearch: \`insidePolygon\` is not implented in instant-meilisearch.`
101+ )
97102 }
98103 return geoContext
99104}
0 commit comments