Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geosearch default sorting (asc) it's not handled during data loading #547

Open
DavideArena opened this issue Nov 11, 2023 · 3 comments
Open

Comments

@DavideArena
Copy link

DavideArena commented Nov 11, 2023

Describe the bug

Hello, i was trying the geosearch feature of Orama (and it's awesome!) and i was searching how the sorting systems works in this scenario. At first point, seems like there's no sorting, and sorting of data retrieved depends on documents sort inside database (first inserted will be put as first result, second inserted as second result and so on...).

I started to investigate inside code, and i found here (searchByRadius function) a default sorting. So i didn't understand why results don't maintain this sorting.

I figured out the problem, it is the scoring associated with the result. When you use the location search system, and you don't specify other terms, the scoring system assign default 0 value to records, and then the score sorting lose the default sorting made initially by the searchByRadius function.

I don't know if one possible way could be to attach the distance calculated by geosearch feature as score of docs, and use that as sorting parameter.

To Reproduce

  1. Init db with following schema:

{ entityId: 'string', location: 'geopoint' }

  1. Put three elements inside
insert(db, {
      entityId: 'entityFar',
      location: {
        lat: 43.773034,
        lon: 11.252929,
      },
    })
insert(db, {
      entityId: 'entityNear',
      location: {
        lat: 43.772974,
        lon: 11.25428,
      },
    })
insert(db, {
      entityId: 'entityVeryFar',
      location: {
        lat:  43.773404,
        lon: 11.252167,
      },
    })
  1. Search with geoseach
  await search(db, {
    where: {
      location: {
        radius: {
          coordinates: {
            lat: 43.773081,
            lon: 11.255533,
          },
          unit: 'm',
          value: 3000,
          inside: true,
        },
      },
    },
  });

Expected behavior

Expected

{
   "elapsed":{
      "raw":4898041,
      "formatted":"4ms"
   },
   "hits":[
      {
         "id":"21819145-3",
         "score":0,
         "document":{
            "entityId":"EntityNear",
            "location":{
               "lat":43.772974,
               "lon":11.25428
            }
         }
      },
      {
         "id":"21819145-2",
         "score":0,
         "document":{
            "entityId":"entityFar",
            "location":{
               "lat":43.773034,
               "lon":11.252929
            }
         }
      },
      {
         "id":"21819145-4",
         "score":0,
         "document":{
            "entityId":"entityVeryFar",
            "location":{
               "lat":43.773404,
               "lon":11.252167
            }
         }
      }
   ],
   "count":3
}

Got

{
   "elapsed":{
      "raw":4898041,
      "formatted":"4ms"
   },
   "hits":[
      {
         "id":"21819145-2",
         "score":0,
         "document":{
            "entityId":"entityFar",
            "location":{
               "lat":43.773034,
               "lon":11.252929
            }
         }
      },
      {
         "id":"21819145-3",
         "score":0,
         "document":{
            "entityId":"EntityNear",
            "location":{
               "lat":43.772974,
               "lon":11.25428
            }
         }
      },
      {
         "id":"21819145-4",
         "score":0,
         "document":{
            "entityId":"entityVeryFar",
            "location":{
               "lat":43.773404,
               "lon":11.252167
            }
         }
      }
   ],
   "count":3
}

Environment Info

OS: MacOS Ventura 13.1
Node: 18.14.1
Orama version: 2.0.0-beta.5

Affected areas

Search

Additional context

No response

@debiff
Copy link

debiff commented Dec 19, 2023

@micheleriva do you think this is a bug that is worth to be explored? If yes, I'd like to try!

@micheleriva
Copy link
Member

@debiff go ahead :)

@debiff
Copy link

debiff commented Dec 19, 2023

Quick question: is it correct that by applying filters (with where) we expect and ideally obtain the documents sorted? There is a reason why is not used the sortBy parameter? As a user, it seems to me more intuitive and less misleading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants