fastSearch method

List<T> fastSearch(
  1. String term, {
  2. double matchThreshold = 1.5,
})

Returns search results ordered by decreasing score. ~3-5x faster than search, but does not include the search score.

Implementation

List<T> fastSearch(String term, {double matchThreshold = 1.5}) {
  final sorted = items
      .map((item) => Tuple2(
          item,
          item.terms
              .map((itemTerm) => _scoreTerm(term, itemTerm))
              .reduce(math.min)))
      .toList()
    ..sort((a, b) => a.item2.compareTo(b.item2));
  final result = <T>[];
  for (final candidate in sorted) {
    if (candidate.item2 >= matchThreshold) {
      break;
    }
    result.add(candidate.item1.object);
  }
  return result;
}