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

插件详情v2.0.0

autotrie

一个基于优化的 Trie 实现的 Dart/Flutter 自动补全引擎。

AndroidiOSmacOSWindowsLinux
近 30 天下载
3.8万
喜欢数
42
Pub 分数
150

安装插件

flutter pub add autotrie

插件介绍

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

AutoTrie 是一个为 Dart 和 Flutter 应用程序构建的高性能自动补全引擎,基于优化的 Trie 数据结构。它高效支持快速的前缀搜索,非常适合实时文本输入、搜索栏和代码编辑器中的建议功能。该包设计用于低内存使用和快速查找,即使在大型数据集下也能确保流畅的用户体验。AutoTrie 具有平台无关性,支持 Android、iOS、macOS、Windows 和 Linux。其轻量级特性和简洁的 API 使其易于集成到现有项目中。

适合场景

  • 实时搜索建议
  • 代码补全功能
  • 自动完成文本字段
  • 动态下拉菜单
  • 输入预测

主要特点

  • 优化的 Trie 实现
  • 快速前缀匹配
  • 低内存占用
  • 跨平台支持
  • 简单的 API 集成

适合对象

  • 开发自动补全UI的开发者
  • 需要快速文本过滤的应用程序
  • 搜索密集型应用
  • 教育或编码工具
  • 高性能输入组件

使用建议

  • 最适合静态或更新频率较低的数据集
  • 可能需要对动态数据进行预处理
  • 不适合全文搜索
  • 仅限前缀匹配
  • 内存使用量随数据集大小而变化

原始 README

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

AutoTrie

A versatile library which solves autocompletion in Dart/Flutter. It is based around a space-efficient implementation of Trie which uses variable-length lists. With this, serving auto-suggestions is both fast and no-hassle. Suggestions are also sorted by how often they've been entered and subsorted by recency of entry, for search-engine-like results.

Read more about Trie here.

A Brief Note

It takes time, effort, and mental power to keep this package updated, useful, and improving. If you used or are using the package, I'd appreciate it if you could spare a few dollars to help me continue development.

PayPal

Usage

A usage example is provided below. Check the API Reference for detailed docs:

import 'package:autotrie/autotrie.dart';

void main() {
  // You are allowed to initialize with a starting databank by passing a `bank` parameter.
  var engine = AutoComplete(engine: SortEngine.configMulti(Duration(seconds: 1), 15, 0.5, 0.5));

  engine.enter('more'); // Enter more thrice.
  engine.enter('more');
  engine.enter('more');

  engine.enter('moody'); // Enter moody twice.
  engine.enter('moody');

  engine.enter('morose'); // Enter scattered words (with mo).
  engine.enter('morty');
  engine.enter('moment');
  engine.enter('momentum');

  engine.enter('sorose'); // Enter scattered words (without mo).
  engine.enter('sorty');

  engine.delete('morose'); // Delete morose.

  // Check if morose is deleted.
  print('Morose deletion check: ${!engine.contains('morose')}');

  // Check if engine is empty.
  print('Engine emptiness check: ${engine.isEmpty}');
 
  // They've been ranked by frequency and recency. Since they're all so similar
  // in recency, frequency takes priority.
  print("'mo' suggestions: ${engine.suggest('mo')}");
  // Result: [more, moody, momentum, moment, morty]

  // Get all entries.
  // They've *not* been sorted.
  // Use `engine.suggest('')` to get all entries sorted` 
  print('All entries: ${engine.allEntries}');
  // Result: [more, moody, sorty, sorose, momentum, moment, morty]
}

Sorting

The AutoComplete constructor takes a SortEngine, which it uses to sort the result of the autocompletion operation. There are a few different modes it can operate in:

  • SortEngine.entriesOnly() -> AutoComplete results are only sorted by number of entries in the engine (High to Low)
  • SortEngine.msOnly() -> AutoComplete results are only sorted by how much time has passed since their last entry (Low to High)
  • SortEngine.simpleMulti() ->
    • Sorted using two logistic curves, one for ms and one for entries
      • The ms curve is set to use 3 years (a LOT) as the upper end of how far back entries could have been entered
      • The entries curve is set to use 30 entries as the max amount of entries
      • These values are highly arbitrary and not likely to fit your project; this mode is not recommended unless you are just playing around.
    • Takes two weights (one for recency and one for entries) which can be used to balance how heavily each factor should affect the final sorting.
  • SortEngine.configMulti() ->
    • Sorted using two logistic curves, one for ms and one for entries
      • The ms curve is balanced using a parameter (a Duration) for the max time since entry in this engine.
      • The entries curve is balanced using a parameter (an int) for the max amount of entries in this engine.
      • If you know approximately how old and how big this AutoComplete engine is, it is highly recommended that you use this mode.
    • Takes two weights (one for recency and one for entries) which can be used to balance how heavily each factor should affect the final sorting.

Basic File Persistence

AutoComplete is natively capable of writing itself to and reading itself from a file. To do this, persist to a file using the persist method (it takes a File object): await engine.persist(myFile);

Then you can rebuild using AutoComplete.fromFile (it takes a File along with the mandatory SortEngine): var engine = AutoComplete.fromFile(file: myFile, engine: SortEngine.entriesOnly());

This persistence will preserve all the metadata (last insert, number of entries) in the table as well as the core data (the Strings themselves).

Hive Integration

  • Hive is a speedy, local, and key-value database for Dart/Flutter. Go check it out if you haven't already!
  • Hive integration is now available with autotrie:
    • Our way of integration uses extension methods.
    • Import Hive and AutoTrie, and create a normal Hive box using Hive.openBox('nameHere').
    • You can then call searchKeys(String prefix) and searchValues(String prefix) on that box to get auto-suggestions.
    • There is no sorting options: only entry-level sorting is available.

Features and bugs

Please file feature requests and bugs at the issue tracker.


This library and its contents are subject to the terms of the Mozilla Public License, v. 2.0.
© 2020 Aditya Kishore

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目