Skip to content

Filter down the results #17

@imdewan

Description

@imdewan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions