-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Implements Geosearch #505
Implements Geosearch #505
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@H4ad thanks a lot for the early review, I'm still writing/refactoring most of the code, so it's expected to see things that are not super optimized yet 🙏 I'll make sure to ask you for a review as soon as the PR is ready :) |
Just a little comment about a micro-optimization, probably using a tuple will use less memory than having an object to store |
Yes I'm using an object during development as the property names helps me read the code easily! |
My idea for DX: import { create, insert } from '@orama/orama'
const db = await create({
schema: {
name: 'string',
city: 'string',
center: 'geopoint[2]' // 2 dim points
},
})
// https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.2
await insert(db, {
name: 'Duomo',
city: 'Milan',
// https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1
center: [9.191383, 45.464211]
})
const resultsByRadius = await search(db, {
term: 'Duomo',
where {
center: {
byRadius: {
center: [11.012345, 42.012345],
radius: {
unit: 'km',
value: 100
},
keep: 'inner', // or 'outer'
}
}
})
const resultsByPolygon = await search(db, {
term: 'Duomo',
where {
center: {
byPolygon: {
coordinates: [ [11.019283, 42.019283], [11.0192839, 42.019283 ], ...],
keep: 'inner', // or 'outer'
}
}
}) I prefer to use:
|
@allevo I reviewed your comment, I'd propose a compromise between your proposal and mine.
The API might look like this: import { search, create, insert } from '@orama/orama'
const db = await create({
name: 'string',
coordinates: 'geopoint'
})
await insert(db, {...})
await insert(db, {...})
await insert(db, {...})
await search(db, {
term: 'duomo',
where: {
geo: {
radius: {
coordinates: [11.012345, 42.012345],
unit: 'km', // defaults to 'm'
value: 100,
inside: false // optional, default is true
}
}
}
})
await search(db, {
term: 'duomo',
where: {
geo: {
polygon: {
coordinates: [ [11.019283, 42.019283], [11.0192839, 42.019283 ], ...],
unit: 'km', // defaults to 'm'
value: 100,
inside: false // optional, default is true
}
}
}
}) That way we could reuse most of the code for polygon and radius search. What do you think? |
Another challenge.
So something like import { search, create, insert } from '@orama/orama'
const db = await create({
name: 'string',
position: 'geopoint[2]'
})
await insert(db, {...})
await insert(db, {...})
await insert(db, {...})
await search(db, {
term: 'duomo',
where: {
position: { // the name of the property
radius: {
coordinates: { lon: 11.012345, lat: 42.012345 },
unit: 'km',
value: 100,
inside: false // optional, default is true
}
}
}
})
await search(db, {
term: 'duomo',
where: {
position: { // the name of the property
polygon: {
coordinates: [ { lon: 11.019283, lat: 42.019283 }, { lon: 11.0192839, lat: 42.019283 }, ...],
unit: 'km',
value: 100,
inside: false // optional, default is true
}
}
}
}) |
@allevo looks almost good to me. I just don't like the I agree with coordinates ordering, but internally, we will always store them as tuples to save some space (especially when serializing the db). I think I'll start implementing the last API design you shared, then it will be easy to find a compromise on the |
reqOperation = 'polygon' | ||
} else { | ||
throw new Error(`Invalid operation ${operation}`) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the search for both operations is not yet supported. We should throw an error.
radius: { | ||
coordinates: Point, | ||
value: number, | ||
unit?: GeosearchDistanceUnit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to use a default here.
Co-authored-by: Vinicius Lourenço <12551007+H4ad@users.noreply.github.com>
This PR aims to implement geolocation-based search (as requested in #212).
The initial design for the APIs is the following: