Skip to content

Commit

Permalink
fix: fixes distance function usage for high precision geosearch (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva authored Oct 29, 2023
1 parent 67f398b commit e31b81e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 51 deletions.
88 changes: 44 additions & 44 deletions packages/docs/public/sitemap-0.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://docs.oramasearch.com</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/csv-file</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/json-file</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/rest-api</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/webhooks</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/native-integrations/docusaurus</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/native-integrations/introduction</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/native-integrations/shopify</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/indexes/create-a-new-index</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/indexes/delete-an-index</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/indexes/edit-an-existing-index</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/integrating-orama-cloud/javascript-sdk</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/understanding-orama</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/understanding-orama/indexes</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/internals/components</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/internals/utilities</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-astro</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-data-persistence</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-docusaurus</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-match-highlight</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-nextra</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-parsedoc</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/text-analysis/stemming</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/text-analysis/stop-words</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/create</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/insert</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/remove</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/BM25-algorithm</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/facets</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/fields-boosting</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/filters</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/geosearch</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/grouping</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/introduction</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/preflight</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/sorting</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/threshold</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/vector-search</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/typescript</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/update</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/utilities</loc><lastmod>2023-10-29T16:49:08.128Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/csv-file</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/json-file</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/rest-api</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/custom/webhooks</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/native-integrations/docusaurus</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/native-integrations/introduction</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/data-sources/native-integrations/shopify</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/indexes/create-a-new-index</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/indexes/delete-an-index</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/indexes/edit-an-existing-index</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/integrating-orama-cloud/javascript-sdk</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/understanding-orama</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/cloud/understanding-orama/indexes</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/internals/components</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/internals/utilities</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-astro</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-data-persistence</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-docusaurus</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-match-highlight</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-nextra</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/plugins/plugin-parsedoc</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/text-analysis/stemming</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/text-analysis/stop-words</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/create</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/insert</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/remove</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/BM25-algorithm</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/facets</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/fields-boosting</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/filters</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/geosearch</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/grouping</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/introduction</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/preflight</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/sorting</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/threshold</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/search/vector-search</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/typescript</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/update</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://docs.oramasearch.com/open-source/usage/utilities</loc><lastmod>2023-10-29T17:06:45.505Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
</urlset>
9 changes: 4 additions & 5 deletions packages/orama/src/trees/bkd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ export function searchByRadius (
sort: SortGeoPoints = 'asc',
highPrecision = false
): GeoSearchResult[] {
const distanceFn = highPrecision ? vincentyDistance : haversineDistance
const stack: Array<{ node: Nullable<Node>, depth: number }> = [{ node, depth: 0 }]
const result: GeoSearchResult[] = []

while (stack.length > 0) {
const { node, depth } = stack.pop() as { node: Node, depth: number }
if (node === null) continue

const dist = haversineDistance(center, node.point)
const dist = distanceFn(center, node.point)

if (inclusive ? dist <= radius : dist > radius) {
result.push({ point: node.point, docIDs: node.docIDs ?? [] })
Expand All @@ -251,11 +252,9 @@ export function searchByRadius (
}

if (sort) {
const sortFn = highPrecision ? vincentyDistance : haversineDistance

result.sort((a, b) => {
const distA = sortFn(center, a.point)
const distB = sortFn(center, b.point)
const distA = distanceFn(center, a.point)
const distB = distanceFn(center, b.point)
return sort.toLowerCase() === 'asc' ? distA - distB : distB - distA
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/orama/tests/search.geo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ t.test('geosearch', t => {

t.same(polygonResults.count, 5)
t.same(polygonResults.hits.map(({ id }) => id), ['1', '2', '3', '4', '5'])
t.same(radiusResults.count, 2)
t.same(radiusResults.hits.map(({ id }) => id), ['1', '2'])
t.same(radiusResults.count, 1)
t.same(radiusResults.hits.map(({ id }) => id), ['1'])
})
})

1 comment on commit e31b81e

@vercel
Copy link

@vercel vercel bot commented on e31b81e Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.