1
2
3
4
5
6
7
8
9
10
11
12
13
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
60
61
62
63
64
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
//! The Tantivy full-text backend, in the two store layers: the connection-manager [`TantivyStore`]
//! owns ONE index ROOT — a local mmap directory tree, no server — and hands out the STATELESS
//! [`TantivyFulltext`] handle per slot.
//!
//! # THE THREE LAWS, and why each is a law rather than a preference
//!
//! Each was measured on the reference implementation, and each is stated here as the reason it is.
//!
//! ## ONE index PER SLOT, because BM25's corpus statistics are index-wide
//!
//! A slot is a DIRECTORY under the root holding its own index — its own lockfile, its own writer,
//! its own reader. Not one shared index keyed by slot, and the reason is not tidiness:
//!
//! - **The statistics pool.** Both of them: `docfreq` over `numdocs` (hence IDF), and the average
//! document length (`avgdl`) that the length normalization divides by. One shared index would pool
//! every slot into ONE corpus, so indexing transcripts would move captions' scores AND reorder
//! them. A single-term query is exposed too, which is the part that surprises: IDF is then one
//! factor common to every hit and so cannot reorder them, but `avgdl` sits inside each document's
//! OWN length normalization, scaled by that document's OWN length, and never factors out — so a
//! sibling slot's long documents reweight this slot's long documents against its short ones.
//! `tests::a_sibling_slot_cannot_move_this_slot_s_bm25_ranking` is that leak as an assertion, and
//! its two documents sit either side of the tipping point on purpose.
//! - **The writer lock is per-DIRECTORY.** A second `IndexWriter` over one directory fails
//! `LockFailure(LockBusy)`, so under a shared index every slot would queue through one writer.
//! Per-slot directories mean per-slot lockfiles: two handles minted from one store can hold their
//! writers CONCURRENTLY as long as they name different slots.
//!
//! ## The keyed replace rides the IDENTITY TERM, because `delete_term` is the only door
//!
//! Tantivy deletes by a SINGLE term. Its [`delete_query`] twin — which would take a conjunction over
//! several fields — is `#[doc(hidden)]` in 0.26.1 (`src/indexer/index_writer.rs:697`), and
//! `delete_term` is a THIN WRAPPER over it: it builds a one-term `TermQuery` and calls it. So a
//! multi-field identity cannot be the delete target as separate columns; the identity has to be ONE
//! value, and this backend builds it.
//!
//! What that value must satisfy is INJECTIVITY and nothing else. It is never ranged over, never
//! sorted, never prefix-scanned — it is looked up exactly, once, by a delete — so an ordering
//! property would be a promise with no reader. [`TantivyAddress`] delivers exactly that: each append
//! writes a fixed-width big-endian `u32` length and then the field's raw bytes, so a rendered term
//! parses back into exactly ONE field sequence and the `("ab", "c")` versus `("a", "bc")` collision
//! class is structurally dead — there is no separator character to collide, because there is no
//! separator.
//!
//! `delete_term` also SWALLOWS a term it cannot resolve: it returns a bare opstamp rather than an
//! error when the term's field is not indexed (the `unwrap_or_else` at that same site). A schema
//! that made the identity field stored-only would therefore turn every keyed replace into an APPEND,
//! silently. `tests::a_keyed_replace_leaves_exactly_one_document` is what stands where that error
//! would have been.
//!
//! ## The writer is serialized by an EXCLUSIVE BORROW, because the replace is not atomic
//!
//! [`WriteContext`](FulltextWrite::WriteContext) is `&mut `[`SlotWriter`], and the exclusivity is
//! LOAD-BEARING rather than a bound left un-minimized — see that type's own doc for the mechanism
//! and the measurement. A keyed replace is `delete_term` THEN `add_document`, and a delete only
//! tombstones documents whose opstamp is LOWER than its own, so two `upsert` calls sharing one
//! writer can interleave as (delete, delete, add, add) and leave TWO documents under ONE identity.
//!
//! Both of tantivy's calls take `&self`, which is exactly the observation that misleads: `Sync` is
//! not *safe to use concurrently for this protocol*. The borrow is what forbids the interleaving,
//! and it is pinned by the doctest pair on [`SlotWriter`].
//!
//! # The schema is four fields, and each is spent
//!
//! ```text
//! source STRING (indexed) the DISCRIMINANT — which source this entry came in under
//! identity BYTES (indexed) the delete_term target: source ⊕ id, length-prefixed
//! key BYTES (stored) the whole `R::Key` — what a hit is handed back under
//! body TEXT (indexed) the tokenized text BM25 ranks — `| STORED` where the
//! declaration wrote `stored`; see the posture note
//! ```
//!
//! **The discriminant is a native FIELD**, untokenized and indexed, so *which source* is a `Term` an
//! engine builds rather than something a later reader reconstructs by scanning. Nothing in this
//! crate queries it yet; `tests::the_source_word_is_a_native_term` is what keeps that property
//! measured rather than assumed, and it is the read side a fan-in will reach for.
//!
//! **The identity is `source ⊕ id`, framed**, not the id alone. Today one source writes into one
//! slot, so the source append is inert — and it is written anyway, because the alternative is an
//! identity that is injective only under a precondition nothing enforces: two sources sharing a slot
//! with overlapping id spaces would have one's write DELETE the other's entry, silently, and the
//! repair would be a reindex rather than a code change. Four bytes and a word per document buy the
//! injectivity outright.
//!
//! **The key is stored and not indexed.** It is the hit's ADDRESS — the whole chain, ancestry
//! included — and nothing looks an entry up by it: what names an entry is the identity above. A
//! caller that could search this field would have an EXISTENCE PROBE for any row from a query string
//! alone, which is the hole [`TantivyFulltextError::UnsearchableField`] closes on the other side.
//!
//! # THE ROWS THIS BACKEND NO LONGER SHIPS, and why there are none left to ship
//!
//! A block of one `impl FulltextField<TantivyFulltext> for …` — the retired per-engine row — per
//! member of [`Id`](crate::Id) stood in this file, with a compiler-instantiated SHIPPED-PARITY AUDIT
//! closing it. Both are gone, and the deletion is the column language arriving: a key reports itself
//! in COLUMNS ([`Field`](crate::Field)) and this engine LANDS them ([`TantivyTerms`] /
//! [`TantivyColumns`]), so a row is written once per TYPE and every engine reads it.
//!
//! The retired row carried the ENGINE as a parameter, which is what made all three of its axes
//! orphan-legal after the engine-specific key trait's `E0117` wall. The column language does not
//! widen that table — it deletes the axis the table existed to enumerate:
//!
//! | a new … | writes | and pairs with |
//! |---|---|---|
//! | ENGINE | `impl ColumnWriter for MyTerms` + `impl ColumnReader for MyColumns` | EVERY row anybody has written, including rows in crates it has never heard of |
//! | value TYPE | `impl Field for MyId` | EVERY engine there is, present and future |
//! | KEY | `impl Field for MyKey` | the same, with one `where` per column type |
//!
//! So the ROW TAX is dead: a vocabulary of N types across M engines was N×M impls and each new
//! engine started at zero, where it is N + M now and a new engine starts complete. The audit went
//! with it because its OBLIGATION went with it — *this crate's engine pairs this crate's
//! vocabulary* is not a question a backend can fail once a backend names no type. What replaced it
//! is `store::field`'s own audit, which is stronger where it counts: it says every member of the id
//! vocabulary is crossable AT ALL, since one row there is the only row a member now needs.
//!
//! What this backend still owes is three things, and each has a home:
//!
//! - **The KINDS.** [`ColumnWriter`] and [`ColumnReader`] have required methods and defaulted ones;
//! this backend faces the five required writes, the five required reads and
//! [`fixed`](ColumnReader::fixed), and deliberately leaves every other kind on its fallback — see
//! [`TantivyTerms`]' impl, where the reason is the STORED LAYOUT rather than laziness.
//! - **The WORDS.** [`ColumnError`] is the floor a row's own refusals are raised through, and
//! [`TantivyFulltextError`] answers it — with [`domain`](ColumnError::domain) and
//! [`width`](ColumnError::width) overridden onto the arms this backend already had, so a
//! `NonZero*` reading a zero and an `IpAddr` reading five octets refuse in exactly the words they
//! refused in before.
//! - **The ROUND TRIP.** A bound only ever says a row EXISTS. Whether a row is RIGHT is
//! `store::field`'s suite and `tests::vocabulary`'s question, and the two stay two.
//!
//! # No async runtime, and no dependency beyond tantivy
//!
//! Tantivy is a SYNCHRONOUS engine, so `upsert` and `search` do their work inline and return a
//! ready future — the shape [`LocalFsBlob`](crate::LocalFsBlob) already established here. A
//! caller wanting the work off the async thread wraps the call. The reference implementation
//! instead ran every tantivy call through `spawn_blocking`, which cost it a tokio dependency with
//! `rt` and `sync` features; this crate has no async runtime at all, and a backend is not the
//! place to acquire one.
//!
//! [`delete_query`]: https://docs.rs/tantivy/0.26.1/tantivy/struct.IndexWriter.html
use ;
use ;
use Utf8Bytes;
// `schema::Field` is ALIASED: `Field` is the column-language ROW in this crate, and tantivy's is a
// schema field's handle. Both are named in this file, so the foreign one wears the qualifier.
use ;
use ;
use crate::;
/// The searchable field an UNFANNED corpus holds — the zero-configuration lane's own.
///
/// A slot's searchable fields are its LANES: one per partition, each carrying that lane's analyzer,
/// and a corpus that declared no fan has exactly one — [`LaneIdent::UND`]'s — which is this name and
/// the only name this backend ever wrote before the fan word existed. So the byte-for-byte shape of
/// an unfanned slot is unchanged, and [`lane_field`] is the one function that says so.
///
/// The whitelist DIRECTION is unchanged and is the whole of what keeps the guard honest as the
/// schema grows: a query may name a searchable field, and every other field of the schema — the
/// stored `key` above all — is refused by default rather than admitted by default.
const SEARCHABLE_FIELD: &str = "body";
/// THE SCHEMA WORDS THIS BACKEND SPELLS ITSELF, which a lane key may therefore not take.
///
/// A lane's field is named after the lane, so a lane keyed `key` would collide with the stored
/// address — silently, since tantivy's schema builder is happy to hold two fields of one name and
/// only one of them can be resolved. `body` is here for the same reason one grain over: it is
/// [`LaneIdent::UND`]'s own field, so a second lane spelling it would be two lanes in one field.
const RESERVED_LANE_KEYS: = ;
/// The analyzer a lane rides where the deployment named none — tantivy's own, and the one every
/// corpus this backend ever wrote has been tokenized by.
const DEFAULT_ANALYZER: &str = "default";
/// **EVERY ANALYZER A TANTIVY BUILD SHIPS REGISTERED**, for the refusal that lists them.
///
/// It is a MEASUREMENT of `TokenizerManager::default()` and not a vocabulary: those four names are
/// what tantivy 0.26 registers, `en_stem` behind its own `stemmer` feature which this crate keeps on
/// with the rest of tantivy's defaults. Every other analyzer tantivy SHIPS — `NgramTokenizer`,
/// `RegexTokenizer`, the non-English `Stemmer`s, `AsciiFoldingFilter` — is an exported type that
/// nothing registers, so it reaches a lane the same way a third party's own does: the deployment
/// registers it on the manager and names it here. See [`TantivyStore::with_tokenizers`].
///
/// The list is restated rather than read back because tantivy's manager has no enumeration —
/// `register` and `get`, and nothing that walks it — so a refusal that wanted to print the registry
/// has nowhere to read it from. What it prints instead is what a build is GUARANTEED to hold, said
/// plainly, beside the sentence that names the door for everything else.
const SHIPPED_ANALYZERS: = ;
/// **ONE SLOT'S FAN, RESOLVED** — `(lane key, the analyzer name that lane's field is built with)`, in
/// the roster's own order.
///
/// It is what layer two produces at [`create_slot`](TantivyStore::create_slot) — the declaration's
/// roster joined to the deployment's table, with every name already checked against the manager —
/// and what the schema builder, the write and the read all read back. A name of its own because
/// three signatures spell it: the pair is a fact with two halves, and a reader should not have to
/// parse the type to learn which half is which.
///
/// `Arc<[…]>` for the reason the slot cache holds `Arc`s: a fan is settled once and handed out per
/// open, so a clone is a refcount rather than a walk.
type Fan = ;
/// The schema field one lane's text is indexed into.
///
/// [`LaneIdent::UND`] keeps `body`, which is what makes an unfanned corpus byte-identical to every
/// corpus this backend wrote before lanes existed; every other lane is its own key. One function,
/// spent by the schema builder, the write and the read, so the three cannot name different fields.
/// **THE PER-SLOT ANALYZER TABLE** — this backend's answer to
/// [`FulltextEngine::Options`](crate::FulltextEngine::Options), one analyzer NAME per lane.
///
/// ```
/// use ingraph::LaneAnalyzers;
///
/// let knobs = LaneAnalyzers::new()
/// .with("en", "en_stem")
/// .with("rest", "whitespace");
///
/// assert_eq!(knobs.analyzer("en"), Some("en_stem"));
/// // A lane the table says nothing about rides tantivy's own `default`.
/// assert_eq!(knobs.analyzer("zh"), None);
/// ```
///
/// # It carries NAMES, and the instance stays the manager's
///
/// The ruling split a lane in two: its EXISTENCE is a declaration fact that shapes the slot, and its
/// INSTANCE is an assembly fact that arrives at boot. This is the join between them, and it is a
/// name rather than a `TextAnalyzer` for one reason — tantivy already has a registry of built
/// analyzers, so a table holding instances would be a second one, and two registries is how a
/// corpus comes to be written by one analyzer and searched by another. What a deployment does
/// instead is register its own on the manager ([`TantivyStore::with_tokenizers`]) and NAME it here.
///
/// # It is FRAMEWORK-OPEN by construction
///
/// A name is resolved against the manager the store holds, so the vocabulary is the deployment's:
/// `SHIPPED_ANALYZERS` is what a build is guaranteed to hold, and a jieba, a Thai dictionary or an
/// n-gram is one `register` call away with no word here changing. A name the manager does not hold
/// is refused AT CONSTRUCTION —
/// [`UnknownAnalyzer`](TantivyFulltextError::UnknownAnalyzer) — rather than silently falling back to
/// `default`, which is the mis-filing the whole lane layer exists to prevent.
///
/// # ABSENCE IS THE DEFAULT, and that is presence-is-enablement at this seat
///
/// A lane the table says nothing about is tokenized by tantivy's `default`, which is exactly what an
/// unfanned corpus already was. So a deployment naming no knobs at all gets the corpus it had, byte
/// for byte.
/// The payload of [`TantivyFulltextError::UnknownAnalyzer`]: which lane named an analyzer, and what
/// it named.
///
/// BOXED at the error for [`SlotMismatch`]'s measured reason exactly — two [`Utf8Bytes`] inline
/// would widen every `Result` on this backend's paths past `clippy::result_large_err`'s ceiling to
/// describe a boot-time arrangement mistake.
/// A stored address failed to parse back into the values it was written from.
///
/// Every arm is a SHAPE failure of the stored bytes rather than a domain refusal: a value whose own
/// domain is narrower than the width it stores has no arm here, because this codec knows widths and
/// not meanings.
/// THIS ENGINE'S ADDRESS VOCABULARY — the canonical binary form a key's columns seal into, and the
/// form a hit's stored address arrives in.
///
/// It is [`FulltextEngine::Address`] for [`TantivyFulltext`]: what
/// [`finalize`](FulltextEngine::finalize) hands back and what [`open`](FulltextEngine::open) spends.
/// ONE type for both directions, because it is one correspondence — an address written by a key has
/// to be readable by that same key's type, and two members would let a backend supply one half and
/// not the other.
///
/// The length prefix IS the design. Each column is written as a fixed-width big-endian `u32` length
/// and then the value's raw bytes, so a rendered address parses back into exactly one column
/// sequence and two different sequences can never render identically — where a separator-character
/// scheme has no such guarantee, since `("ab", "c")` and `("a", "bc")` concatenate to the same
/// string and any separator byte can appear inside a field. Every column is a byte-copy, never a
/// string rendering.
///
/// INJECTIVITY is the whole contract, and ordering is deliberately not part of it: the identity is
/// looked up exactly by [`delete_term`](https://docs.rs/tantivy/0.26.1/tantivy/struct.IndexWriter.html#method.delete_term)
/// and by nothing else, so a big-endian layout here buys sortability no reader spends. What the
/// big-endian widths ARE for is determinism — one value renders to one address on every host.
///
/// # It holds BYTES and no cursor, and the two phases beside it are why
///
/// Writing is [`TantivyTerms`]' and reading is [`TantivyColumns`]', so an address is a VALUE
/// between them rather than a half-consumed buffer: it is sealed once, it rides inside a hit, and it
/// is spent once when a key opens it. A cursor living here would be meaningless until opened and
/// would put two addresses holding the same bytes at different read positions out of `Eq` with each
/// other.
///
/// **THE STORED LAYOUT IS UNCHANGED, BYTE FOR BYTE**, by these three types and by the column
/// language above them — see `store::field`'s layout-parity test, which pins the shipped rows'
/// bytes against hand-written expectations that encode what is already on disk.
/// The fixed width of one column's length prefix — portable across targets, unlike a `usize`.
const PREFIX: usize = 4;
/// THE WRITE PHASE — [`FulltextEngine::WriteBuffer`] for [`TantivyFulltext`], and the accumulator a
/// key reports its columns into.
///
/// It is a [`ColumnWriter`], so a key hands it one TYPED column at a time and it frames each
/// directly into the bytes a tantivy `Term` is built from — `i64`, `text`, `uuid` and the rest land
/// as themselves, with no intermediate encoding in between. That is the whole economy of the column
/// language at this backend: what used to be a per-(type × engine) row calling `push_i64` is now a
/// row calling `i64`, and the byte it lands is the same byte.
///
/// NOT an address, and the type says so. [`FulltextEngine::buffer`]'s own doc names this engine as
/// the cautionary case — `TantivyAddress::default()` is the empty byte string, which is exactly the
/// coincidence that would have made a `Default` bound look right — and the split is what makes the
/// confusion unrepresentable: a half-built address has no address's type here.
/// The REQUIRED kinds only, each framed as itself — and the defaulted kinds are deliberately left
/// alone.
///
/// [`fixed`](ColumnWriter::fixed) falls through to [`bytes`](ColumnWriter::bytes), which is what
/// keeps every narrow integer, every fixed byte array and the network family landing the exact bytes
/// this backend has always stored for them: one length prefix and the value's own big-endian
/// octets. Overriding `fixed` here would land something else and break the read of every index
/// written before the move.
/// THE READ PHASE — [`FulltextEngine::ReadBuffer`] for [`TantivyFulltext`], and the cursor a key
/// takes its columns back off.
///
/// It is minted by [`FulltextEngine::open`] out of an address it CONSUMES, so it owns the bytes and
/// borrows nothing; the cursor advances and is never rewound. A hit's address is read once, by the
/// key that owns it, in the order that key's columns were written.
/// The REQUIRED kinds only, mirroring [`TantivyTerms`]' writes — and
/// [`fixed`](ColumnReader::fixed), which is the one place a WIDTH is checked and therefore the one
/// kind an engine has to face itself.
///
/// Every defaulted narrow integer arrives through `fixed`, which is why they need no arm here: the
/// width is settled once and turning `N` bytes into the value they are cannot fail.
/// ONE ENTRY under construction — [`FulltextWrite::Doc`] for [`TantivyFulltext`].
///
/// It is the whole of what this backend needs to index something, and it names no record: the
/// EMISSION fills it in, because the emission is the code that can see what a record's id, key and
/// text are. Everything typed happens there; what crosses the seam is this.
///
/// Three positions, and each is spent on one of the schema's four fields:
///
/// | position | schema field | what it is |
/// |---|---|---|
/// | `source` | `source` (indexed) + the identity's first column | the DISCRIMINANT — which source this entry came in under |
/// | identity | `identity` (indexed) | the `delete_term` target: source ⊕ id, framed |
/// | address | `key` (stored) | the whole key — what a hit is handed back under |
/// | body | `body` (indexed, stored) | the tokenized text BM25 ranks |
///
/// The SOURCE is framed into the identity by [`new`](Self::new), before anything else is appended.
/// Today one source writes into one slot, so the append is inert — and it is written anyway, because
/// the alternative is an identity that is injective only under a precondition nothing enforces: two
/// sources sharing a slot with overlapping id spaces would have one's write DELETE the other's
/// entry, silently, and the repair would be a reindex rather than a code change.
///
/// # Both accumulators are WRITE PHASES, and that is the honest type for a builder
///
/// The identity and the address are [`TantivyTerms`], not [`TantivyAddress`]es: an entry under
/// construction is exactly a key REPORTING itself, and it reports across two calls — the source at
/// [`new`](Self::new), the id at [`with_identity`](Self::with_identity). What
/// [`FulltextEngine::finalize`] seals is the same bytes; nothing here needs a sealed address,
/// because what the write path spends is a byte slice for a `Term`.
/// The payload of [`TantivyFulltextError::SlotMismatch`]: which slot the handle indexes into, and
/// which slot the [`SlotWriter`] it was handed is the capability for.
///
/// BOXED at the error, and that is measured rather than stylistic: a slot name is a
/// [`Utf8Bytes`] and two of them are 128 bytes, which is exactly `clippy::result_large_err`'s
/// ceiling — so carrying the pair inline would widen every `Result` on the write path, the OK arm
/// included, to describe a state that is a caller's programming error and never a runtime condition.
/// The other arms are already small, so this one variant decides the whole error's size.
/// A Tantivy full-text failure — of the manager's open or writer path, or of a handle's op.
///
/// `Debug` and no more: tantivy's own error types are neither `Clone` nor `PartialEq`, and every one
/// this backend can meet — a directory open, an IO error, a malformed query, a second writer's
/// `LockFailure` — folds into the [`Tantivy`](Self::Tantivy) arm through `TantivyError`'s own `From`
/// conversions. One backend-error surface, as the filesystem blob face has one.
/// The COLUMN LANGUAGE's floor, answered in this backend's own arms.
///
/// [`custom`](ColumnError::custom) is the whole obligation and the one method with nowhere else to
/// go. The two NAMED refusals are overridden rather than defaulted, and that is a compatibility act
/// as much as a wording one: the retired per-engine rows raised
/// [`Domain`](KeyDecodeError::Domain) for a zero read back into a `NonZero*` and
/// [`Width`](KeyDecodeError::Width) for an untagged network enum's unexpected octet count, and the
/// engine-blind rows that replaced them raise exactly those two through this trait. Left defaulted,
/// both would have become a sentence in [`Column`](TantivyFulltextError::Column) and every caller
/// matching on the old arm would have gone quietly wrong.
/// Refuse a slot that is not an identifier — the guard that keeps every slot's index INSIDE the
/// store root and keeps one slot vocabulary across the crate's stores.
///
/// It is the first act of [`TantivyStore::slot_index`], the only route from a slot NAME to the
/// filesystem, so no directory can be created around it.
///
/// A charset rather than a path rule, which is what makes it portable: `..`, `/`, `\`, an absolute
/// path, the empty name and a NUL fall outside it on EVERY target, where a `Path`-based rule would
/// admit `a\b` on unix and refuse it on Windows. The residual, stated rather than papered over: a
/// charset does not make directory CREATION platform-independent — Windows reserves device names
/// (`con`, `nul`, `aux`, `com1`, …) that are perfectly good identifiers and illegal directory names,
/// so a slot called `nul` still fails there, as an IO error rather than as silent corruption.
// WHETHER a slot's index KEEPS the text it indexed — the `stored` word's whole reach into this
// backend, carried as the bit it is.
//
// The indexed half is not a choice: a full-text slot exists to be searched, so `body` is tokenized
// in every posture. What varies is whether tantivy also writes the text into the doc store, and the
// answer rides `STORED` on that one field. The default is NOT KEPT, and the default is the point:
// what a full-text index promises is that the text is FINDABLE, and handing it back is a second
// promise paid for in bytes on every entry — a caller that wants the value has the system of record,
// addressed by the key every hit already carries.
//
// ONE POSTURE PER SLOT, and the first open decides. `Index::open_or_create` REJECTS a directory
// whose on-disk schema differs from the one asked for, so a slot written under one posture and
// reopened under the other is a loud tantivy error rather than a silent disagreement. Within one
// `TantivyStore` the slot cache holds the first answer, and a reader that reaches a never-written
// slot CREATES it at the default — so a stored slot is opened for writing before it is searched,
// which is the order an emitted arrangement runs in anyway.
//
// It USED to be a `SlotSchema` type of its own, holding exactly this bit. The FULL-TEXT KIND's
// blueprint now carries the posture (`crate::SlotSchema::is_stored`) beside the corpus name and the
// columns a declaration elected, so one name means one thing: two types differing by two members and
// sharing a name is drift a reader pays for. What crosses this backend's own doors is the bit.
/// A slot index's fields, resolved once when the slot is opened.
///
/// A tantivy `Field` is a `u32` handle, so the three fixed ones cost nothing to carry; the LANES are
/// an `Arc<[…]>` because a fanned corpus holds as many as it declared and a [`SlotWriter`] carries
/// the set rather than re-resolving it per document. That is what took `Copy` off this type: one
/// refcount bump per writer, against a resolve per entry.
/// A slot's opened index with its reader and its fields — what the cache memoizes, so the directory
/// scan and the reader build happen at most ONCE per slot, never per op.
///
/// `Clone` is three cheap handle clones (`Index` and `IndexReader` are `Arc`-backed, and so is
/// [`Fields`]' lane list): that is how a caller takes what it needs out of the cache without holding
/// a borrow of it.
/// The write capability for ONE slot: that slot's sole `IndexWriter` together with the schema fields
/// to write through.
///
/// [`TantivyStore::writer`] resolves both from the SAME slot and is the only way to obtain one, so
/// the pairing cannot be forged — and a face that queues through it reaches no index but that slot's
/// without resolving anything.
///
/// The pairing is the whole point. Every slot's schema is structurally identical — `open_index`
/// builds it identically and `Index::open_or_create` rejects a divergent on-disk one, so the four
/// fields are the same four ids in every slot — which means a handle for one slot holding another
/// slot's writer would land its document in that OTHER index and be told nothing. Carrying the slot
/// HERE turns that into a typed [`SlotMismatch`](TantivyFulltextError::SlotMismatch) at the op head,
/// and carrying the fields here is what lets the write path name no slot at all.
///
/// The caller owns it for a whole batch, queues through any number of handles on the slot — ONE AT A
/// TIME, which the exclusive [`WriteContext`](FulltextWrite::WriteContext) enforces — and
/// [`commit`](Self::commit)s it itself; dropping it releases the slot's writer lock and returns the
/// threads.
///
/// # Writers are TRANSIENT, and the resource ceiling is THREADS
///
/// An open writer is not free, and its dominant cost is OS threads rather than its arena. Every open
/// `IndexWriter` — including the single-threaded one [`writer`](TantivyStore::writer) mints — spawns
/// a fixed pool, so N writers held open at once cost a multiple of N threads: the exact constant is
/// platform- and version-specific, the LINEARITY is not. The `heap_bytes` arena is a lazily
/// committed CEILING rather than an upfront cost. Dropping the writer reclaims all of it. So a
/// driver that fans out across many slots must BOUND how many writers it holds open at once — a
/// foot-gun the heap budget alone would never reveal.
///
/// # Queueing two entries IN TURN is the shape, and each `upsert` takes a fresh reborrow
///
/// The entry arrives BUILT — a `TantivyDoc` the emission filled in — so this block names no record
/// face, no key trait and no newtype. That is the A′ dividend as a diff: the same doctest used to
/// need `Identifiable`, `Transformer`, `FulltextRecord`, `FulltextTable` and two hand-written key
/// codecs before it could queue one document, and a bare `i64` id could not be used at all without
/// one, because the engine's key trait was a local trait over foreign types.
///
/// The name in the `use` is the WRITE FACE now, not the base: the verb moved there with the scope
/// it spends, so a caller that only queues binds one trait and inherits no search.
///
/// ```no_run
/// use ingraph::{
/// AsyncFulltextWrite, Connected, SlotWriter, TantivyDoc, TantivyFulltext, TantivyStore,
/// };
///
/// /// The EMISSION's half, by hand: the record's source word, its id, its key and its text,
/// /// crossed into the engine's own entry. Every value here is a shipped row.
/// fn entry() -> TantivyDoc {
/// TantivyDoc::new("docs")
/// .with_identity(&7_i64)
/// .with_address(&(7_i64))
/// .with_body("a red car")
/// }
///
/// async fn queue_two_in_turn(store: &TantivyStore, face: &TantivyFulltext, writer: &mut SlotWriter) {
/// face
/// .upsert(Connected::new(store, &mut *writer), entry())
/// .await
/// .expect("the first entry queues");
/// face
/// .upsert(Connected::new(store, &mut *writer), entry())
/// .await
/// .expect("the second entry queues");
/// }
/// ```
///
/// A SHARED writer will not do — `upsert` cannot be HANDED one. That is the pin, and it is
/// deliberately this shape: two concurrent queuers would each need a shared context, so refusing the
/// context refuses the concurrency, and the keyed replace's delete-then-add pair is serialized.
///
/// ```compile_fail
/// # use ingraph::{
/// # AsyncFulltextWrite, Connected, SlotWriter, TantivyDoc, TantivyFulltext, TantivyStore,
/// # };
/// # fn entry() -> TantivyDoc {
/// # TantivyDoc::new("docs").with_identity(&7_i64).with_address(&(7_i64)).with_body("a red car")
/// # }
/// fn queue_through_a_shared_writer(
/// store: &TantivyStore,
/// face: &TantivyFulltext,
/// writer: &SlotWriter, // shared — what a second concurrent queuer would have to hold
/// ) {
/// let _ = face.upsert(Connected::new(store, writer), entry());
/// }
/// ```
///
/// Both blocks earn their keep only TOGETHER. Stable rustdoc runs a `compile_fail` block just far
/// enough to see it fail and never checks WHY, so a negative test can pass while testing nothing —
/// this one would still "pass" if the imports went stale. The twin above shares the imports and the
/// calls and must COMPILE, and the block here is written so that loosening the write context back to
/// a shared borrow would make it compile too. Between them, a regression turns one of the two red.
///
/// An EXCLUSIVE-borrow phrasing of the negative — two overlapping `&mut` reborrows, `E0499` — would
/// NOT do, and that is measured on the reference implementation: it keeps failing under a loosened
/// context, so it would pin nothing.
/// The Tantivy connection-manager and the shared connection its handles thread: ONE index root plus
/// the lazily-opened per-slot index cache.
///
/// It IS the [`FulltextEngine::Connection`] of the [`TantivyFulltext`] handles
/// [`fulltext`](Self::fulltext) mints — a handle holds only its slot and reaches its index through
/// `ctx.connection()`, so a slot's directory is opened exactly ONCE however many handles name it.
///
/// # The cache is two locks, and the split is what each one buys
///
/// The outer `Mutex` guards the map LOOKUP alone and is released before anything is opened; the
/// per-slot `Mutex` is what the open runs under. So one slot's open never blocks another slot's
/// lookup, and two racing first-uses of ONE never-opened slot converge on a single open rather than
/// both taking the create path. An init failure is not cached — a later call retries.
///
/// Not `Clone`: the cache is the manager's identity, and a clone would fork it into a second cache
/// over the same root. Share it by reference — `Connected::new(&store, scope)` — or behind an `Arc`.
/// The `body` options ONE LANE's field is built with — tokenized by `analyzer`, and KEPT only where
/// the declaration asked.
///
/// # It reproduces `TEXT` exactly at the default analyzer
///
/// tantivy's `TEXT` constant IS this construction with the tokenizer name `default`: fieldnorms on,
/// positions recorded, not stored, not fast. Building it out by hand is what lets the tokenizer name
/// vary, and `the_default_lane_is_tantivys_own_TEXT` pins the equality so an unfanned corpus's
/// schema stays byte-for-byte the one this backend has always written.
/// [`open_index`] over the UNFANNED corpus — one lane, keyed `und`, on tantivy's own `default`.
///
/// Test-only: it is the arrangement layer two produces for a declaration that named no lanes, spelled
/// once so the tests that predate the fan word read as they did.
/// Open (or create) the index in one slot's directory, at the posture `stored` asks for and cut into
/// the lanes `fan` names.
///
/// The directory must exist before `MmapDirectory` will open it, so a fresh slot is created first.
/// The BLOCKING construction face, and the one that HOLDS THE BODY.
///
/// Opening an index root is `MmapDirectory::open` and `Index::open_or_create` — syscalls that
/// return, with nothing to await anywhere beneath them. The inherent [`TantivyStore::open`] always
/// said so; this seam is where the trait face stops wrapping that fact in an `async fn`. It is the
/// shipped full-text citizen taking the posture [`LocalFsStore`](crate::LocalFsStore) already takes
/// on the blob side, for the same measured reason: the blocking face IS the act, and the async face
/// is what bridges to it.
/// The ASYNCHRONOUS construction face — the blocking body above, resolved immediately.
///
/// It exists so a deployment whose launch is bounded on the async face reaches this store at all,
/// and it DELEGATES rather than duplicating: there is exactly one opening here, and both faces name
/// it. Written out rather than bridged by a blanket, per the dual-mode law — a blanket from one face
/// to the other would hand every blocking store an async face and blind the bound that selects.
/// The Tantivy full-text face — a STATELESS keyed handle holding ONLY its slot name: no index, no
/// reader, no writer.
///
/// It threads the [`TantivyStore`] as its connection, so `upsert` queues into the writer the
/// caller
/// took on this slot and `search` reads this slot's reader. The original defect this two-layer shape
/// exists to prevent is a face that opened its own `Index`, so two faces over one directory
/// deadlocked on the writer lock — a handle opens nothing, and the store owns every index.
// THE BASE: what this engine SPEAKS and the address lifecycle it speaks it through. No verb, no
// lease, no GAT — those are the four faces below.
//
// R-FREE, and the whole `where` clause went with the record. What used to ride here —
// `R: TantivyRecord + FulltextTable`, `R::Key: TantivyKey + Send`, `R::Document: AsRef<str>` — was
// five bounds describing a record this engine never has to know about: the source word, the id, the
// key and the text all arrive inside the `TantivyDoc` the emission built, and the hit's address goes
// back out as this engine's own. There is nothing left to bound.
//
// `R::Key: 'static` was NOT among them, and that is what doing the work inline buys: a face that ran
// its search on a blocking pool would inherit `spawn_blocking`'s `T: Send + 'static` output bound.
/// THE BLOCKING READ FACE, and it holds no body of its own — [`search_slot`] is the body, and it was
/// already the body.
///
/// The claim a blocking face makes is STRUCTURAL, so it is worth stating what was measured before it
/// was made: nothing under this verb awaits. [`search_slot`] is a plain `fn` — it opens the slot
/// through the manager's cache, parses and checks the query, runs `Searcher::search` and reads each
/// hit's stored bytes — and the base impl's `ready(…)` wraps a `Result` that is already computed by
/// the time the wrapper is reached. So this face is that call with the wrapper never applied, which
/// is why it can be written at all: this module's own header states the same fact from the engine's
/// side (*tantivy is a SYNCHRONOUS engine*), and the reference implementation's `spawn_blocking` is
/// the shape this backend declined along with its runtime.
/// The ASYNCHRONOUS read face — the blocking body above, resolved immediately.
///
/// It DELEGATES rather than reaching [`search_slot`] a second time, which is the discipline
/// [`FulltextStore`] / [`AsyncFulltextStore`] already keep two layers up: there is one search here
/// and both faces name it, so a fix to one is a fix to both. Written out rather than bridged by a
/// blanket, per the dual-mode law — a blanket from one face to the other would hand every blocking
/// engine an async face and blind the bound that selects.
/// THE BLOCKING WRITE FACE — [`upsert_entry`] is the body, and both of its steps are in-memory queue
/// ops with no IO: `delete_term` pushes onto the delete queue and returns an opstamp, and
/// `add_document` sends to the indexing worker. Visibility waits on the caller's commit, which is
/// not this verb's act.
///
/// The EXCLUSIVE write scope is unchanged and remains load-bearing — see
/// [`WriteContext`](FulltextWrite::WriteContext). Taking the future off a signature changes nothing
/// about the delete-then-add pair's non-atomicity, and a face that relaxed the borrow would break
/// the same invariant in a new place.
/// The ASYNCHRONOUS write face — the blocking body above, resolved immediately, for
/// [`AsyncFulltextRead`]'s stated reason.
/// **THE WRITE LANE** — the four acts around [`upsert`](AsyncFulltextWrite::upsert) that a caller
/// holding only this engine cannot spell, answered in this backend's own terms.
///
/// Every member is the road an existing hand-written caller already takes, moved behind the seam
/// with nothing added: [`open`](FulltextLane::open) is
/// [`TantivyStore::writer`](TantivyStore::writer) at this handle's own slot,
/// [`scope`](FulltextLane::scope) is the `&mut SlotWriter` the write face's GAT already names,
/// [`entry`](FulltextLane::entry) is the [`TantivyDoc`] builder, and
/// [`publish`](FulltextLane::publish) is `commit` then `reload` — the pair that makes a write
/// findable rather than merely durable.
///
/// # `publish` DROPS the writer between the two steps, and that is load-bearing
///
/// A slot's writer holds tantivy's per-directory lockfile, and a subscriber opens one batch per
/// delivery — so a lane that reloaded while still holding the writer would leave the next delivery's
/// [`open`](FulltextLane::open) racing its own lock. The batch is taken BY VALUE for exactly this
/// reason: the drop is the release, and it is spelled where a reader can see it happen before the
/// reload.
///
/// # The ARENA is this backend's floor, and the knob for it is recorded rather than invented
///
/// [`MIN_WRITER_HEAP_BYTES`](TantivyStore::MIN_WRITER_HEAP_BYTES) is what a batch opens at. A
/// per-deployment arena is a real want and it has a home already — the node's own `options = "…"`
/// word, which is how every other launched node is tuned — so inventing a second one here would put
/// one knob in two places.
/// Queue one entry's keyed replace through `writer` — the body of [`FulltextWrite::upsert`].
///
/// The connection is not needed at all: the scope carries BOTH halves of a write — the slot's writer
/// and that slot's fields — so this path resolves no slot, takes no cache lock and names no path.
/// What is left to check is the PAIRING, one compare per document, before either in-memory side
/// effect. It also subsumes the slot guard: a [`SlotWriter`] exists only for a slot
/// [`writer`](TantivyStore::writer) accepted, so a handle naming an INVALID slot can never match
/// one.
///
/// It reads NOTHING about a record. The identity, the address and the text were decided where the
/// record's type was known, and what arrives here is a built entry — which is why this function has
/// no type parameter and no `where` clause left.
/// Run one query against `slot`'s committed snapshot — the body of [`FulltextRead::search`].
///
/// Generic over NOTHING: no record and — since A′ — no key either. What a hit carries out is the
/// stored address VERBATIM, in this engine's own vocabulary, and reading it back into a declaration's
/// key type is the emission's act one layer up. That is where the `Trailing` check went too: this
/// function cannot know how many values a key reads, so it does not pretend to.
///
/// The score is tantivy's native BM25, which is already higher-is-better — so, unlike a cosine
/// face's `1 - distance`, there is NO negation. The query runs against the SUBSET's fields with no
/// clause beside them, and the corpus statistics it is computed from are this slot's own, which is
/// what makes scores from DIFFERENT slots incomparable: those are different corpora.
///
/// # The subset resolves against the SCHEMA, which is where the honest answer is short today
///
/// A tantivy slot's schema carries exactly one searchable text field ([`SEARCHABLE_FIELD`]), so
/// [`All`](FulltextSubset::All) is that field — the whole of what this backend has ever searched,
/// byte for byte — and a [`These`](FulltextSubset::These) naming it is the same query. Any OTHER
/// name is [`UnheldColumn`](TantivyFulltextError::UnheldColumn), which is this backend reporting
/// that the per-field document has not landed rather than answering from a box that holds every
/// elected field's text at once.
///
/// The resolution is a list because that is what it becomes: `QueryParser::for_index` takes the
/// default fields a BARE term resolves against, so a schema with several searchable columns needs no
/// second mechanism here — the same walk hands it a longer list.
/// Resolve a [`FulltextSubset`] into the schema fields a bare term searches — validate-then-act, and
/// the whole of what a column selector costs this backend.
///
/// The slot's own [`Fields`] are passed in rather than looked up: the caller already opened the slot
/// and holds its field handles, and a second lookup here would be a second chance to resolve a
/// different one.
///
/// # A LANE IS A COLUMN, and that is what makes the read side of the fan need no new door
///
/// A slot's searchable columns are its lanes — `body` on an unfanned corpus, one per lane on a
/// fanned one — so asking ONE lane is a [`These`](FulltextSubset::These) naming it, and the probe a
/// router produced reaches this backend through the scope that already existed.
/// [`All`](FulltextSubset::All) is every lane, which on an unfanned corpus is the single `body` this
/// backend has always searched, byte for byte.
///
/// # Errors
///
/// [`TantivyFulltextError::EmptySubset`] for a [`These`](FulltextSubset::These) naming nothing;
/// [`TantivyFulltextError::UnheldColumn`] naming the FIRST column, in the caller's own order, that
/// this slot's schema does not hold.
/// Refuse a parsed query that names any field but [`SEARCHABLE_FIELD`].
///
/// Walks the WHOLE AST, because a field name can be anywhere in it: nested boolean clauses carry
/// their own sub-trees, a boost wraps one, and a leaf carries the name itself — on a literal, on a
/// range's or a set's or a regex's field, and on an `Exists`, where the field IS the query. A check
/// that looked only at the top level would pass `body:fox AND key:<base64>`, which is the shape an
/// attacker writes.
///
/// `None` is the BARE form (`fox`, `[a TO b]`) and is legal: it resolves against the parser's
/// default fields, which are the SCOPE's and therefore this slot's lanes and nothing else. So this
/// rejects exactly the EXPLICIT names, which is the whole of what the default-field argument does
/// not constrain.
///
/// The whitelist is the slot's own [`Fields`] rather than one name, and the DIRECTION is unchanged:
/// a lane's field is admitted because the roster carried it, and every other field of the schema —
/// the stored `key` above all — is refused because it is not in the roster.
///
/// # Errors
///
/// [`TantivyFulltextError::UnsearchableField`] naming the first offending field in walk order.
/// **THE FACTORY VISITOR** — layer two's machine for a tantivy-backed resource: shown one declared
/// type at a time, it creates every corpus that type owns in this mount.
///
/// ```text
/// Shared<Ft> ──► TantivySlotMaker<Ft> ──next_type::<Media>()──► Media's blueprint
/// │ │
/// │ per corpus: create_slot(schema, knobs) │
/// └──────────────► TantivyStore ◄───────────────┘
/// ```
///
/// # It is the AUTHOR'S MACHINE, and this one happens to ship
///
/// A slot maker holds its own connection and its own per-slot values, which is why the walk hands it
/// nothing but types: `#[ingraph::resource(tantivy)]` names this as its initializer because the
/// framework wrote that engine, and a foreign resource's author writes theirs beside their own
/// faces. Nothing about the walk is specialised to it.
///
/// # THE KNOB TABLE is where the [`Options`](crate::FulltextEngine::Options) seat lands
///
/// The blueprint is a `const` and carries only what a DECLARATION states; a tokenizer choice is a
/// value a DEPLOYMENT decides, and it arrives at boot. So the visitor holds the per-slot table, and
/// its VALUE TYPE is the projection — `<TantivyFulltext as FulltextEngine>::Options` — which is what
/// makes the seat a real position rather than a reservation. It is EMPTY on the launch's own path
/// today: the seat is `()` at this backend, so there is nothing to write into it and no document row
/// invented to pretend otherwise. [`with_knobs`](Self::with_knobs) is the door a hand-driven walk
/// fills it through.
///
/// # It records what it MADE
///
/// [`made`](Self::made) is the corpora this walk created, in walk order — which is how a deployment,
/// or a test, states that the walk ran at all. It is the only observation the visitor keeps.
///
/// # Under `runtime`, where the rest of this file is under none
///
/// It is the one item here whose type PARAMETER is a tier's: `R: AsyncResource`, and the
/// `Shared<R>` it holds, are the shareable-resource layer's and ride that word. The engine itself —
/// the connection, the slot handles, the writer, the term codec — names none of it, so a build
/// taking the full-text backend without the drive layer gets every door and not this walk. What the
/// walk is FOR is a launch, and a build with no launch has nothing to run one with.
/// The BLOCKING face, because opening a tantivy index is two syscalls and no await — the same
/// measurement that puts this store on [`FulltextStore`] rather than on its awaited twin.
///
/// The `Db` is the RESOURCE and not the engine, which is the grain the whole layer turns on: two
/// deployments' stores are two resource types and therefore two habitats, so a declaration electing
/// into one of them is `E0277` at the other. An engine-keyed habitat would have collapsed them into
/// one and made a second tantivy mount unaddressable.