Commit 4047989
fix(api-search): ZMS-94: keep $text queries plannable inside OR branches
MongoDB resolves $text through the compound `fulltext` index, which is prefixed
with `user`, so a $text clause nested in an $or needs its own equality on
`user`, and every sibling branch of that $or has to be index backed. Neither
held, so any search mixing a header keyword with a fulltext term under OR
returned a 500.
applyTextIndexPrefix stamps the user id onto every branch of every $or that
wraps a $text clause. The filter already requires `user` at the top level, so
the repeated equality does not change what it matches. Both filter builders
call it, so the or.* API params are covered as well, not only the q syntax.
MongoDB also accepts a single $text expression per query, and the builder
emitted two whenever text terms landed in different OR branches. Terms that
cannot claim the one slot now fall back to the regex matching quoted phrases
already use, keeping AND semantics for a merged AND term and keeping negated
terms excluding rather than widening the match.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0179oqSvLfdTeNBTsSPVmp4m1 parent 332ef14 commit 4047989
3 files changed
Lines changed: 311 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
15 | 60 | | |
16 | 61 | | |
17 | 62 | | |
| |||
356 | 401 | | |
357 | 402 | | |
358 | 403 | | |
| 404 | + | |
| 405 | + | |
359 | 406 | | |
360 | 407 | | |
361 | 408 | | |
362 | | - | |
| 409 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 46 | + | |
51 | 47 | | |
52 | 48 | | |
53 | 49 | | |
54 | 50 | | |
55 | 51 | | |
56 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
| |||
290 | 288 | | |
291 | 289 | | |
292 | 290 | | |
293 | | - | |
| 291 | + | |
294 | 292 | | |
295 | 293 | | |
296 | 294 | | |
297 | | - | |
298 | 295 | | |
299 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
300 | 321 | | |
301 | 322 | | |
302 | 323 | | |
303 | 324 | | |
304 | 325 | | |
305 | 326 | | |
306 | 327 | | |
| 328 | + | |
| 329 | + | |
307 | 330 | | |
308 | | - | |
| 331 | + | |
309 | 332 | | |
310 | 333 | | |
311 | 334 | | |
| |||
352 | 375 | | |
353 | 376 | | |
354 | 377 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 378 | + | |
359 | 379 | | |
360 | 380 | | |
361 | 381 | | |
| |||
745 | 765 | | |
746 | 766 | | |
747 | 767 | | |
| 768 | + | |
| 769 | + | |
748 | 770 | | |
749 | 771 | | |
750 | 772 | | |
| |||
0 commit comments