completr 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. {completr-0.2.2 → completr-0.2.3}/Cargo.lock +3 -3
  2. {completr-0.2.2 → completr-0.2.3}/Cargo.toml +1 -1
  3. {completr-0.2.2 → completr-0.2.3}/PKG-INFO +1 -1
  4. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/engine.rs +10 -9
  5. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/search.rs +11 -3
  6. {completr-0.2.2 → completr-0.2.3}/LICENSE +0 -0
  7. {completr-0.2.2 → completr-0.2.3}/README.md +0 -0
  8. {completr-0.2.2 → completr-0.2.3}/crates/completr/Cargo.toml +0 -0
  9. {completr-0.2.2 → completr-0.2.3}/crates/completr/README.md +0 -0
  10. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/blocked.rs +0 -0
  11. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/client.rs +0 -0
  12. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/codec.rs +0 -0
  13. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/database.rs +0 -0
  14. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/dict.rs +0 -0
  15. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/document.rs +0 -0
  16. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/elias_fano.rs +0 -0
  17. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/fuzzy.rs +0 -0
  18. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/highlight.rs +0 -0
  19. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/hybrid.rs +0 -0
  20. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/inbox.rs +0 -0
  21. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/index.rs +0 -0
  22. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/lib.rs +0 -0
  23. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/postings.rs +0 -0
  24. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/segment/merge.rs +0 -0
  25. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/segment/titles.rs +0 -0
  26. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/segment/words.rs +0 -0
  27. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/segment.rs +0 -0
  28. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/staged.rs +0 -0
  29. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/store.rs +0 -0
  30. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/text.rs +0 -0
  31. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/trie.rs +0 -0
  32. {completr-0.2.2 → completr-0.2.3}/crates/completr/src/vectors.rs +0 -0
  33. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/Cargo.toml +0 -0
  34. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/examples/layers.py +0 -0
  35. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/examples/live_updates.py +0 -0
  36. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/examples/quickstart.py +0 -0
  37. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/__init__.py +0 -0
  38. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/__init__.pyi +0 -0
  39. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/_async.py +0 -0
  40. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/_async.pyi +0 -0
  41. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/_errors.py +0 -0
  42. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/_types.py +0 -0
  43. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/completr.pyi +0 -0
  44. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/python/completr/py.typed +0 -0
  45. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/src/lib.rs +0 -0
  46. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/tests/test_allocators.py +0 -0
  47. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/tests/test_api.py +0 -0
  48. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/tests/test_client.py +0 -0
  49. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/tests/test_completr.py +0 -0
  50. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/tests/test_database.py +0 -0
  51. {completr-0.2.2 → completr-0.2.3}/crates/completr-py/tests/test_vectors.py +0 -0
  52. {completr-0.2.2 → completr-0.2.3}/pyproject.toml +0 -0
@@ -735,7 +735,7 @@ dependencies = [
735
735
 
736
736
  [[package]]
737
737
  name = "completr"
738
- version = "0.2.2"
738
+ version = "0.2.3"
739
739
  dependencies = [
740
740
  "arc-swap",
741
741
  "async-trait",
@@ -765,7 +765,7 @@ dependencies = [
765
765
 
766
766
  [[package]]
767
767
  name = "completr-cli"
768
- version = "0.2.2"
768
+ version = "0.2.3"
769
769
  dependencies = [
770
770
  "clap",
771
771
  "completr",
@@ -776,7 +776,7 @@ dependencies = [
776
776
 
777
777
  [[package]]
778
778
  name = "completr-py"
779
- version = "0.2.2"
779
+ version = "0.2.3"
780
780
  dependencies = [
781
781
  "completr",
782
782
  "mimalloc",
@@ -3,7 +3,7 @@ resolver = "2"
3
3
  members = ["crates/completr", "crates/completr-py"]
4
4
 
5
5
  [workspace.package]
6
- version = "0.2.2"
6
+ version = "0.2.3"
7
7
  edition = "2021"
8
8
  rust-version = "1.94.1"
9
9
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: completr
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Operating System :: MacOS
@@ -5,7 +5,8 @@ use rustc_hash::FxHashMap;
5
5
 
6
6
  use crate::hybrid::fuse;
7
7
  use crate::{
8
- AliasSuggestion, Error, HybridOptions, HybridSuggestion, Index, SearchOptions, Suggestion,
8
+ AliasSuggestion, Error, HybridOptions, HybridSuggestion, Index, MatchKind, SearchOptions,
9
+ Suggestion,
9
10
  };
10
11
 
11
12
  /// The namespace of indexes published or written without naming one.
@@ -409,7 +410,7 @@ pub fn layered_complete(
409
410
  })
410
411
  .collect();
411
412
  merge(layers, per_layer, options.limit, |s: &Suggestion| {
412
- (s.id, s.score)
413
+ (s.id, s.kind == MatchKind::Fuzzy, s.score)
413
414
  })
414
415
  }
415
416
 
@@ -433,7 +434,7 @@ pub fn layered_complete_aliases(
433
434
  })
434
435
  .collect();
435
436
  merge(layers, per_layer, options.limit, |s: &AliasSuggestion| {
436
- (s.id, s.score)
437
+ (s.id, false, s.score)
437
438
  })
438
439
  }
439
440
 
@@ -452,7 +453,7 @@ pub fn layered_vector_search(
452
453
  });
453
454
  }
454
455
  Ok(merge(layers, per_layer, options.limit, |s: &Suggestion| {
455
- (s.id, s.score)
456
+ (s.id, false, s.score)
456
457
  }))
457
458
  }
458
459
 
@@ -471,7 +472,7 @@ fn merge<S>(
471
472
  layers: &[Option<&Index>],
472
473
  per_layer: Vec<Vec<S>>,
473
474
  limit: usize,
474
- key: impl Fn(&S) -> (u64, f64),
475
+ key: impl Fn(&S) -> (u64, bool, f64),
475
476
  ) -> Vec<LayeredSuggestion<S>> {
476
477
  let mut merged: Vec<LayeredSuggestion<S>> = Vec::new();
477
478
  let mut position: FxHashMap<u64, usize> = FxHashMap::default();
@@ -495,11 +496,11 @@ fn merge<S>(
495
496
  .flatten()
496
497
  .any(|index| index.covers(id))
497
498
  });
499
+ // A correction from one layer never outranks a direct match from another.
498
500
  merged.sort_by(|a, b| {
499
- key(&b.suggestion)
500
- .1
501
- .partial_cmp(&key(&a.suggestion).1)
502
- .unwrap_or(std::cmp::Ordering::Equal)
501
+ let (a, b) = (key(&a.suggestion), key(&b.suggestion));
502
+ a.1.cmp(&b.1)
503
+ .then(b.2.partial_cmp(&a.2).unwrap_or(std::cmp::Ordering::Equal))
503
504
  });
504
505
  merged.truncate(limit);
505
506
  merged
@@ -9,6 +9,9 @@ use rustc_hash::{FxHashMap, FxHashSet};
9
9
  use crate::index::{char_count, current_filter, with_filter, Field};
10
10
  use crate::{fuzzy, text, Index};
11
11
 
12
+ /// Shorter queries are not corrected: one edit away from two characters is almost anything.
13
+ const MIN_CORRECTED_CHARS: usize = 3;
14
+
12
15
  #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
13
16
  #[non_exhaustive]
14
17
  pub enum MatchKind {
@@ -898,7 +901,10 @@ impl Index {
898
901
  .collect();
899
902
 
900
903
  let mut fuzzy_matches: FxHashMap<u32, (usize, usize, f64)> = FxHashMap::default();
901
- if prefix_matches.len() < max_results && depth < 2 {
904
+ if prefix_matches.len() < max_results
905
+ && depth < 2
906
+ && text::char_len(q) >= MIN_CORRECTED_CHARS
907
+ {
902
908
  let mut last_distance = 0;
903
909
  for (rank, (phrase, distance)) in self
904
910
  .fix_spell(
@@ -1017,9 +1023,11 @@ impl Index {
1017
1023
  (score, len, self.id_key(doc), doc, m)
1018
1024
  })
1019
1025
  .collect();
1026
+ // Corrections rank below every direct match before the cut, so a longer limit only appends.
1020
1027
  scored.sort_unstable_by(|a, b| {
1021
- b.0.partial_cmp(&a.0)
1022
- .unwrap_or(Ordering::Equal)
1028
+ (a.4.fuzzy_distance > 0)
1029
+ .cmp(&(b.4.fuzzy_distance > 0))
1030
+ .then(b.0.partial_cmp(&a.0).unwrap_or(Ordering::Equal))
1023
1031
  .then(a.1.cmp(&b.1))
1024
1032
  .then(a.2.cmp(&b.2))
1025
1033
  });
File without changes
File without changes
File without changes