typesense / typesense-ruby

Ruby client for Typesense: https://github.com/typesense/typesense
Apache License 2.0
75 stars 8 forks source link

Specify the user id that made the request #31

Closed sunny closed 8 months ago

sunny commented 9 months ago

Description

We should be able to tell which user has triggered a search query, following the documentation:

When you send a search query to the source collection, you can optionally send a x-typesense-user-id parameter or a X-TYPESENSE-USER-ID header to indicate the user who made this particular search request. When not specified, Typesense uses the client IP address for aggregation by default.

Analytics Query Suggestions — Typesense 0.25.2 Documentation

Expected Behavior

We should be able to pass along a user id that is then added as a header.

Perhaps this could be an extra argument to search? E.g.:

typesense.collections["books"].documents.search(
  q: "hunger",
  query_by: "title",
  sort_by: "ratings_count:desc",
  headers: {"x-typesense-user-id" => 42}
)

Metadata

Typesense Version: 0.25.2

jasonbosco commented 9 months ago

You should be able to do this already:

typesense.collections["books"].documents.search(
  q: "hunger",
  query_by: "title",
  sort_by: "ratings_count:desc",
  'x-typesense-user-id': 42
)

Since x-typesense-user-id is also accepted as a query parameter

sunny commented 8 months ago

Thank you @jasonbosco!