findWithScores method

List<ObjectWithScore<T>> findWithScores()

Finds objects matching the query associated to their query score (e. g. distance in NN search). The resulting list is sorted by score in ascending order.

Returns a list of ObjectWithScore that matching objects and their score, sorted by score in ascending order.

This only works on objects with a property with an HnswIndex.

Implementation

List<ObjectWithScore<T>> findWithScores() {
  final result = <ObjectWithScore<T>>[];
  final errorWrapper = ObjectVisitorError();
  visitCallback(Pointer<OBX_bytes_score> data) {
    try {
      final item = data.ref;
      final object = _entity.objectFromData(_store, item.data, item.size);
      final score = item.score;
      result.add(ObjectWithScore(object, score));
      return true;
    } catch (e) {
      errorWrapper.error = e;
      return false;
    }
  }

  visitWithScore(_ptr, visitCallback);
  errorWrapper.throwIfError();
  return result;
}