@findlane/browser

中文文档
0.34.0发布于 2026/11/06MITTypeScriptES Module零依赖近 30 天下载 4751

Findlane browser SDK: fast, typo-tolerant public search from the browser with an index's public ID, plus React hooks and components.

原始使用文档
文档目录9 节
  1. Install
  2. Quick start
  3. Query suggestions
  4. React
  5. Search requests
  6. Events
  7. Security
  8. Errors
  9. License

@findlane/browser

The Findlane browser SDK: fast, typo-tolerant search from the browser with an index's public ID. No dependencies, about 1 KB, plus optional React hooks and components.

Docs: https://findlane.dev/docs/browser-sdk

Install

npm install @findlane/browser

Quick start

import { SearchBrowserClient } from "@findlane/browser"

const client = new SearchBrowserClient({ publicId: "pub_your_public_index_id" })
const results = await client.search({ q: "trail shoe", limit: 10, highlight: true })
// results.hits[0].highlights?.title: "Trail <mark>shoe</mark>" (HTML-escaped, safe to insert as HTML)

Without a build step, load it with a script tag, which defines a global Findlane:

<script src="https://cdn.findlane.dev/browser/0/findlane.min.js"></script>
<script>
  const client = new Findlane.SearchBrowserClient({ publicId: "pub_your_public_id" })
</script>

Each index has a copyable public ID in the dashboard. An owner must save allowed origins for the index before browser search is enabled.

Query suggestions

Whole searches to offer as visitors type, and the index's popular searches for an empty box. They don't count as searches. Recent searches stay in the visitor's browser.

await client.querySuggestions({ q: "hrek" }) // [{ q: "hrekkjavöku búningar", typed: [0, 4] }]
await client.popularSearches() // [{ q: "gríma" }, { q: "latex" }]
client.recentSearches.add("hárkolla")

React

@findlane/browser/react has a search box that suggests searches and results as visitors type, a results page with filters, and the hooks behind them, for React 18.2 and 19. Pages that don't import it don't load it.

import { SearchBox } from "@findlane/browser/react"
import "@findlane/browser/react/styles.css" // optional

<SearchBox publicId="pub_your_public_id" getHref={(hit) => hit.record.url} action="/search"
  querySuggestions={4} popularSearches={6} recentSearches />

SearchDialog is the same search box in a dialog that ⌘K opens, as on docs sites. A results page shares its state through SearchProvider, with RefinementList, SortSelect, Hits, LoadMore, and hooks such as useRefinementList and useRange for your own markup. With routing, the search is kept in the URL. @findlane/browser/react/ssr renders the first results on the server. On a product page, useProductView(objectID), or <ProductView> in a server component, sends the page's view for the index's Events page. Docs: https://findlane.dev/docs/react

Search requests

Option
qThe query. Words match with typos and as prefixes, depending on the index's settings.
filtersField values to keep: a value, { in: [...] }, or a range { gte, lte } for numbers and dates.
facetsFields to count values for, such as ["brand.name"].
disjunctiveFacetsFacets counted without the filter on their own field, so a list of checkboxes keeps its other values.
sortA sort ID from the index settings, or "relevance".
limit, offsetPaging: up to 50 hits a request, and offsets up to 1,000.
countMode, facetMode"page" (the default, fastest) or "exact" for totals and facet counts across every match.
highlighttrue to wrap matched words in <mark>, or { preTag, postTag }.
attributesToRetrieveReturn only these fields.

A response has hits (each with its record and any highlights), total, facets, and tookMs. Pass { signal } as a second argument to cancel a request, as search-as-you-type should.

Events

client.events sends views, clicks, add-to-carts and orders in the background, for the index's Events page and Bought together. With visitorIds: true, they also carry random IDs for the browser and the visit, when the index takes them, and client.events.forget() deletes the IDs and asks for their events to be deleted. Docs: https://findlane.dev/docs/events

Security

The public ID grants search access only to its index, and it is visible in browser source. By default the API returns every uploaded record field. attributesToRetrieve requests fewer fields for speed, but it does not make the others private. Origin checks constrain browsers; they do not authenticate other callers. Keep public catalog fields safe to expose. The dashboard can remove origins, add server-enforced restrictions, or rotate the ID.

For logged-in people, pass signedKey: a short-lived key your server signs with the server SDK's signSearchKey, or a function that fetches one. Its restrictions replace the index's public settings. See Logged-in visitors.

Errors

Failed requests throw a FindlaneError with the HTTP status and the API's message:

  • 403: this origin isn't allowed.
  • 429: the public search rate limit.
  • 402: the workspace has used its monthly searches.

License

MIT

版本与发布记录

@findlane/browser 共发布 39 个版本,首次发布于 2026/09/30;过去 12 个月发布了 39 个版本。

版本发布日期距今
0.34.0latest2026/11/068 天前
0.33.02026/11/059 天前
0.32.02026/11/059 天前
0.31.02026/11/059 天前
0.30.02026/11/0410 天前
0.29.02026/11/0410 天前

关于 @findlane/browser 的常见问题

@findlane/browser 是什么?

Findlane browser SDK: fast, typo-tolerant public search from the browser with an index's public ID, plus React hooks and components.

如何安装 @findlane/browser?

在项目目录运行 npm install @findlane/browser,或使用 pnpm add / yarn add / bun add。

@findlane/browser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@findlane/browser 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@findlane/browser 可以商用吗?

@findlane/browser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@findlane/browser 的下载量有多少?

根据 npm 官方下载统计,@findlane/browser 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,751 次,日均约 158 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@findlane/browser 还在维护吗?

最新版本 0.34.0 发布于 2026/11/06(8 天前);至今共发布 39 个版本,其中过去 12 个月发布了 39 个;首次发布于 2026/09/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。