Commit d571390
committed
fix(workers): match Fuse ordering and reject non-cloneable options
FuseWorker previously merged shard results and sorted by `score ?? 0`,
which broke parity with Fuse in three ways:
1. With `includeScore: false`, score was never returned from the shards,
so the merge step had nothing to sort on and the order was effectively
shard-concat order.
2. Equal-score results across shards collapsed in shard-concat order
instead of Fuse's `(score, idx)` global tie-break.
3. With `shouldSort: false`, results came back in shard-concat order
rather than global collection order — visible after `add()` (which
round-robins across shards) and `setCollection()`.
The worker is now initialized with `includeScore: true` so the main
thread always receives the score it needs to tie-break, then strips it
from the final result if the caller didn't ask for it. The merge sort
mirrors Fuse's default `(score, idx)` comparator on the global refIndex,
and `shouldSort: false` re-sorts by global refIndex.
Also reject function-valued options (`sortFn`, top-level `getFn`,
`keys[].getFn`) at construction time. Functions aren't structured-
cloneable, so they used to crash with an opaque `DataCloneError` on the
first `search()` call. The new error names the offending option.
Plan 007.1 parent 4ad5999 commit d571390
5 files changed
Lines changed: 330 additions & 7 deletions
File tree
- docs
- src
- core
- workers
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
165 | 167 | | |
166 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
167 | 181 | | |
168 | 182 | | |
169 | 183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
61 | 90 | | |
62 | 91 | | |
63 | 92 | | |
| |||
93 | 122 | | |
94 | 123 | | |
95 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
96 | 132 | | |
97 | 133 | | |
98 | 134 | | |
99 | 135 | | |
100 | 136 | | |
101 | 137 | | |
102 | 138 | | |
| 139 | + | |
103 | 140 | | |
104 | 141 | | |
105 | 142 | | |
| |||
110 | 147 | | |
111 | 148 | | |
112 | 149 | | |
113 | | - | |
| 150 | + | |
114 | 151 | | |
115 | 152 | | |
116 | 153 | | |
| |||
144 | 181 | | |
145 | 182 | | |
146 | 183 | | |
147 | | - | |
148 | 184 | | |
149 | 185 | | |
150 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
151 | 214 | | |
152 | 215 | | |
153 | | - | |
154 | 216 | | |
155 | 217 | | |
156 | 218 | | |
| |||
0 commit comments