搜索插件、代码仓与 APP 分类

插件详情v0.19.0

meilisearch

Meilisearch Dart 是 Dart 和 Flutter 开发人员的 Meilisearch API 客户端。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
4240
喜欢数
65
Pub 分数
140

安装插件

flutter pub add meilisearch

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Meilisearch Dart 是一个轻量级的 API 客户端,适用于 Dart 和 Flutter 应用程序,可实现与 Meilisearch(一种快速、相关且可自定义的搜索引擎)的无缝集成。它允许开发者在应用程序中直接执行实时搜索、管理索引和处理文档更新。该客户端支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,非常适合跨平台搜索功能。通过直观的方法和最少的设置,它简化了为任何 Flutter 项目添加强大搜索功能的过程。

适合场景

  • 移动应用中的实时搜索
  • Flutter 中的索引管理
  • 跨多个平台的全文搜索
  • 搜索建议和自动完成
  • 文档索引和更新
  • 跨平台搜索实现

主要特点

  • 搜索操作的简单 API
  • 支持所有主要平台
  • 实时搜索结果
  • 轻松的索引和文档处理
  • 轻便且快速
  • 内置错误处理

适合对象

  • 需要搜索功能的Flutter开发人员
  • 需要快速全文搜索的应用
  • 针对多个平台的项目
  • 使用 Meilisearch 后端的团队
  • 希望实现低延迟搜索的开发者

使用建议

  • 需要一个正在运行的 Meilisearch 服务器
  • 需要适当的 API 密钥管理
  • 仅限 Meilisearch 后端
  • 搜索查询的网络依赖
  • 不适用于仅离线搜索

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Meilisearch

Meilisearch Dart

Meilisearch | Meilisearch Cloud | Documentation | Discord | Roadmap | Website | FAQ

Pub Version GitHub Workflow Status License Code Coverage

⚡ The Meilisearch API client written in Dart

Meilisearch Dart is the Meilisearch API client for Dart and Flutter developers.

Meilisearch is an open-source search engine. Learn more about Meilisearch.

Table of Contents

📖 Documentation

This readme contains all the documentation you need to start using this Meilisearch SDK.

For general information on how to use Meilisearch—such as our API reference, tutorials, guides, and in-depth articles—refer to our main documentation website.

🔧 Installation

You can install the meilisearch package by adding a few lines into pubspec.yaml file.

dependencies:
  meilisearch: ^0.19.0

Then open your terminal and update dart packages.

pub get
Run Meilisearch

⚡️ Launch, scale, and streamline in minutes with Meilisearch Cloud—no maintenance, no commitment, cancel anytime. Try it free now.

🪨 Prefer to self-host? Download and deploy our fast, open-source search engine on your own infrastructure.

🚀 Getting started

Add Documents
import 'package:meilisearch/meilisearch.dart';

void main() async {
  var client = MeiliSearchClient('http://127.0.0.1:7700', 'masterKey');

  // An index is where the documents are stored.
  var index = client.index('movies');

  const documents = [
    { 'id': 1, 'title': 'Carol', 'genres': ['Romance', 'Drama'] },
    { 'id': 2, 'title': 'Wonder Woman', 'genres': ['Action', 'Adventure'] },
    { 'id': 3, 'title': 'Life of Pi', 'genres': ['Adventure', 'Drama'] },
    { 'id': 4, 'title': 'Mad Max: Fury Road', 'genres': ['Adventure', 'Science Fiction'] },
    { 'id': 5, 'title': 'Moana', 'genres': ['Fantasy', 'Action']},
    { 'id': 6, 'title': 'Philadelphia', 'genres': ['Drama'] },
  ]

  // If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
  var task = await index.addDocuments(documents); // => { "uid": 0 }
}

With the uid, you can check the status (enqueued, canceled, processing, succeeded or failed) of your documents addition using the task.

Basic Search
// Meilisearch is typo-tolerant:
var result = await index.search('carlo');

print(result.hits);

JSON Output:

[
  {
    "id": 1,
    "title": "Carol",
    "genres": ["Romance", "Drama"]
  }
]
Custom Search

All the supported options are described in the search parameters section of the documentation.

var result = await index.search(
  'carol',
  attributesToHighlight: ['title'],
);

JSON output:

{
    "hits": [
        {
            "id": 1,
            "title": "Carol",
            "_formatted": {
                "id": 1,
                "title": "<em>Carol</em>"
            }
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 0,
    "query": "carol"
}
Custom Search With Filters

If you want to enable filtering, you must add your attributes to the filterableAttributes index setting.

await index.updateFilterableAttributes(['id', 'genres']);

You only need to perform this operation once.

Note that MeiliSearch will rebuild your index whenever you update filterableAttributes. Depending on the size of your dataset, this might take time. You can track the process using the task status.

Then, you can perform the search:

await index.search('wonder', filter: ['id > 1 AND genres = Action']);
{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action","Adventure"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "estimatedTotalHits": 1,
  "processingTimeMs": 0,
  "query": "wonder"
}

Advanced Configuration

Customizing the dio instance

Meilisearch uses dio internally to send requests, you can provide it with your own interceptors or adapter using the MeiliSearchClient.withCustomDio constructor.

Using MeiliDocumentContainer

The MeiliDocumentContainer<T> class contains meilisearch-specific fields (e.g. rankingScoreDetails, _formatted, matchesPosition, etc...).

We define the mapToContainer() extension to help you quickly opt-in to this class, example:

final res = await index
      .search("hello world")
      .asSearchResult() //or .asPaginatedResult() if using page parameters
      .mapToContainer();

🤖 Compatibility with Meilisearch

This package guarantees compatibility with version v1.x of Meilisearch, but some features may not be present. Please check the issues for more info.

💡 Learn more

The following sections in our main documentation website may interest you:

⚙️ Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!


Meilisearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目