MrDSA
MrDSA3d ago

Geospatial

I've seen the geo spatial lib for convex but am unable to use it as i need to filter the results with full text search too, my current code is
export const searchBookswithLocation = query({
args: {
searchTerm: v.string(),
latitude: v.number(),
longitude: v.number(),
},
handler: async (ctx, args) => {
const maxResults = 16;
const maxDistance = 10000;
const result = await geospatial.queryNearest(
ctx,
{ latitude: args.latitude, longitude: args.longitude },
maxResults,
maxDistance,
)
;
return result;
},
});
export const searchBookswithLocation = query({
args: {
searchTerm: v.string(),
latitude: v.number(),
longitude: v.number(),
},
handler: async (ctx, args) => {
const maxResults = 16;
const maxDistance = 10000;
const result = await geospatial.queryNearest(
ctx,
{ latitude: args.latitude, longitude: args.longitude },
maxResults,
maxDistance,
)
;
return result;
},
});
would like to use this with a search index or even just filter it down, have something like this
export const searchBooks = query({
args: {
searchTerm: v.string(),
},
handler: async (ctx, args) => {
const maxDistanceMeter = 10;
const books = await ctx.db
.query("books")
.withSearchIndex("bookSearch", (q) =>
q.search("searchString", args.searchTerm).eq("status", "Available"),
)

.take(10);
return books;
},
});
export const searchBooks = query({
args: {
searchTerm: v.string(),
},
handler: async (ctx, args) => {
const maxDistanceMeter = 10;
const books = await ctx.db
.query("books")
.withSearchIndex("bookSearch", (q) =>
q.search("searchString", args.searchTerm).eq("status", "Available"),
)

.take(10);
return books;
},
});
1 Reply
Convex Bot
Convex Bot3d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!

Did you find this page helpful?