search 0.3.0

Pub Package Github Actions CI

Overview #

This is a simple information retrieval engine for the package database.

Licensed under the Apache License 2.0.

How it works #

Iteration #

SearchableDatabase wraps any other Database and intercepts search requests that contain one or more KeywordFilter instances.

The current implementation then simply visits every document in the collection and calculates score for each document. This is very inefficient strategy for large collections / many concurrent requests. However, for typical mobile and web applications, this is fine!

Preprocessing #

In the preprocessing step, we simplify both the keyword and the inputs.

The following transformations are done:

  • String is converted to lowercase.
    • "John" --> " john "
  • Some extended Latin characters are replaced with simpler characters.
    • "Élysée" --> " elysee "
  • Some suffixes are removed.
    • "Joe's coffee" --> " joe coffee "
  • Multiple whitespace characters are replaced with a single space.
    • "hello,\n world" --> " hello world "

Scoring #

The document scoring algorithm is very basic.

The high-level idea is to raise score for:

  • More matches
  • Sequential matches
  • Matches of non-preprocessed strings

Contributing #

Getting started #

In pubspec.yaml:

dependencies:
  database: any
  search: any

In lib/main.dart:

import 'package:database/database.dart';
import 'package:search/search.dart';

void main() {
  final database = SearchableDatabase(
    master: MemoryDatabaseAdapter(),
  ).database();
  final collection = database.collection('employee');
  final result = await collection.search(
    query: Query.parse(
      '(Hello OR Hi) world!',
      skip: 0,
      take: 10,
    ),
  );
}

[0.3.0] - January 21, 2020

  • Support for 'package:database' version 0.3.x.

[0.2.1] - January 1, 2020

  • Initial release

example/example.dart

import 'package:database/database.dart';
import 'package:search/search.dart';

void main() async {
  // Set default database
  final database = SearcheableDatabase(
    master: MemoryDatabaseAdapter(),
    isReadOnly: true,
  ).database();

  // Search items
  final collection = database.collection('employee');
  final response = await collection.search(
    query: Query.parse('"software developer" (dart OR javascript)'),
  );

  // Print items
  for (var snapshot in response.snapshots) {
    print('Document ID: ${snapshot.document.documentId}');
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  search: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:search/search.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Feb 17, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
charcode ^1.1.0 1.1.3
database ^0.3.0 0.3.0
meta ^1.1.0 1.1.8
Transitive dependencies
async 2.4.0
built_collection 4.3.2
built_value 7.0.9
collection 1.14.12
convert 2.1.1
crypto 2.1.4
cryptography 0.1.2
csslib 0.16.1
fixnum 0.10.11
html 0.14.0+3
matcher 0.12.6
path 1.6.4
petitparser 3.0.1
protobuf 1.0.1
quiver 2.1.2+1
source_span 1.6.0
stack_trace 1.9.3
term_glyph 1.1.0
typed_data 1.1.6
universal_html 1.1.13
universal_io 0.8.6 1.0.0
xml 3.7.0
zone_local 0.1.2
Dev dependencies
pedantic ^1.8.0
test ^1.8.0