MrDSAM
Convex Community5mo ago
1 reply
MrDSA

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;
  },
});


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;
  },
});
Was this page helpful?