-
-
Notifications
You must be signed in to change notification settings - Fork 299
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
Comments
@micheleriva do you think this is a bug that is worth to be explored? If yes, I'd like to try! |
@debiff go ahead :) |
Quick question: is it correct that by applying filters (with |
@debiff thank you for the tip. I've tried as described here (https://docs.orama.com/open-source/usage/search/sorting#custom-sort) with a custom sorting, using the score as sorting value. Seems working! I didn't expect it will work because on result points i got all docs with score 0 (but maybe during the search the score has a value). Using const db = create({
schema: {
entityId: "string",
location: "geopoint",
},
});
insert(db, {
entityId: "entityVeryVeryFar",
location: {
lat: 44.773404,
lon: 12.252167,
},
});
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,
},
});
const points = await search(db, {
where: {
location: {
radius: {
coordinates: {
lat: 43.773081,
lon: 11.255533,
},
unit: "m",
value: 1000000,
inside: true,
},
},
},
sortBy: (a, b) => {
// Sorting by score
return a[1] - b[1];
},
});
console.log(JSON.stringify(points, null, 2)); Result {
"elapsed": {
"raw": 468208,
"formatted": "468μs"
},
"hits": [
{
"id": "16635519-3",
"score": 0,
"document": {
"entityId": "entityNear",
"location": {
"lat": 43.772974,
"lon": 11.25428
}
}
},
{
"id": "16635519-2",
"score": 0,
"document": {
"entityId": "entityFar",
"location": {
"lat": 43.773034,
"lon": 11.252929
}
}
},
{
"id": "16635519-4",
"score": 0,
"document": {
"entityId": "entityVeryFar",
"location": {
"lat": 43.773404,
"lon": 11.252167
}
}
},
{
"id": "16635519-1",
"score": 0,
"document": {
"entityId": "entityVeryVeryFar",
"location": {
"lat": 44.773404,
"lon": 12.252167
}
}
}
],
"count": 4
} Probabily what i was expecting was that this behaviour was the default out of the box, but probably the sort has an effort and it's correct to be applied only if needed. Dunno at this point if this issue should be opened. |
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
{ entityId: 'string', location: 'geopoint' }
Expected behavior
Expected
Got
Environment Info
Affected areas
Search
Additional context
No response
The text was updated successfully, but these errors were encountered: