CodecCollector.java.html
259 KB
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
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>CodecCollector.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.codec.util</a> > <span class="el_source">CodecCollector.java</span></div><h1>CodecCollector.java</h1><pre class="source lang-java linenums">package mtas.codec.util;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.regex.Pattern;
import mtas.analysis.token.MtasToken;
import mtas.analysis.token.MtasTokenString;
import mtas.codec.MtasCodecPostingsFormat;
import mtas.codec.tree.IntervalTreeNodeData;
import mtas.codec.util.CodecComponent.ComponentDocument;
import mtas.codec.util.CodecComponent.ComponentFacet;
import mtas.codec.util.CodecComponent.ComponentField;
import mtas.codec.util.CodecComponent.ComponentGroup;
import mtas.codec.util.CodecComponent.ComponentCollection;
import mtas.codec.util.CodecComponent.ComponentKwic;
import mtas.codec.util.CodecComponent.ComponentList;
import mtas.codec.util.CodecComponent.ComponentPosition;
import mtas.codec.util.CodecComponent.ComponentSpan;
import mtas.codec.util.CodecComponent.ComponentTermVector;
import mtas.codec.util.CodecComponent.ComponentToken;
import mtas.codec.util.CodecComponent.GroupHit;
import mtas.codec.util.CodecComponent.KwicHit;
import mtas.codec.util.CodecComponent.KwicToken;
import mtas.codec.util.CodecComponent.ListHit;
import mtas.codec.util.CodecComponent.ListToken;
import mtas.codec.util.CodecComponent.Match;
import mtas.codec.util.CodecComponent.SubComponentFunction;
import mtas.codec.util.CodecInfo.IndexDoc;
import mtas.codec.util.CodecSearchTree.MtasTreeHit;
import mtas.codec.util.collector.MtasDataCollector;
import mtas.parser.function.ParseException;
import mtas.parser.function.util.MtasFunctionParserFunction;
import mtas.search.spans.MtasSpanAndQuery;
import mtas.search.spans.MtasSpanFollowedByQuery;
import mtas.search.spans.MtasSpanMatchAllQuery;
import mtas.search.spans.MtasSpanPrecededByQuery;
import mtas.search.spans.MtasSpanSequenceItem;
import mtas.search.spans.MtasSpanSequenceQuery;
import mtas.search.spans.MtasSpanTermQuery;
import mtas.search.spans.util.MtasSpanQuery;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.spans.SpanWeight;
import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.ByteRunAutomaton;
import org.apache.lucene.util.automaton.CompiledAutomaton;
import org.apache.lucene.util.automaton.RegExp;
import org.apache.solr.legacy.LegacyNumericUtils;
import org.apache.solr.schema.NumberType;
import com.sun.tools.javac.code.Attribute.Array;
/**
* The Class CodecCollector.
*/
public class CodecCollector {
/** The Constant log. */
<span class="fc" id="L98"> private static final Log log = LogFactory.getLog(CodecCollector.class);</span>
/**
* Instantiates a new codec collector.
*/
<span class="nc" id="L103"> private CodecCollector() {</span>
// don't do anything
<span class="nc" id="L105"> }</span>
/**
* Collect field.
*
* @param field
* the field
* @param searcher
* the searcher
* @param reader
* the reader
* @param rawReader
* the raw reader
* @param fullDocList
* the full doc list
* @param fullDocSet
* the full doc set
* @param fieldInfo
* the field info
* @param spansQueryWeight
* the spans query weight
* @throws IllegalAccessException
* the illegal access exception
* @throws IllegalArgumentException
* the illegal argument exception
* @throws InvocationTargetException
* the invocation target exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void collectField(String field, IndexSearcher searcher,
IndexReader reader, IndexReader rawReader, List<Integer> fullDocList,
List<Integer> fullDocSet, ComponentField fieldInfo,
Map<MtasSpanQuery, SpanWeight> spansQueryWeight)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, IOException {
<span class="fc" id="L142"> Map<Integer, List<Integer>> docSets = new HashMap<>();</span>
<span class="fc" id="L144"> ListIterator<LeafReaderContext> iterator = reader.leaves().listIterator();</span>
<span class="fc bfc" id="L145" title="All 2 branches covered."> while (iterator.hasNext()) {</span>
<span class="fc" id="L146"> LeafReaderContext lrc = iterator.next();</span>
<span class="fc" id="L147"> LeafReader r = lrc.reader();</span>
// compute relevant docSet/docList
<span class="fc" id="L150"> List<Integer> docSet = null;</span>
<span class="fc" id="L151"> List<Integer> docList = null;</span>
<span class="fc bfc" id="L152" title="All 2 branches covered."> if (fullDocSet != null) {</span>
<span class="fc" id="L153"> docSet = new ArrayList<>();</span>
<span class="fc" id="L154"> docSets.put(lrc.ord, docSet);</span>
<span class="fc" id="L155"> Iterator<Integer> docSetIterator = fullDocSet.iterator();</span>
<span class="fc" id="L156"> Integer docSetId = null;</span>
<span class="fc" id="L157"> Bits liveDocs = lrc.reader().getLiveDocs();</span>
<span class="fc bfc" id="L158" title="All 2 branches covered."> while (docSetIterator.hasNext()) {</span>
<span class="fc" id="L159"> docSetId = docSetIterator.next();</span>
// just to make sure to ignore deleted documents
<span class="fc bfc" id="L161" title="All 2 branches covered."> if ((docSetId >= lrc.docBase)</span>
<span class="fc bfc" id="L162" title="All 4 branches covered."> && (docSetId < lrc.docBase + lrc.reader().maxDoc())</span>
<span class="pc bpc" id="L163" title="1 of 2 branches missed."> && (liveDocs == null || liveDocs.get((docSetId - lrc.docBase)))) {</span>
<span class="fc" id="L164"> docSet.add(docSetId);</span>
}
}
<span class="fc" id="L167"> Collections.sort(docSet);</span>
}
<span class="pc bpc" id="L169" title="1 of 2 branches missed."> if (fullDocList != null) {</span>
<span class="fc" id="L170"> docList = new ArrayList<>();</span>
<span class="fc" id="L171"> Iterator<Integer> docListIterator = fullDocList.iterator();</span>
<span class="fc" id="L172"> Integer docListId = null;</span>
<span class="fc bfc" id="L173" title="All 2 branches covered."> while (docListIterator.hasNext()) {</span>
<span class="fc" id="L174"> docListId = docListIterator.next();</span>
<span class="fc bfc" id="L175" title="All 2 branches covered."> if ((docListId >= lrc.docBase)</span>
<span class="fc bfc" id="L176" title="All 2 branches covered."> && (docListId < lrc.docBase + lrc.reader().maxDoc())) {</span>
<span class="fc" id="L177"> docList.add(docListId);</span>
}
}
<span class="fc" id="L180"> Collections.sort(docList);</span>
}
<span class="fc" id="L183"> Terms t = rawReader.leaves().get(lrc.ord).reader().terms(field);</span>
<span class="pc bpc" id="L184" title="1 of 2 branches missed."> CodecInfo mtasCodecInfo = t == null ? null</span>
<span class="fc" id="L185"> : CodecInfo.getCodecInfoFromTerms(t);</span>
<span class="fc" id="L187"> collectSpansPositionsAndTokens(spansQueryWeight, searcher, mtasCodecInfo,</span>
r, lrc, field, t, docSet, docList, fieldInfo,
<span class="fc" id="L189"> rawReader.leaves().get(lrc.ord).reader().getFieldInfos());</span>
<span class="fc" id="L190"> collectPrefixes(rawReader.leaves().get(lrc.ord).reader().getFieldInfos(),</span>
field, fieldInfo);
<span class="fc" id="L192"> }</span>
// check termvectors
<span class="fc bfc" id="L195" title="All 2 branches covered."> if (!fieldInfo.termVectorList.isEmpty()</span>
<span class="fc bfc" id="L196" title="All 2 branches covered."> && needSecondRoundTermvector(fieldInfo.termVectorList)) {</span>
// check positions
<span class="fc" id="L198"> boolean needPositions = false;</span>
<span class="pc bpc" id="L199" title="1 of 2 branches missed."> if (!fieldInfo.termVectorList.isEmpty()) {</span>
<span class="fc bfc" id="L200" title="All 2 branches covered."> for (ComponentTermVector ctv : fieldInfo.termVectorList) {</span>
<span class="pc bpc" id="L201" title="1 of 2 branches missed."> if (!needPositions) {</span>
<span class="pc bpc" id="L202" title="1 of 2 branches missed."> needPositions = ctv.functions != null ? ctv.functionNeedPositions()</span>
: needPositions;
}
<span class="fc" id="L205"> }</span>
}
<span class="fc" id="L207"> Map<Integer, Integer> positionsData = null;</span>
// loop
<span class="fc" id="L210"> iterator = reader.leaves().listIterator();</span>
<span class="fc bfc" id="L211" title="All 2 branches covered."> while (iterator.hasNext()) {</span>
<span class="fc" id="L212"> LeafReaderContext lrc = iterator.next();</span>
<span class="fc" id="L213"> LeafReader r = lrc.reader();</span>
<span class="fc" id="L214"> List<Integer> docSet = docSets.get(lrc.ord);</span>
<span class="fc" id="L215"> Terms t = rawReader.leaves().get(lrc.ord).reader().terms(field);</span>
<span class="pc bpc" id="L216" title="1 of 2 branches missed."> if (needPositions) {</span>
<span class="nc bnc" id="L217" title="All 2 branches missed."> CodecInfo mtasCodecInfo = t == null ? null</span>
<span class="nc" id="L218"> : CodecInfo.getCodecInfoFromTerms(t);</span>
<span class="nc" id="L219"> positionsData = computePositions(mtasCodecInfo, r, lrc, field,</span>
docSet);
}
<span class="fc" id="L222"> createTermvectorSecondRound(fieldInfo.termVectorList, positionsData,</span>
<span class="fc" id="L223"> docSets.get(lrc.ord), t, r, lrc);</span>
<span class="fc" id="L224"> }</span>
}
<span class="fc" id="L226"> }</span>
/**
* Collect collection.
*
* @param reader
* the reader
* @param docSet
* the doc set
* @param collectionInfo
* the collection info
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void collectCollection(IndexReader reader, List<Integer> docSet,
ComponentCollection collectionInfo) throws IOException {
<span class="fc bfc" id="L242" title="All 2 branches covered."> if (collectionInfo.action().equals(ComponentCollection.ACTION_CHECK)) {</span>
// can't do anything in lucene for check
<span class="fc" id="L244"> } else if (collectionInfo.action()</span>
<span class="fc bfc" id="L245" title="All 2 branches covered."> .equals(ComponentCollection.ACTION_LIST)) {</span>
// can't do anything in lucene for list
<span class="fc" id="L247"> } else if (collectionInfo.action()</span>
<span class="fc bfc" id="L248" title="All 2 branches covered."> .equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="fc" id="L249"> BytesRef term = null;</span>
<span class="fc" id="L250"> PostingsEnum postingsEnum = null;</span>
Integer docId;
<span class="fc" id="L252"> Integer termDocId = -1;</span>
Terms terms;
LeafReaderContext lrc;
LeafReader r;
<span class="fc" id="L256"> ListIterator<LeafReaderContext> iterator = reader.leaves().listIterator();</span>
<span class="fc bfc" id="L257" title="All 2 branches covered."> while (iterator.hasNext()) {</span>
<span class="fc" id="L258"> lrc = iterator.next();</span>
<span class="fc" id="L259"> r = lrc.reader();</span>
<span class="fc bfc" id="L260" title="All 2 branches covered."> for (String field : collectionInfo.fields()) {</span>
<span class="pc bpc" id="L261" title="1 of 2 branches missed."> if ((terms = r.terms(field)) != null) {</span>
<span class="fc" id="L262"> TermsEnum termsEnum = terms.iterator();</span>
<span class="fc bfc" id="L263" title="All 2 branches covered."> while ((term = termsEnum.next()) != null) {</span>
<span class="fc" id="L264"> Iterator<Integer> docIterator = docSet.iterator();</span>
<span class="fc" id="L265"> postingsEnum = termsEnum.postings(postingsEnum,</span>
PostingsEnum.NONE);
<span class="fc" id="L267"> termDocId = -1;</span>
<span class="pc bpc" id="L268" title="1 of 2 branches missed."> while (docIterator.hasNext()) {</span>
<span class="fc" id="L269"> docId = docIterator.next() - lrc.docBase;</span>
<span class="fc bfc" id="L270" title="All 4 branches covered."> if ((docId >= termDocId) && ((docId.equals(termDocId))</span>
<span class="fc" id="L271"> || ((termDocId = postingsEnum.advance(docId))</span>
<span class="fc bfc" id="L272" title="All 2 branches covered."> .equals(docId)))) {</span>
<span class="fc" id="L273"> collectionInfo.addValue(term.utf8ToString());</span>
<span class="fc" id="L274"> break;</span>
}
<span class="pc bpc" id="L276" title="1 of 2 branches missed."> if (termDocId.equals(PostingsEnum.NO_MORE_DOCS)) {</span>
<span class="nc" id="L277"> break;</span>
}
}
<span class="fc" id="L280"> }</span>
}
<span class="fc" id="L282"> }</span>
}
}
<span class="fc" id="L285"> }</span>
/**
* Collect spans positions and tokens.
*
* @param spansQueryWeight
* the spans query weight
* @param searcher
* the searcher
* @param mtasCodecInfo
* the mtas codec info
* @param r
* the r
* @param lrc
* the lrc
* @param field
* the field
* @param t
* the t
* @param docSet
* the doc set
* @param docList
* the doc list
* @param fieldInfo
* the field info
* @param fieldInfos
* the field infos
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void collectSpansPositionsAndTokens(
Map<MtasSpanQuery, SpanWeight> spansQueryWeight, IndexSearcher searcher,
CodecInfo mtasCodecInfo, LeafReader r, LeafReaderContext lrc,
String field, Terms t, List<Integer> docSet, List<Integer> docList,
ComponentField fieldInfo, FieldInfos fieldInfos) throws IOException {
<span class="fc" id="L321"> boolean needSpans = false;</span>
<span class="fc" id="L322"> boolean needPositions = false;</span>
<span class="fc" id="L323"> boolean needTokens = false;</span>
// results
<span class="fc" id="L326"> Map<Integer, Integer> positionsData = null;</span>
<span class="fc" id="L327"> Map<Integer, Integer> tokensData = null;</span>
<span class="fc" id="L328"> Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData = null;</span>
<span class="fc" id="L329"> Map<MtasSpanQuery, Map<Integer, List<Match>>> spansMatchData = null;</span>
<span class="fc" id="L330"> Map<String, SortedMap<String, int[]>> facetData = null;</span>
<span class="fc" id="L331"> Map<String, String> facetDataType = null;</span>
// collect position stats
<span class="fc bfc" id="L334" title="All 2 branches covered."> if (!fieldInfo.statsPositionList.isEmpty()) {</span>
<span class="fc" id="L335"> needPositions = true;</span>
}
// collect token stats
<span class="fc bfc" id="L338" title="All 2 branches covered."> if (!fieldInfo.statsTokenList.isEmpty()) {</span>
<span class="fc" id="L339"> needTokens = true;</span>
}
<span class="fc bfc" id="L341" title="All 2 branches covered."> if (!fieldInfo.termVectorList.isEmpty()) {</span>
<span class="fc bfc" id="L342" title="All 2 branches covered."> for (ComponentTermVector ctv : fieldInfo.termVectorList) {</span>
<span class="fc bfc" id="L343" title="All 2 branches covered."> if (!needPositions) {</span>
<span class="pc bpc" id="L344" title="1 of 2 branches missed."> needPositions = (ctv.functions == null</span>
<span class="pc" id="L345"> ? ctv.subComponentFunction.parserFunction.needPositions()</span>
<span class="fc" id="L346"> : ctv.functionNeedPositions());</span>
}
<span class="fc" id="L348"> }</span>
}
// compute from spans for selected docs
<span class="fc bfc" id="L352" title="All 2 branches covered."> if (!fieldInfo.spanQueryList.isEmpty()) {</span>
// check for statsSpans
<span class="fc" id="L354"> spansNumberData = new HashMap<>();</span>
<span class="fc" id="L355"> spansMatchData = new HashMap<>();</span>
<span class="fc" id="L356"> facetData = new HashMap<>();</span>
<span class="fc" id="L357"> facetDataType = new HashMap<>();</span>
// spans
<span class="fc bfc" id="L359" title="All 2 branches covered."> if (!fieldInfo.statsSpanList.isEmpty()) {</span>
<span class="fc bfc" id="L360" title="All 2 branches covered."> for (ComponentSpan cs : fieldInfo.statsSpanList) {</span>
<span class="fc bfc" id="L361" title="All 2 branches covered."> needPositions = (!needPositions) ? cs.parser.needPositions()</span>
: needPositions;
<span class="fc bfc" id="L363" title="All 2 branches covered."> needPositions = (!needPositions) ? cs.functionNeedPositions()</span>
: needPositions;
<span class="pc bpc" id="L365" title="1 of 4 branches missed."> needSpans = (!needSpans) ? cs.parser.needArgumentsNumber() > 0</span>
: needSpans;
<span class="fc" id="L367"> HashSet<Integer> arguments = cs.parser.needArgument();</span>
<span class="fc" id="L368"> arguments.addAll(cs.functionNeedArguments());</span>
<span class="fc bfc" id="L369" title="All 2 branches covered."> for (int a : arguments) {</span>
<span class="pc bpc" id="L370" title="1 of 2 branches missed."> if (cs.queries.length > a) {</span>
<span class="fc" id="L371"> MtasSpanQuery q = cs.queries[a];</span>
<span class="fc bfc" id="L372" title="All 2 branches covered."> if (!spansNumberData.containsKey(q)) {</span>
<span class="fc" id="L373"> spansNumberData.put(q, new HashMap<Integer, Integer>());</span>
}
}
<span class="fc" id="L376"> }</span>
<span class="fc" id="L377"> }</span>
}
// kwic
<span class="pc bpc" id="L380" title="1 of 2 branches missed."> if (!fieldInfo.kwicList.isEmpty()) {</span>
<span class="nc" id="L381"> needSpans = true;</span>
<span class="nc bnc" id="L382" title="All 2 branches missed."> for (ComponentKwic ck : fieldInfo.kwicList) {</span>
<span class="nc bnc" id="L383" title="All 2 branches missed."> if (!spansMatchData.containsKey(ck.query)) {</span>
<span class="nc" id="L384"> spansMatchData.put(ck.query, new HashMap<Integer, List<Match>>());</span>
}
<span class="nc" id="L386"> }</span>
}
// list
<span class="pc bpc" id="L389" title="1 of 2 branches missed."> if (!fieldInfo.listList.isEmpty()) {</span>
<span class="nc" id="L390"> needSpans = true;</span>
<span class="nc bnc" id="L391" title="All 2 branches missed."> for (ComponentList cl : fieldInfo.listList) {</span>
<span class="nc bnc" id="L392" title="All 2 branches missed."> if (!spansMatchData.containsKey(cl.spanQuery)) {</span>
<span class="nc bnc" id="L393" title="All 2 branches missed."> if (cl.number > 0) {</span>
// only if needed
<span class="nc bnc" id="L395" title="All 2 branches missed."> if (cl.position < (cl.start + cl.number)) {</span>
<span class="nc" id="L396"> spansMatchData.put(cl.spanQuery,</span>
new HashMap<Integer, List<Match>>());
} else {
<span class="nc" id="L399"> spansNumberData.put(cl.spanQuery,</span>
new HashMap<Integer, Integer>());
}
<span class="nc bnc" id="L402" title="All 2 branches missed."> } else if (!spansNumberData.containsKey(cl.spanQuery)) {</span>
<span class="nc" id="L403"> spansNumberData.put(cl.spanQuery,</span>
new HashMap<Integer, Integer>());
}
}
<span class="nc" id="L407"> }</span>
}
// group
<span class="fc bfc" id="L410" title="All 2 branches covered."> if (!fieldInfo.groupList.isEmpty()) {</span>
<span class="fc" id="L411"> needSpans = true;</span>
<span class="fc bfc" id="L412" title="All 2 branches covered."> for (ComponentGroup cg : fieldInfo.groupList) {</span>
<span class="pc bpc" id="L413" title="1 of 2 branches missed."> if (!spansMatchData.containsKey(cg.spanQuery)) {</span>
<span class="fc" id="L414"> spansMatchData.put(cg.spanQuery,</span>
new HashMap<Integer, List<Match>>());
}
<span class="fc" id="L417"> }</span>
}
// facet
<span class="pc bpc" id="L420" title="1 of 2 branches missed."> if (!fieldInfo.facetList.isEmpty()) {</span>
<span class="nc bnc" id="L421" title="All 2 branches missed."> for (ComponentFacet cf : fieldInfo.facetList) {</span>
<span class="nc bnc" id="L422" title="All 2 branches missed."> needPositions = !needPositions ? cf.baseParserNeedPositions()</span>
: needPositions;
<span class="nc bnc" id="L424" title="All 2 branches missed."> needPositions = !needPositions ? cf.functionNeedPositions()</span>
: needPositions;
<span class="nc bnc" id="L426" title="All 2 branches missed."> for (int i = 0; i < cf.baseFields.length; i++) {</span>
<span class="nc bnc" id="L427" title="All 4 branches missed."> needSpans = !needSpans ? cf.baseParsers[i].needArgumentsNumber() > 0</span>
: needSpans;
<span class="nc" id="L429"> HashSet<Integer> arguments = cf.baseParsers[i].needArgument();</span>
<span class="nc bnc" id="L430" title="All 2 branches missed."> for (int a : arguments) {</span>
<span class="nc bnc" id="L431" title="All 2 branches missed."> if (cf.spanQueries.length > a) {</span>
<span class="nc" id="L432"> MtasSpanQuery q = cf.spanQueries[a];</span>
<span class="nc bnc" id="L433" title="All 2 branches missed."> if (!spansNumberData.containsKey(q)) {</span>
<span class="nc" id="L434"> spansNumberData.put(q, new HashMap<Integer, Integer>());</span>
}
}
<span class="nc" id="L437"> }</span>
<span class="nc bnc" id="L438" title="All 2 branches missed."> for (MtasFunctionParserFunction function : cf.baseFunctionParserFunctions[i]) {</span>
<span class="nc bnc" id="L439" title="All 4 branches missed."> needSpans = !needSpans ? function.needArgumentsNumber() > 0</span>
: needSpans;
<span class="nc" id="L441"> arguments = function.needArgument();</span>
<span class="nc bnc" id="L442" title="All 2 branches missed."> for (int a : arguments) {</span>
<span class="nc bnc" id="L443" title="All 2 branches missed."> if (cf.spanQueries.length > a) {</span>
<span class="nc" id="L444"> MtasSpanQuery q = cf.spanQueries[a];</span>
<span class="nc bnc" id="L445" title="All 2 branches missed."> if (!spansNumberData.containsKey(q)) {</span>
<span class="nc" id="L446"> spansNumberData.put(q, new HashMap<Integer, Integer>());</span>
}
}
<span class="nc" id="L449"> }</span>
}
<span class="nc bnc" id="L451" title="All 2 branches missed."> if (!facetData.containsKey(cf.baseFields[i])) {</span>
<span class="nc" id="L452"> facetData.put(cf.baseFields[i], new TreeMap<String, int[]>());</span>
<span class="nc" id="L453"> facetDataType.put(cf.baseFields[i], cf.baseFieldTypes[i]);</span>
}
}
<span class="nc" id="L456"> }</span>
}
// termvector
<span class="pc bpc" id="L459" title="1 of 2 branches missed."> if (!fieldInfo.termVectorList.isEmpty()) {</span>
<span class="nc bnc" id="L460" title="All 2 branches missed."> for (ComponentTermVector ctv : fieldInfo.termVectorList) {</span>
<span class="nc bnc" id="L461" title="All 2 branches missed."> if ((ctv.subComponentFunction.parserFunction != null</span>
<span class="nc bnc" id="L462" title="All 4 branches missed."> && ctv.subComponentFunction.parserFunction.needPositions())</span>
<span class="nc bnc" id="L463" title="All 2 branches missed."> || (ctv.functions != null && ctv.functionNeedPositions())) {</span>
<span class="nc" id="L464"> needPositions = true;</span>
}
<span class="nc" id="L466"> }</span>
}
}
<span class="fc bfc" id="L470" title="All 2 branches covered."> if (needSpans) {</span>
Map<Integer, Integer> numberData;
Map<Integer, List<Match>> matchData;
// collect values for facetFields
<span class="pc bpc" id="L474" title="1 of 2 branches missed."> for (Entry<String, SortedMap<String, int[]>> entry : facetData</span>
<span class="fc" id="L475"> .entrySet()) {</span>
<span class="nc" id="L476"> FieldInfo fi = fieldInfos.fieldInfo(entry.getKey());</span>
<span class="nc bnc" id="L477" title="All 2 branches missed."> if (fi != null) {</span>
//prefer to use pointvalue
<span class="nc bnc" id="L479" title="All 2 branches missed."> if (!fi.getDocValuesType().equals(DocValuesType.NONE)) { </span>
<span class="nc" id="L480"> Iterator<Integer> docIterator = docSet.iterator();</span>
//numeric or sorted
<span class="nc bnc" id="L482" title="All 4 branches missed."> if(fi.getDocValuesType().equals(DocValuesType.NUMERIC) || fi.getDocValuesType().equals(DocValuesType.SORTED)) {</span>
//create map of values to corresponding docIds
<span class="nc" id="L484"> Map<Object, List<Integer>> facetDataSubList = new HashMap<>();</span>
//numeric
<span class="nc bnc" id="L486" title="All 2 branches missed."> if(fi.getDocValuesType().equals(DocValuesType.NUMERIC)) {</span>
<span class="nc" id="L487"> NumericDocValues docValues = r.getContext().reader()</span>
<span class="nc" id="L488"> .getNumericDocValues(entry.getKey()); </span>
int docId;
<span class="nc bnc" id="L490" title="All 2 branches missed."> while (docIterator.hasNext()) {</span>
<span class="nc" id="L491"> docId = docIterator.next() - lrc.docBase;</span>
<span class="nc bnc" id="L492" title="All 2 branches missed."> if(docValues.advanceExact(docId)) {</span>
<span class="nc" id="L493"> long value = docValues.longValue();</span>
<span class="nc bnc" id="L494" title="All 2 branches missed."> if(!facetDataSubList.containsKey(value)) {</span>
<span class="nc" id="L495"> List<Integer> facetDataSubListItem = new ArrayList<Integer>();</span>
<span class="nc" id="L496"> facetDataSubListItem.add(docId+lrc.docBase);</span>
<span class="nc" id="L497"> facetDataSubList.put(value, facetDataSubListItem); </span>
<span class="nc" id="L498"> } else {</span>
<span class="nc" id="L499"> facetDataSubList.get(value).add(docId+lrc.docBase);</span>
}
<span class="nc" id="L501"> } </span>
}
//sorted
<span class="nc bnc" id="L504" title="All 2 branches missed."> } else if(fi.getDocValuesType().equals(DocValuesType.SORTED)) { </span>
<span class="nc" id="L505"> SortedDocValues docValues = r.getContext().reader().getSortedDocValues(entry.getKey());</span>
int docId;
<span class="nc bnc" id="L507" title="All 2 branches missed."> while (docIterator.hasNext()) {</span>
<span class="nc" id="L508"> docId = docIterator.next() - lrc.docBase;</span>
<span class="nc bnc" id="L509" title="All 2 branches missed."> if(docValues.advanceExact(docId)) {</span>
<span class="nc" id="L510"> String value = docValues.binaryValue().utf8ToString();</span>
<span class="nc bnc" id="L511" title="All 2 branches missed."> if(!facetDataSubList.containsKey(value)) {</span>
<span class="nc" id="L512"> List<Integer> facetDataSubListItem = new ArrayList<Integer>();</span>
<span class="nc" id="L513"> facetDataSubListItem.add(docId+lrc.docBase);</span>
<span class="nc" id="L514"> facetDataSubList.put(value, facetDataSubListItem); </span>
<span class="nc" id="L515"> } else {</span>
<span class="nc" id="L516"> facetDataSubList.get(value).add(docId+lrc.docBase);</span>
}
<span class="nc" id="L518"> } </span>
}
}
<span class="nc bnc" id="L521" title="All 2 branches missed."> if(!facetDataSubList.isEmpty()) {</span>
<span class="nc" id="L522"> SortedMap<String, int[]> facetDataList = entry.getValue();</span>
<span class="nc" id="L523"> SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");</span>
<span class="nc" id="L524"> sdf.setTimeZone(TimeZone.getTimeZone("GMT"));</span>
<span class="nc bnc" id="L525" title="All 2 branches missed."> for(Entry<Object,List<Integer>> facetEntry : facetDataSubList.entrySet()) {</span>
<span class="nc" id="L526"> int[] docIdList = facetEntry.getValue().stream().mapToInt(i -> i).toArray();</span>
String termValue;
<span class="nc bnc" id="L528" title="All 2 branches missed."> if(facetDataType.get(entry.getKey()).equals(NumberType.DATE.name())) {</span>
<span class="nc" id="L529"> Date date = new Date((Long) facetEntry.getKey());</span>
<span class="nc" id="L530"> termValue = sdf.format(date);</span>
<span class="nc" id="L531"> } else {</span>
<span class="nc" id="L532"> termValue = facetEntry.getKey().toString();</span>
}
<span class="nc bnc" id="L534" title="All 2 branches missed."> if (!facetDataList.containsKey(termValue)) {</span>
<span class="nc" id="L535"> facetDataList.put(termValue, docIdList);</span>
} else {
<span class="nc" id="L537"> int[] oldList = facetDataList.get(termValue);</span>
<span class="nc" id="L538"> int[] newList = new int[oldList.length</span>
+ docIdList.length];
<span class="nc" id="L540"> System.arraycopy(oldList, 0, newList, 0, oldList.length);</span>
<span class="nc" id="L541"> System.arraycopy(docIdList, 0, newList,</span>
oldList.length, docIdList.length);
<span class="nc" id="L543"> facetDataList.put(termValue, newList);</span>
}
<span class="nc" id="L545"> } </span>
}
<span class="nc" id="L547"> } else {</span>
<span class="nc" id="L548"> throw new IOException("facets for docValues of type "+fi.getDocValuesType()+" not implemented");</span>
}
<span class="nc bnc" id="L550" title="All 2 branches missed."> } else if(!docSet.isEmpty()) {</span>
<span class="nc" id="L551"> if(facetDataType.get(entry.getKey())</span>
<span class="nc bnc" id="L552" title="All 2 branches missed."> .equals(ComponentFacet.TYPE_POINTFIELD_WITHOUT_DOCVALUES)) {</span>
<span class="nc" id="L553"> throw new IOException("can't create facets for pointField without docValues");</span>
}
<span class="nc" id="L555"> Terms fft = r.terms(entry.getKey());</span>
<span class="nc bnc" id="L556" title="All 2 branches missed."> if (fft != null) { </span>
<span class="nc" id="L557"> TermsEnum termsEnum = fft.iterator();</span>
<span class="nc" id="L558"> BytesRef term = null;</span>
<span class="nc" id="L559"> PostingsEnum postingsEnum = null;</span>
<span class="nc" id="L560"> SortedMap<String, int[]> facetDataList = entry.getValue();</span>
<span class="nc bnc" id="L561" title="All 2 branches missed."> while ((term = termsEnum.next()) != null) {</span>
int docId;
<span class="nc" id="L563"> int termDocId = -1;</span>
<span class="nc" id="L564"> int[] facetDataSublist = new int[docSet.size()];</span>
<span class="nc" id="L565"> int facetDataSublistCounter = 0;</span>
<span class="nc" id="L566"> Iterator<Integer> docIterator = docSet.iterator();</span>
<span class="nc" id="L567"> postingsEnum = termsEnum.postings(postingsEnum);</span>
<span class="nc bnc" id="L568" title="All 2 branches missed."> while (docIterator.hasNext()) {</span>
<span class="nc" id="L569"> docId = docIterator.next() - lrc.docBase;</span>
<span class="nc bnc" id="L570" title="All 4 branches missed."> if (docId >= termDocId</span>
&& ((docId == termDocId) || ((termDocId = postingsEnum
<span class="nc bnc" id="L572" title="All 2 branches missed."> .advance(docId)) == docId))) {</span>
<span class="nc" id="L573"> facetDataSublist[facetDataSublistCounter] = docId</span>
+ lrc.docBase;
<span class="nc" id="L575"> facetDataSublistCounter++;</span>
}
}
<span class="nc bnc" id="L578" title="All 2 branches missed."> if (facetDataSublistCounter > 0) {</span>
<span class="nc" id="L579"> String termValue = null;</span>
<span class="nc" id="L580"> if (facetDataType.get(entry.getKey())</span>
<span class="nc bnc" id="L581" title="All 2 branches missed."> .equals(NumberType.INTEGER.name())) {</span>
// only values without shifting bits
<span class="nc bnc" id="L583" title="All 2 branches missed."> if (term.bytes[term.offset] == LegacyNumericUtils.SHIFT_START_INT) {</span>
<span class="nc" id="L584"> termValue = Integer</span>
<span class="nc" id="L585"> .toString(LegacyNumericUtils.prefixCodedToInt(term));</span>
} else {
continue;
}
<span class="nc" id="L589"> } else if (facetDataType.get(entry.getKey())</span>
<span class="nc bnc" id="L590" title="All 2 branches missed."> .equals(NumberType.LONG.name())) {</span>
<span class="nc bnc" id="L591" title="All 2 branches missed."> if (term.bytes[term.offset] == LegacyNumericUtils.SHIFT_START_LONG) {</span>
<span class="nc" id="L592"> termValue = Long</span>
<span class="nc" id="L593"> .toString(LegacyNumericUtils.prefixCodedToLong(term));</span>
} else {
continue;
}
} else {
<span class="nc" id="L598"> termValue = term.utf8ToString();</span>
}
<span class="nc bnc" id="L600" title="All 2 branches missed."> if (!facetDataList.containsKey(termValue)) {</span>
<span class="nc" id="L601"> facetDataList.put(termValue, Arrays.copyOf(facetDataSublist,</span>
facetDataSublistCounter));
} else {
<span class="nc" id="L604"> int[] oldList = facetDataList.get(termValue);</span>
<span class="nc" id="L605"> int[] newList = new int[oldList.length</span>
+ facetDataSublistCounter];
<span class="nc" id="L607"> System.arraycopy(oldList, 0, newList, 0, oldList.length);</span>
<span class="nc" id="L608"> System.arraycopy(facetDataSublist, 0, newList,</span>
oldList.length, facetDataSublistCounter);
<span class="nc" id="L610"> facetDataList.put(termValue, newList);</span>
}
}
<span class="nc" id="L613"> }</span>
}
}
}
<span class="nc" id="L617"> }</span>
<span class="fc bfc" id="L619" title="All 2 branches covered."> for (MtasSpanQuery sq : fieldInfo.spanQueryList) {</span>
// what to collect
<span class="fc bfc" id="L621" title="All 2 branches covered."> if (spansNumberData.containsKey(sq)) {</span>
<span class="fc" id="L622"> numberData = spansNumberData.get(sq);</span>
} else {
<span class="fc" id="L624"> numberData = null;</span>
}
<span class="fc bfc" id="L626" title="All 2 branches covered."> if (spansMatchData.containsKey(sq)) {</span>
<span class="fc" id="L627"> matchData = spansMatchData.get(sq);</span>
} else {
<span class="fc" id="L629"> matchData = null;</span>
}
<span class="pc bpc" id="L631" title="1 of 4 branches missed."> if ((numberData != null) || (matchData != null)) {</span>
<span class="fc" id="L632"> Spans spans = spansQueryWeight.get(sq).getSpans(lrc,</span>
SpanWeight.Postings.POSITIONS);
<span class="fc bfc" id="L634" title="All 2 branches covered."> if (spans != null) {</span>
Iterator<Integer> it;
<span class="pc bpc" id="L636" title="1 of 2 branches missed."> if (docSet != null) {</span>
<span class="fc" id="L637"> it = docSet.iterator();</span>
} else {
<span class="nc" id="L639"> it = docList.iterator();</span>
}
<span class="pc bpc" id="L641" title="1 of 2 branches missed."> if (it.hasNext()) {</span>
<span class="fc" id="L642"> int docId = it.next();</span>
int number;
ArrayList<Match> matchDataList;
<span class="fc" id="L645"> Integer spansDocId = null;</span>
<span class="pc bpc" id="L646" title="1 of 2 branches missed."> while (docId != DocIdSetIterator.NO_MORE_DOCS) {</span>
<span class="fc bfc" id="L647" title="All 2 branches covered."> if (spans.advance(</span>
(docId - lrc.docBase)) == DocIdSetIterator.NO_MORE_DOCS) {
<span class="fc" id="L649"> break;</span>
}
<span class="fc" id="L651"> spansDocId = spans.docID() + lrc.docBase;</span>
<span class="pc bpc" id="L652" title="1 of 4 branches missed."> while ((docId < spansDocId) && it.hasNext()) {</span>
<span class="fc" id="L653"> docId = it.next();</span>
}
<span class="pc bpc" id="L655" title="1 of 2 branches missed."> if (docId < spansDocId) {</span>
<span class="nc" id="L656"> break;</span>
}
<span class="pc bpc" id="L658" title="1 of 2 branches missed."> if (spansDocId.equals(docId)) {</span>
<span class="fc" id="L659"> number = 0;</span>
<span class="fc" id="L660"> matchDataList = new ArrayList<>();</span>
int tmpStartPosition;
<span class="fc" id="L662"> while ((tmpStartPosition = spans</span>
<span class="fc bfc" id="L663" title="All 2 branches covered."> .nextStartPosition()) != Spans.NO_MORE_POSITIONS) {</span>
<span class="fc" id="L664"> number++;</span>
<span class="fc bfc" id="L665" title="All 2 branches covered."> if (matchData != null) {</span>
<span class="fc" id="L666"> Match m = new Match(tmpStartPosition,</span>
<span class="fc" id="L667"> spans.endPosition());</span>
<span class="fc" id="L668"> matchDataList.add(m);</span>
<span class="fc" id="L669"> }</span>
}
<span class="fc bfc" id="L671" title="All 2 branches covered."> if ((numberData != null)) {</span>
<span class="fc" id="L672"> numberData.put(spansDocId, number);</span>
}
<span class="fc bfc" id="L674" title="All 2 branches covered."> if ((matchData != null)) {</span>
<span class="fc" id="L675"> matchData.put(spansDocId, matchDataList);</span>
}
<span class="fc bfc" id="L677" title="All 2 branches covered."> if (it.hasNext()) {</span>
<span class="fc" id="L678"> docId = it.next();</span>
} else {
break;
}
<span class="fc" id="L682"> }</span>
}
}
}
}
<span class="fc" id="L687"> }</span>
}
// collect position stats
<span class="fc bfc" id="L691" title="All 2 branches covered."> if (needPositions) {</span>
<span class="pc bpc" id="L692" title="1 of 2 branches missed."> if (mtasCodecInfo != null) {</span>
// for relatively small numbers, compute only what is needed
<span class="fc bfc" id="L694" title="All 2 branches covered."> if (docSet.size() < Math.log(r.maxDoc())) {</span>
<span class="fc" id="L695"> positionsData = new HashMap<>();</span>
<span class="fc bfc" id="L696" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="fc" id="L697"> positionsData.put(docId, mtasCodecInfo.getNumberOfPositions(field,</span>
(docId - lrc.docBase)));
<span class="fc" id="L699"> }</span>
// compute everything, only use what is needed
} else {
<span class="fc" id="L702"> positionsData = mtasCodecInfo.getAllNumberOfPositions(field,</span>
lrc.docBase);
<span class="fc bfc" id="L704" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="pc bpc" id="L705" title="1 of 2 branches missed."> if (!positionsData.containsKey(docId)) {</span>
<span class="nc" id="L706"> positionsData.put(docId, 0);</span>
}
<span class="fc" id="L708"> }</span>
}
} else {
<span class="nc" id="L711"> positionsData = new HashMap<>();</span>
<span class="nc bnc" id="L712" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc" id="L713"> positionsData.put(docId, 0);</span>
<span class="nc" id="L714"> }</span>
}
}
// collect token stats
<span class="fc bfc" id="L719" title="All 2 branches covered."> if (needTokens) {</span>
<span class="pc bpc" id="L720" title="1 of 2 branches missed."> if (mtasCodecInfo != null) {</span>
// for relatively small numbers, compute only what is needed
<span class="fc bfc" id="L722" title="All 2 branches covered."> if (docSet.size() < Math.log(r.maxDoc())) {</span>
<span class="fc" id="L723"> tokensData = new HashMap<>();</span>
<span class="fc bfc" id="L724" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="fc" id="L725"> tokensData.put(docId,</span>
<span class="fc" id="L726"> mtasCodecInfo.getNumberOfTokens(field, (docId - lrc.docBase)));</span>
<span class="fc" id="L727"> }</span>
// compute everything, only use what is needed
} else {
<span class="fc" id="L730"> tokensData = mtasCodecInfo.getAllNumberOfTokens(field, lrc.docBase);</span>
<span class="fc bfc" id="L731" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="pc bpc" id="L732" title="1 of 2 branches missed."> if (!tokensData.containsKey(docId)) {</span>
<span class="nc" id="L733"> tokensData.put(docId, 0);</span>
}
<span class="fc" id="L735"> }</span>
}
} else {
<span class="nc" id="L738"> tokensData = new HashMap<>();</span>
<span class="nc bnc" id="L739" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc" id="L740"> tokensData.put(docId, 0);</span>
<span class="nc" id="L741"> }</span>
}
}
<span class="fc bfc" id="L745" title="All 2 branches covered."> if (!fieldInfo.statsPositionList.isEmpty()) {</span>
// create positions
<span class="fc" id="L747"> createPositions(fieldInfo.statsPositionList, positionsData, docSet);</span>
}
<span class="fc bfc" id="L750" title="All 2 branches covered."> if (!fieldInfo.statsTokenList.isEmpty()) {</span>
// create positions
<span class="fc" id="L752"> createTokens(fieldInfo.statsTokenList, tokensData, docSet);</span>
}
<span class="pc bpc" id="L755" title="1 of 2 branches missed."> if (!fieldInfo.documentList.isEmpty()) {</span>
// create document
<span class="nc" id="L757"> createDocument(fieldInfo.documentList, docList, fieldInfo.uniqueKeyField,</span>
searcher, t, lrc);
}
<span class="fc bfc" id="L760" title="All 2 branches covered."> if (!fieldInfo.spanQueryList.isEmpty()) {</span>
<span class="fc bfc" id="L761" title="All 2 branches covered."> if (!fieldInfo.statsSpanList.isEmpty()) {</span>
// create stats
<span class="fc" id="L763"> createStats(fieldInfo.statsSpanList, positionsData, spansNumberData,</span>
<span class="fc" id="L764"> docSet.toArray(new Integer[docSet.size()]));</span>
}
<span class="pc bpc" id="L766" title="1 of 2 branches missed."> if (!fieldInfo.listList.isEmpty()) {</span>
// create list
<span class="nc" id="L768"> createList(fieldInfo.listList, spansNumberData, spansMatchData, docSet,</span>
field, lrc.docBase, fieldInfo.uniqueKeyField, mtasCodecInfo,
searcher);
}
<span class="fc bfc" id="L772" title="All 2 branches covered."> if (!fieldInfo.groupList.isEmpty()) {</span>
// create group
<span class="fc" id="L774"> createGroup(fieldInfo.groupList, spansMatchData, docSet,</span>
<span class="fc" id="L775"> fieldInfos.fieldInfo(field), field, lrc.docBase, mtasCodecInfo,</span>
searcher, lrc);
}
<span class="pc bpc" id="L778" title="1 of 2 branches missed."> if (!fieldInfo.kwicList.isEmpty()) {</span>
// create kwic
<span class="nc" id="L780"> createKwic(fieldInfo.kwicList, spansMatchData, docList, field,</span>
lrc.docBase, fieldInfo.uniqueKeyField, mtasCodecInfo, searcher);
}
<span class="pc bpc" id="L783" title="1 of 2 branches missed."> if (!fieldInfo.facetList.isEmpty()) {</span>
// create facets
<span class="nc" id="L785"> createFacet(fieldInfo.facetList, positionsData, spansNumberData,</span>
facetData, docSet);
}
}
<span class="fc bfc" id="L789" title="All 2 branches covered."> if (!fieldInfo.termVectorList.isEmpty()) {</span>
<span class="fc" id="L790"> createTermvectorFull(fieldInfo.termVectorList, positionsData, docSet, t,</span>
r, lrc);
<span class="fc" id="L792"> createTermvectorFirstRound(fieldInfo.termVectorList, positionsData,</span>
docSet, t, r, lrc);
}
<span class="fc" id="L795"> }</span>
/**
* Collect known prefixes.
*
* @param fi
* the fi
* @return the sets the
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static Set<String> collectKnownPrefixes(FieldInfo fi)
throws IOException {
<span class="pc bpc" id="L808" title="1 of 2 branches missed."> if (fi != null) {</span>
<span class="fc" id="L809"> HashSet<String> result = new HashSet<>();</span>
<span class="fc" id="L810"> String singlePositionPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_SINGLE_POSITION);
<span class="fc" id="L812"> String multiplePositionPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_MULTIPLE_POSITION);
<span class="fc" id="L814"> String setPositionPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_SET_POSITION);
<span class="pc bpc" id="L816" title="1 of 2 branches missed."> if (singlePositionPrefixes != null) {</span>
<span class="fc" id="L817"> String[] prefixes = singlePositionPrefixes</span>
<span class="fc" id="L818"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L819" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L820"> String item = prefixes[i].trim();</span>
<span class="pc bpc" id="L821" title="1 of 2 branches missed."> if (!item.equals("")) {</span>
<span class="fc" id="L822"> result.add(item);</span>
}
}
}
<span class="pc bpc" id="L826" title="1 of 2 branches missed."> if (multiplePositionPrefixes != null) {</span>
<span class="fc" id="L827"> String[] prefixes = multiplePositionPrefixes</span>
<span class="fc" id="L828"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L829" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L830"> String item = prefixes[i].trim();</span>
<span class="pc bpc" id="L831" title="1 of 2 branches missed."> if (!item.equals("")) {</span>
<span class="fc" id="L832"> result.add(item);</span>
}
}
}
<span class="pc bpc" id="L836" title="1 of 2 branches missed."> if (setPositionPrefixes != null) {</span>
<span class="fc" id="L837"> String[] prefixes = setPositionPrefixes</span>
<span class="fc" id="L838"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L839" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L840"> String item = prefixes[i].trim();</span>
<span class="pc bpc" id="L841" title="1 of 2 branches missed."> if (!item.equals("")) {</span>
<span class="fc" id="L842"> result.add(item);</span>
}
}
}
<span class="fc" id="L846"> return result;</span>
} else {
<span class="nc" id="L848"> return Collections.emptySet();</span>
}
}
/**
* Collect intersection prefixes.
*
* @param fi
* the fi
* @return the sets the
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static Set<String> collectIntersectionPrefixes(FieldInfo fi)
throws IOException {
<span class="pc bpc" id="L863" title="1 of 2 branches missed."> if (fi != null) {</span>
<span class="fc" id="L864"> Set<String> result = new HashSet<>();</span>
<span class="fc" id="L865"> String intersectingPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_INTERSECTION);
<span class="pc bpc" id="L867" title="1 of 2 branches missed."> if (intersectingPrefixes != null) {</span>
<span class="fc" id="L868"> String[] prefixes = intersectingPrefixes</span>
<span class="fc" id="L869"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L870" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L871"> String item = prefixes[i].trim();</span>
<span class="pc bpc" id="L872" title="1 of 2 branches missed."> if (!item.equals("")) {</span>
<span class="fc" id="L873"> result.add(item);</span>
}
}
}
<span class="fc" id="L877"> return result;</span>
} else {
<span class="nc" id="L879"> return Collections.emptySet();</span>
}
}
/**
* Collect prefixes.
*
* @param fieldInfos
* the field infos
* @param field
* the field
* @param fieldInfo
* the field info
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void collectPrefixes(FieldInfos fieldInfos, String field,
ComponentField fieldInfo) throws IOException {
<span class="fc bfc" id="L897" title="All 2 branches covered."> if (fieldInfo.prefix != null) {</span>
<span class="fc" id="L898"> FieldInfo fi = fieldInfos.fieldInfo(field);</span>
<span class="pc bpc" id="L899" title="1 of 2 branches missed."> if (fi != null) {</span>
<span class="fc" id="L900"> String singlePositionPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_SINGLE_POSITION);
<span class="fc" id="L902"> String multiplePositionPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_MULTIPLE_POSITION);
<span class="fc" id="L904"> String setPositionPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_SET_POSITION);
<span class="fc" id="L906"> String intersectingPrefixes = fi.getAttribute(</span>
MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_INTERSECTION);
<span class="pc bpc" id="L908" title="1 of 2 branches missed."> if (singlePositionPrefixes != null) {</span>
<span class="fc" id="L909"> String[] prefixes = singlePositionPrefixes</span>
<span class="fc" id="L910"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L911" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L912"> fieldInfo.prefix.addSinglePosition(prefixes[i]);</span>
}
}
<span class="pc bpc" id="L915" title="1 of 2 branches missed."> if (multiplePositionPrefixes != null) {</span>
<span class="fc" id="L916"> String[] prefixes = multiplePositionPrefixes</span>
<span class="fc" id="L917"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L918" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L919"> fieldInfo.prefix.addMultiplePosition(prefixes[i]);</span>
}
}
<span class="pc bpc" id="L922" title="1 of 2 branches missed."> if (setPositionPrefixes != null) {</span>
<span class="fc" id="L923"> String[] prefixes = setPositionPrefixes</span>
<span class="fc" id="L924"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L925" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L926"> fieldInfo.prefix.addSetPosition(prefixes[i]);</span>
}
}
<span class="pc bpc" id="L929" title="1 of 2 branches missed."> if (intersectingPrefixes != null) {</span>
<span class="fc" id="L930"> String[] prefixes = intersectingPrefixes</span>
<span class="fc" id="L931"> .split(Pattern.quote(MtasToken.DELIMITER));</span>
<span class="fc bfc" id="L932" title="All 2 branches covered."> for (int i = 0; i < prefixes.length; i++) {</span>
<span class="fc" id="L933"> fieldInfo.prefix.addIntersecting(prefixes[i]);</span>
}
}
}
}
<span class="fc" id="L938"> }</span>
/**
* Collect spans for occurences.
*
* @param occurences
* the occurences
* @param prefixes
* the prefixes
* @param field
* the field
* @param searcher
* the searcher
* @param lrc
* the lrc
* @return the map
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static Map<GroupHit, Spans> collectSpansForOccurences(
Set<GroupHit> occurences, Set<String> prefixes, String field,
IndexSearcher searcher, LeafReaderContext lrc) throws IOException {
<span class="nc" id="L960"> Map<GroupHit, Spans> list = new HashMap<>();</span>
<span class="nc" id="L961"> IndexReader reader = searcher.getIndexReader();</span>
<span class="nc" id="L962"> final float boost = 0;</span>
<span class="nc bnc" id="L963" title="All 2 branches missed."> for (GroupHit hit : occurences) {</span>
<span class="nc" id="L964"> MtasSpanQuery queryHit = createQueryFromGroupHit(prefixes, field, hit);</span>
<span class="nc bnc" id="L965" title="All 2 branches missed."> if (queryHit != null) {</span>
<span class="nc" id="L966"> MtasSpanQuery queryHitRewritten = queryHit.rewrite(reader);</span>
<span class="nc" id="L967"> SpanWeight weight = queryHitRewritten.createWeight(searcher, false,</span>
boost);
<span class="nc" id="L969"> Spans spans = weight.getSpans(lrc, SpanWeight.Postings.POSITIONS);</span>
<span class="nc bnc" id="L970" title="All 2 branches missed."> if (spans != null) {</span>
<span class="nc" id="L971"> list.put(hit, spans);</span>
}
}
<span class="nc" id="L974"> }</span>
<span class="nc" id="L975"> return list;</span>
}
/**
* Creates the query from group hit.
*
* @param prefixes
* the prefixes
* @param field
* the field
* @param hit
* the hit
* @return the mtas span query
*/
private static MtasSpanQuery createQueryFromGroupHit(Set<String> prefixes,
String field, GroupHit hit) {
// initial check
<span class="nc bnc" id="L992" title="All 6 branches missed."> if (prefixes == null || field == null || hit == null) {</span>
<span class="nc" id="L993"> return null;</span>
} else {
<span class="nc" id="L995"> MtasSpanQuery query = null;</span>
// check for missing
<span class="nc bnc" id="L997" title="All 4 branches missed."> if (hit.missingLeft != null && hit.missingLeft.length > 0) {</span>
<span class="nc bnc" id="L998" title="All 2 branches missed."> for (int i = 0; i < hit.missingLeft.length; i++) {</span>
<span class="nc bnc" id="L999" title="All 2 branches missed."> if (hit.missingLeft[i].size() != hit.unknownLeft[i].size()) {</span>
<span class="nc" id="L1000"> return null;</span>
}
}
}
<span class="nc bnc" id="L1004" title="All 4 branches missed."> if (hit.missingHit != null && hit.missingHit.length > 0) {</span>
<span class="nc bnc" id="L1005" title="All 2 branches missed."> for (int i = 0; i < hit.missingHit.length; i++) {</span>
<span class="nc bnc" id="L1006" title="All 2 branches missed."> if (hit.missingHit[i].size() != hit.unknownHit[i].size()) {</span>
<span class="nc" id="L1007"> return null;</span>
}
}
}
<span class="nc bnc" id="L1011" title="All 4 branches missed."> if (hit.missingRight != null && hit.missingRight.length > 0) {</span>
<span class="nc bnc" id="L1012" title="All 2 branches missed."> for (int i = 0; i < hit.missingRight.length; i++) {</span>
<span class="nc bnc" id="L1013" title="All 2 branches missed."> if (hit.missingRight[i].size() != hit.unknownRight[i].size()) {</span>
<span class="nc" id="L1014"> return null;</span>
}
}
}
<span class="nc" id="L1018"> MtasSpanQuery hitQuery = createSubQueryFromGroupHit(hit.dataHit, false, field);</span>
<span class="nc bnc" id="L1019" title="All 2 branches missed."> if (hitQuery != null) {</span>
<span class="nc" id="L1020"> query = hitQuery;</span>
<span class="nc" id="L1021"> MtasSpanQuery leftHitQuery = createSubQueryFromGroupHit(hit.dataLeft, true, field);</span>
<span class="nc" id="L1022"> MtasSpanQuery rightHitQuery = createSubQueryFromGroupHit(hit.dataRight, false, field);</span>
<span class="nc bnc" id="L1023" title="All 2 branches missed."> if(leftHitQuery!=null) {</span>
<span class="nc" id="L1024"> query = new MtasSpanPrecededByQuery(query, leftHitQuery);</span>
}
<span class="nc bnc" id="L1026" title="All 2 branches missed."> if(rightHitQuery!=null) {</span>
<span class="nc" id="L1027"> query = new MtasSpanFollowedByQuery(query, rightHitQuery);</span>
}
}
<span class="nc" id="L1030"> return query;</span>
}
}
private static MtasSpanQuery createSubQueryFromGroupHit(List<String>[] subHit, boolean reverse,
String field) {
<span class="nc" id="L1036"> MtasSpanQuery query = null;</span>
<span class="nc bnc" id="L1037" title="All 4 branches missed."> if (subHit != null && subHit.length > 0) {</span>
<span class="nc" id="L1038"> List<MtasSpanSequenceItem> items = new ArrayList<>(); </span>
List<String> subHitItem;
<span class="nc bnc" id="L1040" title="All 2 branches missed."> for (int i = 0; i < subHit.length; i++) {</span>
<span class="nc" id="L1041"> MtasSpanQuery item = null;</span>
<span class="nc bnc" id="L1042" title="All 2 branches missed."> if(reverse) {</span>
<span class="nc" id="L1043"> subHitItem = subHit[(subHit.length - i - 1)];</span>
} else {
<span class="nc" id="L1045"> subHitItem = subHit[i];</span>
}
<span class="nc bnc" id="L1047" title="All 2 branches missed."> if (subHitItem.isEmpty()) {</span>
<span class="nc" id="L1048"> item = new MtasSpanMatchAllQuery(field);</span>
<span class="nc bnc" id="L1049" title="All 2 branches missed."> } else if (subHitItem.size() == 1) {</span>
<span class="nc" id="L1050"> Term term = new Term(field, subHitItem.get(0));</span>
<span class="nc" id="L1051"> item = new MtasSpanTermQuery(term);</span>
<span class="nc" id="L1052"> } else {</span>
<span class="nc" id="L1053"> MtasSpanQuery[] subList = new MtasSpanQuery[subHitItem.size()];</span>
<span class="nc bnc" id="L1054" title="All 2 branches missed."> for (int j = 0; j < subHitItem.size(); j++) {</span>
<span class="nc" id="L1055"> Term term = new Term(field, subHitItem.get(j));</span>
<span class="nc" id="L1056"> subList[j] = new MtasSpanTermQuery(term);</span>
}
<span class="nc" id="L1058"> item = new MtasSpanAndQuery(subList);</span>
}
<span class="nc" id="L1060"> items.add(new MtasSpanSequenceItem(item, false));</span>
}
<span class="nc" id="L1062"> query = new MtasSpanSequenceQuery(items, null, null);</span>
}
<span class="nc" id="L1064"> return query;</span>
}
/**
* Compute positions.
*
* @param mtasCodecInfo
* the mtas codec info
* @param r
* the r
* @param lrc
* the lrc
* @param field
* the field
* @param docSet
* the doc set
* @return the map
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static Map<Integer, Integer> computePositions(CodecInfo mtasCodecInfo,
LeafReader r, LeafReaderContext lrc, String field, List<Integer> docSet)
throws IOException {
HashMap<Integer, Integer> positionsData;
<span class="nc bnc" id="L1088" title="All 2 branches missed."> if (mtasCodecInfo != null) {</span>
// for relatively small numbers, compute only what is needed
<span class="nc bnc" id="L1090" title="All 2 branches missed."> if (docSet.size() < Math.log(r.maxDoc())) {</span>
<span class="nc" id="L1091"> positionsData = new HashMap<>();</span>
<span class="nc bnc" id="L1092" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc" id="L1093"> positionsData.put(docId,</span>
<span class="nc" id="L1094"> mtasCodecInfo.getNumberOfPositions(field, (docId - lrc.docBase)));</span>
<span class="nc" id="L1095"> }</span>
// compute everything, only use what is needed
} else {
<span class="nc" id="L1098"> positionsData = mtasCodecInfo.getAllNumberOfPositions(field,</span>
lrc.docBase);
<span class="nc bnc" id="L1100" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc bnc" id="L1101" title="All 2 branches missed."> if (!positionsData.containsKey(docId)) {</span>
<span class="nc" id="L1102"> positionsData.put(docId, 0);</span>
}
<span class="nc" id="L1104"> }</span>
}
} else {
<span class="nc" id="L1107"> positionsData = new HashMap<>();</span>
<span class="nc bnc" id="L1108" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc" id="L1109"> positionsData.put(docId, 0);</span>
<span class="nc" id="L1110"> }</span>
}
<span class="nc" id="L1112"> return positionsData;</span>
}
/**
* Compute arguments.
*
* @param spansNumberData
* the spans number data
* @param queries
* the queries
* @param docSet
* the doc set
* @return the map
*/
private static Map<Integer, long[]> computeArguments(
Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData,
MtasSpanQuery[] queries, Integer[] docSet) {
<span class="fc" id="L1129"> Map<Integer, long[]> args = new HashMap<>();</span>
<span class="fc bfc" id="L1130" title="All 2 branches covered."> for (int q = 0; q < queries.length; q++) {</span>
<span class="fc" id="L1131"> Map<Integer, Integer> tmpData = spansNumberData.get(queries[q]);</span>
<span class="fc" id="L1132"> long[] tmpList = null;</span>
<span class="fc bfc" id="L1133" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="pc bpc" id="L1134" title="1 of 4 branches missed."> if (tmpData != null && tmpData.containsKey(docId)) {</span>
<span class="fc bfc" id="L1135" title="All 2 branches covered."> if (!args.containsKey(docId)) {</span>
<span class="fc" id="L1136"> tmpList = new long[queries.length];</span>
} else {
<span class="fc" id="L1138"> tmpList = args.get(docId);</span>
}
<span class="fc" id="L1140"> tmpList[q] = tmpData.get(docId);</span>
<span class="fc" id="L1141"> args.put(docId, tmpList);</span>
<span class="pc bpc" id="L1142" title="1 of 2 branches missed."> } else if (!args.containsKey(docId)) {</span>
<span class="fc" id="L1143"> tmpList = new long[queries.length];</span>
<span class="fc" id="L1144"> args.put(docId, tmpList);</span>
}
}
}
<span class="fc" id="L1148"> return args;</span>
}
/**
* Intersected doc list.
*
* @param facetDocList
* the facet doc list
* @param docSet
* the doc set
* @return the integer[]
*/
private static Integer[] intersectedDocList(int[] facetDocList,
Integer[] docSet) {
<span class="nc bnc" id="L1162" title="All 4 branches missed."> if (facetDocList != null && docSet != null) {</span>
<span class="nc" id="L1163"> Integer[] c = new Integer[Math.min(facetDocList.length, docSet.length)];</span>
<span class="nc" id="L1164"> int ai = 0;</span>
<span class="nc" id="L1165"> int bi = 0;</span>
<span class="nc" id="L1166"> int ci = 0;</span>
<span class="nc bnc" id="L1167" title="All 4 branches missed."> while (ai < facetDocList.length && bi < docSet.length) {</span>
<span class="nc bnc" id="L1168" title="All 2 branches missed."> if (facetDocList[ai] < docSet[bi]) {</span>
<span class="nc" id="L1169"> ai++;</span>
<span class="nc bnc" id="L1170" title="All 2 branches missed."> } else if (facetDocList[ai] > docSet[bi]) {</span>
<span class="nc" id="L1171"> bi++;</span>
} else {
<span class="nc bnc" id="L1173" title="All 4 branches missed."> if (ci == 0 || facetDocList[ai] != c[ci - 1]) {</span>
<span class="nc" id="L1174"> c[ci++] = facetDocList[ai];</span>
}
<span class="nc" id="L1176"> ai++;</span>
<span class="nc" id="L1177"> bi++;</span>
}
}
<span class="nc" id="L1180"> return Arrays.copyOfRange(c, 0, ci);</span>
}
<span class="nc" id="L1182"> return new Integer[] {};</span>
}
/**
* Creates the positions.
*
* @param statsPositionList
* the stats position list
* @param positionsData
* the positions data
* @param docSet
* the doc set
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createPositions(List<ComponentPosition> statsPositionList,
Map<Integer, Integer> positionsData, List<Integer> docSet)
throws IOException {
<span class="pc bpc" id="L1200" title="1 of 2 branches missed."> if (statsPositionList != null) {</span>
<span class="fc bfc" id="L1201" title="All 2 branches covered."> for (ComponentPosition position : statsPositionList) {</span>
<span class="fc" id="L1202"> position.dataCollector.initNewList(1);</span>
Integer tmpValue;
<span class="fc" id="L1204"> long[] values = new long[docSet.size()];</span>
int value;
<span class="fc" id="L1206"> int number = 0;</span>
<span class="fc bfc" id="L1207" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="fc" id="L1208"> tmpValue = positionsData.get(docId);</span>
<span class="pc bpc" id="L1209" title="1 of 2 branches missed."> value = tmpValue == null ? 0 : tmpValue.intValue();</span>
<span class="fc bfc" id="L1210" title="All 2 branches covered."> if (((position.minimumLong == null)</span>
<span class="fc bfc" id="L1211" title="All 4 branches covered."> || (value >= position.minimumLong))</span>
&& ((position.maximumLong == null)
<span class="fc bfc" id="L1213" title="All 2 branches covered."> || (value <= position.maximumLong))) {</span>
<span class="fc" id="L1214"> values[number] = value;</span>
<span class="fc" id="L1215"> number++;</span>
}
<span class="fc" id="L1217"> }</span>
<span class="fc bfc" id="L1218" title="All 2 branches covered."> if (number > 0) {</span>
<span class="fc" id="L1219"> position.dataCollector.add(values, number);</span>
}
<span class="fc" id="L1221"> position.dataCollector.closeNewList();</span>
<span class="fc" id="L1222"> }</span>
}
<span class="fc" id="L1224"> }</span>
/**
* Creates the tokens.
*
* @param statsTokenList
* the stats token list
* @param tokensData
* the tokens data
* @param docSet
* the doc set
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createTokens(List<ComponentToken> statsTokenList,
Map<Integer, Integer> tokensData, List<Integer> docSet)
throws IOException {
<span class="pc bpc" id="L1241" title="1 of 2 branches missed."> if (statsTokenList != null) {</span>
<span class="fc bfc" id="L1242" title="All 2 branches covered."> for (ComponentToken token : statsTokenList) {</span>
<span class="fc" id="L1243"> token.dataCollector.initNewList(1);</span>
Integer tmpValue;
<span class="fc" id="L1245"> long[] values = new long[docSet.size()];</span>
int value;
<span class="fc" id="L1247"> int number = 0;</span>
<span class="pc bpc" id="L1248" title="1 of 2 branches missed."> if (tokensData != null) {</span>
<span class="fc bfc" id="L1249" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="fc" id="L1250"> tmpValue = tokensData.get(docId);</span>
<span class="pc bpc" id="L1251" title="1 of 2 branches missed."> value = tmpValue == null ? 0 : tmpValue.intValue();</span>
<span class="pc bpc" id="L1252" title="1 of 6 branches missed."> if (((token.minimumLong == null) || (value >= token.minimumLong))</span>
&& ((token.maximumLong == null)
<span class="pc bpc" id="L1254" title="1 of 2 branches missed."> || (value <= token.maximumLong))) {</span>
<span class="fc" id="L1255"> values[number] = value;</span>
<span class="fc" id="L1256"> number++;</span>
}
<span class="fc" id="L1258"> }</span>
}
<span class="fc bfc" id="L1260" title="All 2 branches covered."> if (number > 0) {</span>
<span class="fc" id="L1261"> token.dataCollector.add(values, number);</span>
}
<span class="fc" id="L1263"> token.dataCollector.closeNewList();</span>
<span class="fc" id="L1264"> }</span>
}
<span class="fc" id="L1266"> }</span>
/**
* Creates the stats.
*
* @param statsSpanList
* the stats span list
* @param positionsData
* the positions data
* @param spansNumberData
* the spans number data
* @param docSet
* the doc set
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createStats(List<ComponentSpan> statsSpanList,
Map<Integer, Integer> positionsData,
Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData,
Integer[] docSet) throws IOException {
<span class="pc bpc" id="L1286" title="1 of 2 branches missed."> if (statsSpanList != null) {</span>
<span class="fc bfc" id="L1287" title="All 2 branches covered."> for (ComponentSpan span : statsSpanList) {</span>
<span class="pc bpc" id="L1288" title="1 of 2 branches missed."> if (span.parser.needArgumentsNumber() > span.queries.length) {</span>
<span class="nc" id="L1289"> throw new IOException(</span>
"function " + span.parser + " expects (at least) "
<span class="nc" id="L1291"> + span.parser.needArgumentsNumber() + " queries");</span>
}
// collect
<span class="fc" id="L1294"> Map<Integer, long[]> args = computeArguments(spansNumberData,</span>
span.queries, docSet);
<span class="pc bpc" id="L1296" title="1 of 2 branches missed."> if (span.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {</span>
// try to call functionParser as little as possible
<span class="pc bpc" id="L1298" title="1 of 8 branches missed."> if (span.statsType.equals(CodecUtil.STATS_BASIC)</span>
&& (span.minimumLong == null) && (span.maximumLong == null)
&& (span.functions == null
<span class="pc bpc" id="L1301" title="2 of 4 branches missed."> || (span.functionBasic() && span.functionSumRule()</span>
<span class="pc bpc" id="L1302" title="1 of 2 branches missed."> && !span.functionNeedPositions()))) {</span>
// initialise
<span class="fc" id="L1304"> int length = span.parser.needArgumentsNumber();</span>
<span class="fc" id="L1305"> long[] valueSum = new long[length];</span>
<span class="fc" id="L1306"> long valuePositions = 0;</span>
// collect
<span class="pc bpc" id="L1308" title="1 of 2 branches missed."> if (docSet.length > 0) {</span>
long[] tmpArgs;
<span class="fc bfc" id="L1310" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="fc" id="L1311"> tmpArgs = args.get(docId);</span>
<span class="fc bfc" id="L1312" title="All 2 branches covered."> valuePositions += (positionsData == null) ? 0</span>
<span class="fc" id="L1313"> : positionsData.get(docId);</span>
<span class="pc bpc" id="L1314" title="1 of 2 branches missed."> if (tmpArgs != null) {</span>
<span class="fc bfc" id="L1315" title="All 2 branches covered."> for (int i = 0; i < length; i++) {</span>
<span class="fc" id="L1316"> valueSum[i] += tmpArgs[i];</span>
}
}
}
long valueLong;
<span class="fc" id="L1321"> span.dataCollector.initNewList(1);</span>
try {
<span class="fc" id="L1323"> valueLong = span.parser.getValueLong(valueSum, valuePositions);</span>
<span class="fc" id="L1324"> span.dataCollector.add(valueLong, docSet.length);</span>
<span class="nc" id="L1325"> } catch (IOException e) {</span>
<span class="nc" id="L1326"> log.debug(e);</span>
<span class="nc" id="L1327"> span.dataCollector.error(e.getMessage());</span>
<span class="fc" id="L1328"> }</span>
<span class="pc bpc" id="L1329" title="1 of 2 branches missed."> if (span.functions != null) {</span>
<span class="fc bfc" id="L1330" title="All 2 branches covered."> for (SubComponentFunction function : span.functions) {</span>
<span class="fc" id="L1331"> function.dataCollector.initNewList(1);</span>
<span class="pc bpc" id="L1332" title="1 of 2 branches missed."> if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {</span>
try {
<span class="fc" id="L1334"> valueLong = function.parserFunction.getValueLong(valueSum,</span>
valuePositions);
<span class="fc" id="L1336"> function.dataCollector.add(valueLong, docSet.length);</span>
<span class="nc" id="L1337"> } catch (IOException e) {</span>
<span class="nc" id="L1338"> log.debug(e);</span>
<span class="nc" id="L1339"> function.dataCollector.error(e.getMessage());</span>
<span class="pc" id="L1340"> }</span>
<span class="nc" id="L1341"> } else if (function.dataType</span>
<span class="nc bnc" id="L1342" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
try {
<span class="nc" id="L1344"> double valueDouble = function.parserFunction</span>
<span class="nc" id="L1345"> .getValueDouble(valueSum, valuePositions);</span>
<span class="nc" id="L1346"> function.dataCollector.add(valueDouble, docSet.length);</span>
<span class="nc" id="L1347"> } catch (IOException e) {</span>
<span class="nc" id="L1348"> log.debug(e);</span>
<span class="nc" id="L1349"> function.dataCollector.error(e.getMessage());</span>
<span class="nc" id="L1350"> }</span>
} else {
<span class="nc" id="L1352"> throw new IOException(</span>
"can't handle function dataType " + function.dataType);
}
<span class="fc" id="L1355"> function.dataCollector.closeNewList();</span>
<span class="fc" id="L1356"> }</span>
}
<span class="fc" id="L1358"> span.dataCollector.closeNewList();</span>
}
<span class="fc" id="L1360"> } else {</span>
// collect
<span class="pc bpc" id="L1362" title="1 of 2 branches missed."> if (docSet.length > 0) {</span>
<span class="fc" id="L1363"> int number = 0;</span>
int positions;
long valueLong;
double valueDouble;
<span class="fc" id="L1367"> long[] values = new long[docSet.length];</span>
<span class="fc" id="L1368"> long[][] functionValuesLong = null;</span>
<span class="fc" id="L1369"> double[][] functionValuesDouble = null;</span>
<span class="fc" id="L1370"> span.dataCollector.initNewList(1);</span>
<span class="pc bpc" id="L1371" title="1 of 2 branches missed."> if (span.functions != null) {</span>
<span class="fc" id="L1372"> functionValuesLong = new long[span.functions.size()][];</span>
<span class="fc" id="L1373"> functionValuesDouble = new double[span.functions.size()][];</span>
<span class="pc bpc" id="L1374" title="1 of 2 branches missed."> for (int i = 0; i < span.functions.size(); i++) {</span>
<span class="nc" id="L1375"> SubComponentFunction function = span.functions.get(i);</span>
<span class="nc bnc" id="L1376" title="All 2 branches missed."> if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L1377"> functionValuesLong[i] = new long[docSet.length];</span>
<span class="nc" id="L1378"> functionValuesDouble[i] = null;</span>
<span class="nc" id="L1379"> } else if (function.dataType</span>
<span class="nc bnc" id="L1380" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L1381"> functionValuesLong[i] = null;</span>
<span class="nc" id="L1382"> functionValuesDouble[i] = new double[docSet.length];</span>
}
<span class="nc" id="L1384"> function.dataCollector.initNewList(1);</span>
}
}
<span class="fc bfc" id="L1387" title="All 2 branches covered."> for (int docId : docSet) {</span>
<span class="fc bfc" id="L1388" title="All 2 branches covered."> if (positionsData == null) {</span>
<span class="fc" id="L1389"> positions = 0;</span>
} else {
<span class="pc bpc" id="L1391" title="1 of 2 branches missed."> positions = (positionsData.get(docId) == null ? 0</span>
<span class="fc" id="L1392"> : positionsData.get(docId));</span>
}
<span class="fc" id="L1394"> valueLong = span.parser.getValueLong(args.get(docId),</span>
positions);
<span class="fc bfc" id="L1396" title="All 2 branches covered."> if (((span.minimumLong == null)</span>
<span class="fc bfc" id="L1397" title="All 4 branches covered."> || (valueLong >= span.minimumLong))</span>
&& ((span.maximumLong == null)
<span class="fc bfc" id="L1399" title="All 2 branches covered."> || (valueLong <= span.maximumLong))) {</span>
<span class="fc" id="L1400"> values[number] = valueLong;</span>
<span class="pc bpc" id="L1401" title="1 of 2 branches missed."> if (span.functions != null) {</span>
<span class="pc bpc" id="L1402" title="1 of 2 branches missed."> for (int i = 0; i < span.functions.size(); i++) {</span>
<span class="nc" id="L1403"> SubComponentFunction function = span.functions.get(i);</span>
try {
<span class="nc" id="L1405"> if (function.dataType</span>
<span class="nc bnc" id="L1406" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L1407"> valueLong = function.parserFunction</span>
<span class="nc" id="L1408"> .getValueLong(args.get(docId), positions);</span>
<span class="nc" id="L1409"> functionValuesLong[i][number] = valueLong;</span>
<span class="nc" id="L1410"> } else if (function.dataType</span>
<span class="nc bnc" id="L1411" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L1412"> valueDouble = function.parserFunction</span>
<span class="nc" id="L1413"> .getValueDouble(args.get(docId), positions);</span>
<span class="nc" id="L1414"> functionValuesDouble[i][number] = valueDouble;</span>
}
<span class="nc" id="L1416"> } catch (IOException e) {</span>
<span class="nc" id="L1417"> log.debug(e);</span>
<span class="nc" id="L1418"> function.dataCollector.error(e.getMessage());</span>
<span class="nc" id="L1419"> }</span>
}
}
<span class="fc" id="L1422"> number++;</span>
}
}
<span class="fc bfc" id="L1425" title="All 2 branches covered."> if (number > 0) {</span>
<span class="fc" id="L1426"> span.dataCollector.add(values, number);</span>
<span class="pc bpc" id="L1427" title="1 of 2 branches missed."> if (span.functions != null) {</span>
<span class="pc bpc" id="L1428" title="1 of 2 branches missed."> for (int i = 0; i < span.functions.size(); i++) {</span>
<span class="nc" id="L1429"> SubComponentFunction function = span.functions.get(i);</span>
<span class="nc bnc" id="L1430" title="All 2 branches missed."> if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L1431"> function.dataCollector.add(functionValuesLong[i], number);</span>
<span class="nc" id="L1432"> } else if (function.dataType</span>
<span class="nc bnc" id="L1433" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L1434"> function.dataCollector.add(functionValuesDouble[i],</span>
number);
}
}
}
}
<span class="fc" id="L1440"> span.dataCollector.closeNewList();</span>
<span class="pc bpc" id="L1441" title="1 of 2 branches missed."> if (span.functions != null) {</span>
<span class="pc bpc" id="L1442" title="1 of 2 branches missed."> for (SubComponentFunction function : span.functions) {</span>
<span class="nc" id="L1443"> function.dataCollector.closeNewList();</span>
<span class="nc" id="L1444"> }</span>
}
<span class="fc" id="L1446"> }</span>
}
} else {
<span class="nc" id="L1449"> throw new IOException("unexpected dataType " + span.dataType);</span>
}
<span class="fc" id="L1451"> }</span>
}
<span class="fc" id="L1453"> }</span>
/**
* Creates the list.
*
* @param listList
* the list list
* @param spansNumberData
* the spans number data
* @param spansMatchData
* the spans match data
* @param docSet
* the doc set
* @param field
* the field
* @param docBase
* the doc base
* @param uniqueKeyField
* the unique key field
* @param mtasCodecInfo
* the mtas codec info
* @param searcher
* the searcher
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createList(List<ComponentList> listList,
Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData,
Map<MtasSpanQuery, Map<Integer, List<Match>>> spansMatchData,
List<Integer> docSet, String field, int docBase, String uniqueKeyField,
CodecInfo mtasCodecInfo, IndexSearcher searcher) throws IOException {
<span class="nc bnc" id="L1484" title="All 2 branches missed."> if (listList != null) {</span>
<span class="nc bnc" id="L1485" title="All 2 branches missed."> for (ComponentList list : listList) {</span>
// collect not only stats
<span class="nc bnc" id="L1487" title="All 2 branches missed."> if (list.number > 0) {</span>
<span class="nc" id="L1488"> Map<Integer, List<Match>> matchData = spansMatchData</span>
<span class="nc" id="L1489"> .get(list.spanQuery);</span>
<span class="nc" id="L1490"> Map<Integer, Integer> numberData = spansNumberData</span>
<span class="nc" id="L1491"> .get(list.spanQuery);</span>
List<Match> matchList;
Integer matchNumber;
<span class="nc bnc" id="L1494" title="All 2 branches missed."> if (list.output.equals(ComponentList.LIST_OUTPUT_HIT)) {</span>
<span class="nc bnc" id="L1495" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc bnc" id="L1496" title="All 2 branches missed."> if (matchData != null</span>
<span class="nc bnc" id="L1497" title="All 2 branches missed."> && (matchList = matchData.get(docId)) != null) {</span>
<span class="nc bnc" id="L1498" title="All 2 branches missed."> if (list.position < (list.start + list.number)) {</span>
<span class="nc" id="L1499"> boolean getDoc = false;</span>
Match m;
<span class="nc bnc" id="L1501" title="All 2 branches missed."> for (int i = 0; i < matchList.size(); i++) {</span>
<span class="nc bnc" id="L1502" title="All 4 branches missed."> if ((list.position >= list.start)</span>
&& (list.position < (list.start + list.number))) {
<span class="nc" id="L1504"> m = matchList.get(i);</span>
<span class="nc" id="L1505"> getDoc = true;</span>
<span class="nc" id="L1506"> int startPosition = m.startPosition;</span>
<span class="nc" id="L1507"> int endPosition = m.endPosition - 1;</span>
<span class="nc" id="L1508"> List<MtasTreeHit<String>> terms = mtasCodecInfo</span>
<span class="nc" id="L1509"> .getPositionedTermsByPrefixesAndPositionRange(field,</span>
(docId - docBase), list.prefixes,
startPosition - list.left,
endPosition + list.right);
// construct hit
<span class="nc" id="L1514"> Map<Integer, List<String>> kwicListHits = new HashMap<>();</span>
<span class="nc" id="L1515"> for (int position = Math.max(0,</span>
<span class="nc bnc" id="L1516" title="All 2 branches missed."> startPosition - list.left); position <= (endPosition</span>
<span class="nc" id="L1517"> + list.right); position++) {</span>
<span class="nc" id="L1518"> kwicListHits.put(position, new ArrayList<String>());</span>
}
List<String> termList;
<span class="nc bnc" id="L1521" title="All 2 branches missed."> for (MtasTreeHit<String> term : terms) {</span>
<span class="nc" id="L1522"> for (int position = Math.max(</span>
(startPosition - list.left),
<span class="nc bnc" id="L1524" title="All 2 branches missed."> term.startPosition); position <= Math.min(</span>
(endPosition + list.right),
<span class="nc" id="L1526"> term.endPosition); position++) {</span>
<span class="nc" id="L1527"> termList = kwicListHits.get(position);</span>
<span class="nc" id="L1528"> termList.add(term.data);</span>
}
<span class="nc" id="L1530"> }</span>
<span class="nc" id="L1531"> list.hits.add(new ListHit(docId, i, m, kwicListHits));</span>
}
<span class="nc" id="L1533"> list.position++;</span>
}
<span class="nc bnc" id="L1535" title="All 2 branches missed."> if (getDoc) {</span>
// get unique id
<span class="nc" id="L1537"> Document doc = searcher.doc(docId,</span>
<span class="nc" id="L1538"> new HashSet<String>(Arrays.asList(uniqueKeyField)));</span>
<span class="nc" id="L1539"> IndexableField indxfld = doc.getField(uniqueKeyField);</span>
// get other doc info
<span class="nc bnc" id="L1541" title="All 2 branches missed."> if (indxfld != null) {</span>
<span class="nc" id="L1542"> list.uniqueKey.put(docId, indxfld.stringValue());</span>
}
<span class="nc" id="L1544"> list.subTotal.put(docId, matchList.size());</span>
<span class="nc" id="L1545"> IndexDoc mDoc = mtasCodecInfo.getDoc(field,</span>
(docId - docBase));
<span class="nc bnc" id="L1547" title="All 2 branches missed."> if (mDoc != null) {</span>
<span class="nc" id="L1548"> list.minPosition.put(docId, mDoc.minPosition);</span>
<span class="nc" id="L1549"> list.maxPosition.put(docId, mDoc.maxPosition);</span>
}
}
<span class="nc" id="L1552"> } else {</span>
<span class="nc" id="L1553"> list.position += matchList.size();</span>
}
<span class="nc bnc" id="L1555" title="All 2 branches missed."> } else if (numberData != null</span>
<span class="nc bnc" id="L1556" title="All 2 branches missed."> && (matchNumber = numberData.get(docId)) != null) {</span>
<span class="nc" id="L1557"> list.position += matchNumber;</span>
}
<span class="nc" id="L1559"> }</span>
<span class="nc" id="L1560"> list.total = list.position;</span>
<span class="nc bnc" id="L1561" title="All 2 branches missed."> } else if (list.output.equals(ComponentList.LIST_OUTPUT_TOKEN)) {</span>
<span class="nc bnc" id="L1562" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc bnc" id="L1563" title="All 2 branches missed."> if (matchData != null</span>
<span class="nc bnc" id="L1564" title="All 2 branches missed."> && (matchList = matchData.get(docId)) != null) {</span>
<span class="nc bnc" id="L1565" title="All 2 branches missed."> if (list.position < (list.start + list.number)) {</span>
<span class="nc" id="L1566"> boolean getDoc = false;</span>
Match m;
<span class="nc bnc" id="L1568" title="All 2 branches missed."> for (int i = 0; i < matchList.size(); i++) {</span>
<span class="nc bnc" id="L1569" title="All 4 branches missed."> if ((list.position >= list.start)</span>
&& (list.position < (list.start + list.number))) {
<span class="nc" id="L1571"> m = matchList.get(i);</span>
<span class="nc" id="L1572"> getDoc = true;</span>
<span class="nc" id="L1573"> int startPosition = m.startPosition;</span>
<span class="nc" id="L1574"> int endPosition = m.endPosition - 1;</span>
List<MtasTokenString> tokens;
<span class="nc" id="L1576"> tokens = mtasCodecInfo</span>
<span class="nc" id="L1577"> .getPrefixFilteredObjectsByPositions(field,</span>
(docId - docBase), list.prefixes,
startPosition - list.left,
endPosition + list.right);
<span class="nc" id="L1581"> list.tokens.add(new ListToken(docId, i, m, tokens));</span>
}
<span class="nc" id="L1583"> list.position++;</span>
}
<span class="nc bnc" id="L1585" title="All 2 branches missed."> if (getDoc) {</span>
// get unique id
<span class="nc" id="L1587"> Document doc = searcher.doc(docId,</span>
<span class="nc" id="L1588"> new HashSet<String>(Arrays.asList(uniqueKeyField)));</span>
<span class="nc" id="L1589"> IndexableField indxfld = doc.getField(uniqueKeyField);</span>
// get other doc info
<span class="nc bnc" id="L1591" title="All 2 branches missed."> if (indxfld != null) {</span>
<span class="nc" id="L1592"> list.uniqueKey.put(docId, indxfld.stringValue());</span>
}
<span class="nc" id="L1594"> list.subTotal.put(docId, matchList.size());</span>
<span class="nc" id="L1595"> IndexDoc mDoc = mtasCodecInfo.getDoc(field,</span>
(docId - docBase));
<span class="nc bnc" id="L1597" title="All 2 branches missed."> if (mDoc != null) {</span>
<span class="nc" id="L1598"> list.minPosition.put(docId, mDoc.minPosition);</span>
<span class="nc" id="L1599"> list.maxPosition.put(docId, mDoc.maxPosition);</span>
}
}
<span class="nc" id="L1602"> } else {</span>
<span class="nc" id="L1603"> list.position += matchList.size();</span>
}
<span class="nc bnc" id="L1605" title="All 2 branches missed."> } else if (numberData != null</span>
<span class="nc bnc" id="L1606" title="All 2 branches missed."> && (matchNumber = numberData.get(docId)) != null) {</span>
<span class="nc" id="L1607"> list.position += matchNumber;</span>
}
<span class="nc" id="L1609"> }</span>
<span class="nc" id="L1610"> list.total = list.position;</span>
}
<span class="nc" id="L1613"> } else {</span>
<span class="nc" id="L1614"> Map<Integer, Integer> data = spansNumberData.get(list.spanQuery);</span>
<span class="nc bnc" id="L1615" title="All 2 branches missed."> if (data != null) {</span>
<span class="nc bnc" id="L1616" title="All 2 branches missed."> for (int docId : docSet) {</span>
<span class="nc" id="L1617"> Integer matchNumber = data.get(docId);</span>
<span class="nc bnc" id="L1618" title="All 2 branches missed."> if (matchNumber != null) {</span>
<span class="nc" id="L1619"> list.position += matchNumber;</span>
}
<span class="nc" id="L1621"> }</span>
<span class="nc" id="L1622"> list.total = list.position;</span>
}
}
<span class="nc" id="L1625"> }</span>
}
<span class="nc" id="L1627"> }</span>
/**
* Creates the group.
*
* @param groupList
* the group list
* @param spansMatchData
* the spans match data
* @param docSet
* the doc set
* @param fieldInfo
* the field info
* @param field
* the field
* @param docBase
* the doc base
* @param mtasCodecInfo
* the mtas codec info
* @param searcher
* the searcher
* @param lrc
* the lrc
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createGroup(List<ComponentGroup> groupList,
Map<MtasSpanQuery, Map<Integer, List<Match>>> spansMatchData,
List<Integer> docSet, FieldInfo fieldInfo, String field, int docBase,
CodecInfo mtasCodecInfo, IndexSearcher searcher, LeafReaderContext lrc)
throws IOException {
<span class="pc bpc" id="L1659" title="2 of 4 branches missed."> if (mtasCodecInfo != null && groupList != null) {</span>
List<Match> matchList;
Map<Integer, List<Match>> matchData;
<span class="fc bfc" id="L1662" title="All 2 branches covered."> for (ComponentGroup group : groupList) {</span>
<span class="fc" id="L1663"> group.dataCollector.setWithTotal();</span>
<span class="pc bpc" id="L1664" title="1 of 2 branches missed."> if (!group.prefixes.isEmpty()) {</span>
<span class="fc" id="L1665"> matchData = spansMatchData.get(group.spanQuery);</span>
<span class="fc" id="L1666"> Set<String> knownPrefixes = collectKnownPrefixes(fieldInfo);</span>
<span class="fc" id="L1667"> Set<String> intersectionPrefixes = collectIntersectionPrefixes(</span>
fieldInfo);
<span class="fc" id="L1669"> boolean intersectionGroupPrefixes = intersectionPrefixes(group,</span>
intersectionPrefixes);
<span class="fc" id="L1671"> boolean availablePrefixes = availablePrefixes(group, knownPrefixes);</span>
// sort match lists
<span class="pc bpc" id="L1673" title="1 of 2 branches missed."> if (!intersectionGroupPrefixes) {</span>
<span class="fc bfc" id="L1674" title="All 2 branches covered."> for (Entry<Integer, List<Match>> entry : matchData.entrySet()) {</span>
<span class="fc" id="L1675"> sortMatchList(entry.getValue());</span>
<span class="fc" id="L1676"> }</span>
}
// init
<span class="fc" id="L1679"> group.dataCollector.initNewList(1);</span>
int docId;
<span class="fc" id="L1682"> Map<GroupHit, Long> occurencesSum = new HashMap<>();</span>
<span class="fc" id="L1683"> Map<GroupHit, Integer> occurencesN = new HashMap<>();</span>
<span class="fc" id="L1684"> Set<GroupHit> occurencesInCurrentDocument = new HashSet<>();</span>
<span class="pc bpc" id="L1686" title="1 of 2 branches missed."> if (!availablePrefixes) {</span>
<span class="nc" id="L1687"> HashMap<Integer, GroupHit> hits = new HashMap<>();</span>
<span class="nc bnc" id="L1688" title="All 2 branches missed."> for (int docCounter = 0; docCounter < docSet.size(); docCounter++) {</span>
<span class="nc" id="L1689"> occurencesInCurrentDocument.clear();</span>
<span class="nc" id="L1690"> docId = docSet.get(docCounter);</span>
GroupHit hit;
GroupHit hitKey;
<span class="nc bnc" id="L1693" title="All 2 branches missed."> if (matchData != null</span>
<span class="nc bnc" id="L1694" title="All 2 branches missed."> && (matchList = matchData.get(docId)) != null</span>
<span class="nc bnc" id="L1695" title="All 2 branches missed."> && !matchList.isEmpty()) {</span>
<span class="nc" id="L1696"> Iterator<Match> it = matchList.listIterator();</span>
<span class="nc bnc" id="L1697" title="All 2 branches missed."> while (it.hasNext()) {</span>
<span class="nc" id="L1698"> Match m = it.next();</span>
<span class="nc" id="L1699"> IntervalTreeNodeData<String> positionHit = createPositionHit(</span>
m, group);
<span class="nc" id="L1701"> int length = m.endPosition - m.startPosition;</span>
<span class="nc" id="L1702"> hitKey = null;</span>
<span class="nc bnc" id="L1703" title="All 2 branches missed."> if (!hits.containsKey(length)) {</span>
<span class="nc" id="L1704"> hit = new GroupHit(positionHit.list, positionHit.start,</span>
positionHit.end, positionHit.hitStart,
positionHit.hitEnd, group, knownPrefixes);
<span class="nc" id="L1707"> hits.put(length, hit);</span>
} else {
<span class="nc" id="L1709"> hit = hits.get(length);</span>
<span class="nc bnc" id="L1710" title="All 2 branches missed."> for (GroupHit hitKeyItem : occurencesSum.keySet()) {</span>
<span class="nc bnc" id="L1711" title="All 2 branches missed."> if (hitKeyItem.equals(hit)) {</span>
<span class="nc" id="L1712"> hitKey = hitKeyItem;</span>
<span class="nc" id="L1713"> break;</span>
}
<span class="nc" id="L1715"> }</span>
}
<span class="nc bnc" id="L1717" title="All 2 branches missed."> if (hitKey == null) {</span>
<span class="nc" id="L1718"> occurencesSum.put(hit, Long.valueOf(1));</span>
<span class="nc" id="L1719"> occurencesN.put(hit, 1);</span>
<span class="nc" id="L1720"> occurencesInCurrentDocument.add(hit);</span>
} else {
<span class="nc" id="L1722"> occurencesSum.put(hitKey, occurencesSum.get(hitKey) + 1);</span>
<span class="nc bnc" id="L1723" title="All 2 branches missed."> if (!occurencesInCurrentDocument.contains(hitKey)) {</span>
<span class="nc bnc" id="L1724" title="All 2 branches missed."> if (occurencesN.containsKey(hitKey)) {</span>
<span class="nc" id="L1725"> occurencesN.put(hitKey, occurencesN.get(hitKey) + 1);</span>
} else {
<span class="nc" id="L1727"> occurencesN.put(hitKey, 1);</span>
}
<span class="nc" id="L1729"> occurencesInCurrentDocument.add(hitKey);</span>
}
}
<span class="nc" id="L1732"> }</span>
}
}
<span class="nc" id="L1735"> } else {</span>
<span class="fc" id="L1736"> int maximumNumberOfDocuments = 0;</span>
<span class="fc" id="L1737"> int boundaryMinimumNumberOfDocuments = 1;</span>
<span class="fc" id="L1738"> int boundaryMaximumNumberOfDocuments = 5;</span>
<span class="fc" id="L1739"> Set<GroupHit> administrationOccurrences = new HashSet<>();</span>
<span class="fc bfc" id="L1740" title="All 2 branches covered."> for (int docCounter = 0; docCounter < docSet.size(); docCounter++) {</span>
<span class="fc" id="L1741"> occurencesInCurrentDocument.clear();</span>
<span class="fc" id="L1742"> docId = docSet.get(docCounter);</span>
<span class="pc bpc" id="L1743" title="1 of 2 branches missed."> if (matchData != null</span>
<span class="pc bpc" id="L1744" title="1 of 2 branches missed."> && (matchList = matchData.get(docId)) != null</span>
<span class="pc bpc" id="L1745" title="1 of 2 branches missed."> && !matchList.isEmpty()) {</span>
// loop over matches
<span class="fc" id="L1747"> Iterator<Match> it = matchList.listIterator();</span>
<span class="fc" id="L1748"> ArrayList<IntervalTreeNodeData<String>> positionsHits = new ArrayList<>();</span>
<span class="fc bfc" id="L1749" title="All 2 branches covered."> while (it.hasNext()) {</span>
<span class="fc" id="L1750"> Match m = it.next();</span>
<span class="fc" id="L1751"> positionsHits.add(createPositionHit(m, group));</span>
<span class="fc" id="L1752"> }</span>
<span class="fc" id="L1753"> mtasCodecInfo.collectTermsByPrefixesForListOfHitPositions(field,</span>
(docId - docBase), group.prefixes, positionsHits);
// administration
<span class="fc bfc" id="L1756" title="All 2 branches covered."> for (IntervalTreeNodeData<String> positionHit : positionsHits) {</span>
<span class="fc" id="L1757"> GroupHit hit = new GroupHit(positionHit.list,</span>
positionHit.start, positionHit.end, positionHit.hitStart,
positionHit.hitEnd, group, knownPrefixes);
<span class="fc" id="L1760"> GroupHit hitKey = null;</span>
<span class="fc bfc" id="L1761" title="All 2 branches covered."> for (GroupHit hitKeyItem : occurencesSum.keySet()) {</span>
<span class="fc bfc" id="L1762" title="All 2 branches covered."> if (hitKeyItem.equals(hit)) {</span>
<span class="fc" id="L1763"> hitKey = hitKeyItem;</span>
<span class="fc" id="L1764"> break;</span>
}
<span class="fc" id="L1766"> }</span>
<span class="fc bfc" id="L1767" title="All 2 branches covered."> if (hitKey == null) {</span>
<span class="fc" id="L1768"> occurencesSum.put(hit, Long.valueOf(1));</span>
<span class="fc" id="L1769"> occurencesN.put(hit, 1);</span>
<span class="fc" id="L1770"> occurencesInCurrentDocument.add(hit);</span>
} else {
<span class="fc" id="L1772"> occurencesSum.put(hitKey, occurencesSum.get(hitKey) + 1);</span>
<span class="fc bfc" id="L1773" title="All 2 branches covered."> if (!occurencesInCurrentDocument.contains(hitKey)) {</span>
<span class="pc bpc" id="L1774" title="1 of 2 branches missed."> if (occurencesN.containsKey(hitKey)) {</span>
<span class="fc" id="L1775"> occurencesN.put(hitKey, occurencesN.get(hitKey) + 1);</span>
} else {
<span class="nc" id="L1777"> occurencesN.put(hitKey, 1);</span>
}
<span class="fc" id="L1779"> occurencesInCurrentDocument.add(hitKey);</span>
}
}
<span class="fc" id="L1782"> }</span>
<span class="pc bpc" id="L1783" title="1 of 2 branches missed."> if (!intersectionGroupPrefixes) {</span>
<span class="fc bfc" id="L1784" title="All 2 branches covered."> for (GroupHit groupHit : occurencesInCurrentDocument) {</span>
<span class="fc" id="L1785"> int tmpNumber = occurencesN.get(groupHit);</span>
<span class="fc" id="L1786"> maximumNumberOfDocuments = Math</span>
<span class="fc" id="L1787"> .max(maximumNumberOfDocuments, tmpNumber);</span>
<span class="fc bfc" id="L1788" title="All 2 branches covered."> if (tmpNumber > boundaryMinimumNumberOfDocuments) {</span>
<span class="fc" id="L1789"> administrationOccurrences.add(groupHit);</span>
}
<span class="fc" id="L1791"> }</span>
// collect spans
<span class="pc bpc" id="L1793" title="1 of 2 branches missed."> if (maximumNumberOfDocuments > boundaryMaximumNumberOfDocuments) {</span>
<span class="nc bnc" id="L1794" title="All 2 branches missed."> if (!administrationOccurrences.isEmpty()) {</span>
<span class="nc" id="L1795"> Map<GroupHit, Spans> list = collectSpansForOccurences(</span>
administrationOccurrences, knownPrefixes, field,
searcher, lrc);
<span class="nc bnc" id="L1798" title="All 2 branches missed."> if (list.size() > 0) {</span>
<span class="nc" id="L1799"> collectGroupUsingSpans(list, docSet, docBase,</span>
docCounter, matchData, occurencesSum, occurencesN);
}
}
<span class="nc" id="L1803"> administrationOccurrences.clear();</span>
<span class="nc" id="L1804"> maximumNumberOfDocuments = 0;</span>
<span class="nc" id="L1805"> boundaryMinimumNumberOfDocuments = (int) Math</span>
<span class="nc" id="L1806"> .ceil(boundaryMinimumNumberOfDocuments * 1.2);</span>
<span class="nc" id="L1807"> boundaryMaximumNumberOfDocuments = (int) Math</span>
<span class="nc" id="L1808"> .ceil(boundaryMaximumNumberOfDocuments * 1.2);</span>
}
}
}
}
}
<span class="fc bfc" id="L1815" title="All 2 branches covered."> for (Entry<GroupHit, Long> entry : occurencesSum.entrySet()) {</span>
<span class="fc" id="L1816"> group.dataCollector.add(entry.getKey().toString(), entry.getValue(),</span>
<span class="fc" id="L1817"> occurencesN.get(entry.getKey()));</span>
<span class="fc" id="L1818"> }</span>
<span class="fc" id="L1819"> group.dataCollector.closeNewList();</span>
}
<span class="fc" id="L1821"> }</span>
}
<span class="fc" id="L1823"> }</span>
/**
* Available prefixes.
*
* @param group
* the group
* @param knownPrefixes
* the known prefixes
* @return true, if successful
*/
private static boolean availablePrefixes(ComponentGroup group,
Set<String> knownPrefixes) {
<span class="pc bpc" id="L1836" title="1 of 2 branches missed."> if (knownPrefixes != null) {</span>
<span class="pc bpc" id="L1837" title="1 of 2 branches missed."> for (String prefix : group.prefixes) {</span>
<span class="pc bpc" id="L1838" title="1 of 2 branches missed."> if (knownPrefixes.contains(prefix)) {</span>
<span class="fc" id="L1839"> return true;</span>
}
<span class="nc" id="L1841"> }</span>
}
<span class="nc" id="L1843"> return false;</span>
}
/**
* Intersection prefixes.
*
* @param group
* the group
* @param intersectionPrefixes
* the intersection prefixes
* @return true, if successful
*/
private static boolean intersectionPrefixes(ComponentGroup group,
Set<String> intersectionPrefixes) {
<span class="pc bpc" id="L1857" title="1 of 2 branches missed."> if (intersectionPrefixes != null) {</span>
<span class="fc bfc" id="L1858" title="All 2 branches covered."> for (String prefix : group.prefixes) {</span>
<span class="pc bpc" id="L1859" title="1 of 2 branches missed."> if (intersectionPrefixes.contains(prefix)) {</span>
<span class="nc" id="L1860"> return true;</span>
}
<span class="fc" id="L1862"> }</span>
}
<span class="fc" id="L1864"> return false;</span>
}
/**
* Creates the position hit.
*
* @param m
* the m
* @param group
* the group
* @return the interval tree node data
*/
private static IntervalTreeNodeData<String> createPositionHit(Match m,
ComponentGroup group) {
<span class="fc" id="L1878"> Integer start = null;</span>
<span class="fc" id="L1879"> Integer end = null;</span>
<span class="fc bfc" id="L1880" title="All 6 branches covered."> if (group.hitInside != null || group.hitInsideLeft != null</span>
|| group.hitInsideRight != null) {
<span class="fc" id="L1882"> start = m.startPosition;</span>
<span class="fc" id="L1883"> end = m.endPosition - 1;</span>
} else {
<span class="fc" id="L1885"> start = null;</span>
<span class="fc" id="L1886"> end = null;</span>
}
<span class="fc bfc" id="L1888" title="All 2 branches covered."> if (group.hitLeft != null) {</span>
<span class="fc" id="L1889"> start = m.startPosition;</span>
<span class="fc" id="L1890"> end = Math.max(m.startPosition + group.hitLeft.length - 1,</span>
m.endPosition - 1);
}
<span class="fc bfc" id="L1893" title="All 2 branches covered."> if (group.hitRight != null) {</span>
<span class="fc" id="L1894"> start = Math.min(m.endPosition - group.hitRight.length, m.startPosition);</span>
<span class="fc bfc" id="L1895" title="All 2 branches covered."> end = end == null ? (m.endPosition - 1)</span>
<span class="fc" id="L1896"> : Math.max(end, (m.endPosition - 1));</span>
}
<span class="fc bfc" id="L1898" title="All 2 branches covered."> if (group.left != null) {</span>
<span class="fc bfc" id="L1899" title="All 2 branches covered."> start = start == null ? m.startPosition - group.left.length</span>
<span class="fc" id="L1900"> : Math.min(m.startPosition - group.left.length, start);</span>
<span class="fc bfc" id="L1901" title="All 2 branches covered."> end = end == null ? m.startPosition - 1</span>
<span class="fc" id="L1902"> : Math.max(m.startPosition - 1, end);</span>
}
<span class="fc bfc" id="L1904" title="All 2 branches covered."> if (group.right != null) {</span>
<span class="fc bfc" id="L1905" title="All 2 branches covered."> start = start == null ? m.endPosition : Math.min(m.endPosition, start);</span>
<span class="fc bfc" id="L1906" title="All 2 branches covered."> end = end == null ? m.endPosition + group.right.length - 1</span>
<span class="fc" id="L1907"> : Math.max(m.endPosition + group.right.length - 1, end);</span>
}
<span class="fc" id="L1909"> return new IntervalTreeNodeData<>(start, end, m.startPosition,</span>
m.endPosition - 1);
}
/**
* Collect group using spans.
*
* @param list
* the list
* @param docSet
* the doc set
* @param docBase
* the doc base
* @param docCounter
* the doc counter
* @param matchData
* the match data
* @param occurencesSum
* the occurences sum
* @param occurencesN
* the occurences N
* @return the int
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static int collectGroupUsingSpans(Map<GroupHit, Spans> list,
List<Integer> docSet, int docBase, int docCounter,
Map<Integer, List<Match>> matchData, Map<GroupHit, Long> occurencesSum,
Map<GroupHit, Integer> occurencesN) throws IOException {
<span class="nc" id="L1938"> int total = 0;</span>
<span class="nc bnc" id="L1939" title="All 2 branches missed."> if (docCounter + 1 < docSet.size()) {</span>
// initialize
<span class="nc" id="L1941"> int nextDocCounter = docCounter + 1;</span>
<span class="nc" id="L1942"> long[] subSum = new long[list.size()];</span>
<span class="nc" id="L1943"> int[] subN = new int[list.size()];</span>
<span class="nc" id="L1944"> boolean[] newNextDocs = new boolean[list.size()];</span>
boolean newNextDoc;
<span class="nc" id="L1946"> int[] spansNextDoc = new int[list.size()];</span>
<span class="nc" id="L1947"> int nextDoc = 0;</span>
List<Match> matchList;
<span class="nc" id="L1949"> GroupHit[] hitList = list.keySet().toArray(new GroupHit[list.size()]);</span>
<span class="nc" id="L1950"> Spans[] spansList = new Spans[list.size()];</span>
<span class="nc" id="L1951"> boolean[] finishedSpansList = new boolean[list.size()];</span>
<span class="nc" id="L1952"> newNextDoc = true;</span>
// advance spans, find nextDoc
<span class="nc bnc" id="L1954" title="All 2 branches missed."> for (int i = 0; i < hitList.length; i++) {</span>
<span class="nc" id="L1955"> newNextDocs[i] = true;</span>
<span class="nc" id="L1956"> spansList[i] = list.get(hitList[i]);</span>
<span class="nc" id="L1957"> spansNextDoc[i] = spansList[i]</span>
<span class="nc" id="L1958"> .advance(docSet.get(nextDocCounter) - docBase);</span>
<span class="nc bnc" id="L1959" title="All 2 branches missed."> nextDoc = (i == 0) ? spansNextDoc[i]</span>
<span class="nc" id="L1960"> : Math.min(nextDoc, spansNextDoc[i]);</span>
}
// loop over future documents
<span class="nc bnc" id="L1963" title="All 2 branches missed."> while (nextDoc < DocIdSetIterator.NO_MORE_DOCS) {</span>
// find matches for next document
<span class="nc bnc" id="L1965" title="All 2 branches missed."> while (nextDocCounter < docSet.size()</span>
<span class="nc bnc" id="L1966" title="All 2 branches missed."> && docSet.get(nextDocCounter) < (nextDoc + docBase)) {</span>
<span class="nc" id="L1967"> nextDocCounter++;</span>
}
// finish, if no more docs in set
<span class="nc bnc" id="L1970" title="All 2 branches missed."> if (nextDocCounter >= docSet.size()) {</span>
<span class="nc" id="L1971"> break;</span>
}
// go to the matches
<span class="nc bnc" id="L1974" title="All 2 branches missed."> if (docSet.get(nextDocCounter) == nextDoc + docBase) {</span>
<span class="nc" id="L1975"> matchList = matchData.get(nextDoc + docBase);</span>
<span class="nc bnc" id="L1976" title="All 4 branches missed."> if (matchList != null && !matchList.isEmpty()) {</span>
// initialize
<span class="nc" id="L1978"> int currentMatchPosition = 0;</span>
<span class="nc" id="L1979"> int lastMatchStartPosition = matchList</span>
<span class="nc" id="L1980"> .get(matchList.size() - 1).startPosition;</span>
<span class="nc" id="L1981"> ArrayList<Match> newMatchList = new ArrayList<>(matchList.size());</span>
<span class="nc" id="L1982"> int currentSpanPosition = Spans.NO_MORE_POSITIONS;</span>
// check and initialize for each span
<span class="nc bnc" id="L1984" title="All 2 branches missed."> for (int i = 0; i < spansList.length; i++) {</span>
<span class="nc bnc" id="L1985" title="All 2 branches missed."> if (spansList[i].docID() == nextDoc) {</span>
<span class="nc" id="L1986"> int tmpStartPosition = spansList[i].nextStartPosition();</span>
<span class="nc bnc" id="L1987" title="All 2 branches missed."> if (tmpStartPosition < Spans.NO_MORE_POSITIONS) {</span>
<span class="nc" id="L1988"> finishedSpansList[i] = false;</span>
} else {
<span class="nc" id="L1990"> finishedSpansList[i] = true;</span>
}
// compute position
<span class="nc bnc" id="L1993" title="All 2 branches missed."> currentSpanPosition = (currentSpanPosition == Spans.NO_MORE_POSITIONS)</span>
? tmpStartPosition
<span class="nc" id="L1995"> : Math.min(currentSpanPosition, tmpStartPosition);</span>
<span class="nc" id="L1996"> } else {</span>
<span class="nc" id="L1997"> finishedSpansList[i] = true;</span>
}
}
// loop over matches
<span class="nc bnc" id="L2001" title="All 4 branches missed."> while (currentMatchPosition < matchList.size()</span>
&& currentSpanPosition < Spans.NO_MORE_POSITIONS) {
<span class="nc" id="L2004"> if (currentSpanPosition < matchList</span>
<span class="nc bnc" id="L2005" title="All 2 branches missed."> .get(currentMatchPosition).startPosition) {</span>
// do nothing, match not reached
<span class="nc bnc" id="L2007" title="All 2 branches missed."> } else if (currentSpanPosition > lastMatchStartPosition) {</span>
// finish, past last match
<span class="nc" id="L2009"> break;</span>
} else {
// advance matches
<span class="nc bnc" id="L2012" title="All 2 branches missed."> while (currentMatchPosition < matchList.size()</span>
&& currentSpanPosition > matchList
<span class="nc bnc" id="L2014" title="All 2 branches missed."> .get(currentMatchPosition).startPosition) {</span>
// store current match, not relevant
<span class="nc" id="L2016"> newMatchList.add(matchList.get(currentMatchPosition));</span>
<span class="nc" id="L2017"> currentMatchPosition++;</span>
}
// equal startPosition
<span class="nc bnc" id="L2020" title="All 2 branches missed."> while (currentMatchPosition < matchList.size()</span>
&& currentSpanPosition == matchList
<span class="nc bnc" id="L2022" title="All 2 branches missed."> .get(currentMatchPosition).startPosition) {</span>
// check for each span
<span class="nc bnc" id="L2024" title="All 2 branches missed."> for (int i = 0; i < spansList.length; i++) {</span>
// equal start and end, therefore match
<span class="nc bnc" id="L2026" title="All 4 branches missed."> if (!finishedSpansList[i] && spansList[i].docID() == nextDoc</span>
<span class="nc" id="L2027"> && spansList[i].startPosition() == matchList</span>
<span class="nc bnc" id="L2028" title="All 2 branches missed."> .get(currentMatchPosition).startPosition</span>
<span class="nc" id="L2029"> && spansList[i].endPosition() == matchList</span>
<span class="nc bnc" id="L2030" title="All 2 branches missed."> .get(currentMatchPosition).endPosition) {</span>
// administration
<span class="nc" id="L2032"> total++;</span>
<span class="nc" id="L2033"> subSum[i]++;</span>
<span class="nc bnc" id="L2034" title="All 2 branches missed."> if (newNextDocs[i]) {</span>
<span class="nc" id="L2035"> subN[i]++;</span>
<span class="nc" id="L2036"> newNextDocs[i] = false;</span>
<span class="nc" id="L2037"> newNextDoc = false;</span>
}
<span class="nc bnc" id="L2039" title="All 2 branches missed."> } else if (!finishedSpansList[i]</span>
<span class="nc bnc" id="L2040" title="All 2 branches missed."> && spansList[i].docID() == nextDoc</span>
<span class="nc" id="L2041"> && spansList[i].startPosition() == matchList</span>
<span class="nc bnc" id="L2042" title="All 2 branches missed."> .get(currentMatchPosition).startPosition) {</span>
// no match, store
<span class="nc" id="L2044"> newMatchList.add(matchList.get(currentMatchPosition));</span>
}
}
<span class="nc" id="L2047"> currentMatchPosition++;</span>
}
}
// advance spans
<span class="nc bnc" id="L2052" title="All 2 branches missed."> if (currentMatchPosition < matchList.size()) {</span>
<span class="nc" id="L2053"> currentSpanPosition = Spans.NO_MORE_POSITIONS;</span>
<span class="nc bnc" id="L2054" title="All 2 branches missed."> for (int i = 0; i < spansList.length; i++) {</span>
<span class="nc bnc" id="L2055" title="All 2 branches missed."> if (!finishedSpansList[i]</span>
<span class="nc bnc" id="L2056" title="All 2 branches missed."> && (spansList[i].docID() == nextDoc)) {</span>
<span class="nc bnc" id="L2057" title="All 2 branches missed."> while (!finishedSpansList[i]</span>
<span class="nc" id="L2058"> && spansList[i].startPosition() < matchList</span>
<span class="nc bnc" id="L2059" title="All 2 branches missed."> .get(currentMatchPosition).startPosition) {</span>
<span class="nc" id="L2060"> int tmpStartPosition = spansList[i].nextStartPosition();</span>
<span class="nc bnc" id="L2061" title="All 2 branches missed."> if (tmpStartPosition == Spans.NO_MORE_POSITIONS) {</span>
<span class="nc" id="L2062"> finishedSpansList[i] = true;</span>
}
<span class="nc" id="L2064"> }</span>
<span class="nc bnc" id="L2065" title="All 2 branches missed."> if (!finishedSpansList[i]) {</span>
<span class="nc bnc" id="L2066" title="All 2 branches missed."> currentSpanPosition = (currentSpanPosition == Spans.NO_MORE_POSITIONS)</span>
<span class="nc" id="L2067"> ? spansList[i].startPosition()</span>
<span class="nc" id="L2068"> : Math.min(currentSpanPosition,</span>
<span class="nc" id="L2069"> spansList[i].startPosition());</span>
}
} else {
<span class="nc" id="L2072"> finishedSpansList[i] = true;</span>
}
}
}
}
<span class="nc bnc" id="L2077" title="All 2 branches missed."> if (!newNextDoc) {</span>
// add other matches
<span class="nc bnc" id="L2079" title="All 2 branches missed."> while (currentMatchPosition < matchList.size()) {</span>
<span class="nc" id="L2080"> newMatchList.add(matchList.get(currentMatchPosition));</span>
<span class="nc" id="L2081"> currentMatchPosition++;</span>
}
// update administration
<span class="nc bnc" id="L2084" title="All 2 branches missed."> if (!newMatchList.isEmpty()) {</span>
<span class="nc" id="L2085"> matchData.put(nextDoc + docBase, newMatchList);</span>
} else {
<span class="nc" id="L2087"> matchData.put(nextDoc + docBase, null);</span>
}
}
}
}
// advance to next document
<span class="nc" id="L2093"> nextDocCounter++;</span>
<span class="nc" id="L2094"> newNextDoc = true;</span>
<span class="nc bnc" id="L2095" title="All 2 branches missed."> for (int i = 0; i < hitList.length; i++) {</span>
<span class="nc" id="L2096"> newNextDocs[i] = true;</span>
}
// advance spans
<span class="nc bnc" id="L2099" title="All 2 branches missed."> if (nextDocCounter < docSet.size()) {</span>
<span class="nc" id="L2100"> nextDoc = Spans.NO_MORE_DOCS;</span>
// advance spans
<span class="nc bnc" id="L2102" title="All 2 branches missed."> for (int i = 0; i < hitList.length; i++) {</span>
<span class="nc bnc" id="L2103" title="All 2 branches missed."> if (spansNextDoc[i] < (docSet.get(nextDocCounter) - docBase)) {</span>
<span class="nc" id="L2104"> spansNextDoc[i] = spansList[i]</span>
<span class="nc" id="L2105"> .advance(docSet.get(nextDocCounter) - docBase);</span>
}
<span class="nc bnc" id="L2107" title="All 2 branches missed."> if (spansNextDoc[i] < Spans.NO_MORE_DOCS) {</span>
<span class="nc bnc" id="L2108" title="All 2 branches missed."> nextDoc = (nextDoc == Spans.NO_MORE_DOCS) ? spansNextDoc[i]</span>
<span class="nc" id="L2109"> : Math.min(nextDoc, spansNextDoc[i]);</span>
}
}
}
}
// update administration
<span class="nc bnc" id="L2115" title="All 2 branches missed."> for (int i = 0; i < hitList.length; i++) {</span>
<span class="nc bnc" id="L2116" title="All 4 branches missed."> if (subSum[i] > 0 && (occurencesSum.containsKey(hitList[i]))) {</span>
<span class="nc" id="L2117"> occurencesSum.put(hitList[i],</span>
<span class="nc" id="L2118"> occurencesSum.get(hitList[i]) + subSum[i]);</span>
<span class="nc" id="L2119"> occurencesN.put(hitList[i], occurencesN.get(hitList[i]) + subN[i]);</span>
}
}
}
<span class="nc" id="L2124"> return total;</span>
}
/**
* Sort match list.
*
* @param list
* the list
*/
private static void sortMatchList(List<Match> list) {
<span class="pc bpc" id="L2134" title="1 of 2 branches missed."> if (list != null) {</span>
// light sorting on start position
<span class="fc" id="L2136"> Collections.sort(list, (Match m1,</span>
<span class="fc" id="L2137"> Match m2) -> (Integer.compare(m1.startPosition, m2.startPosition)));</span>
}
<span class="fc" id="L2139"> }</span>
/**
* Creates the document.
*
* @param documentList
* the document list
* @param docList
* the doc list
* @param uniqueKeyField
* the unique key field
* @param searcher
* the searcher
* @param t
* the t
* @param lrc
* the lrc
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createDocument(List<ComponentDocument> documentList,
List<Integer> docList, String uniqueKeyField, IndexSearcher searcher,
Terms t, LeafReaderContext lrc) throws IOException {
<span class="nc bnc" id="L2162" title="All 2 branches missed."> if (documentList != null) {</span>
<span class="nc" id="L2163"> SortedSet<String> listStatsItems = CodecUtil.createStatsItems("sum");</span>
<span class="nc" id="L2164"> String listStatsType = CodecUtil.createStatsType(listStatsItems,</span>
CodecUtil.STATS_TYPE_SUM, null);
<span class="nc bnc" id="L2166" title="All 2 branches missed."> for (ComponentDocument document : documentList) {</span>
// initialize
<span class="nc bnc" id="L2168" title="All 2 branches missed."> for (int docId : docList) {</span>
// get unique id
<span class="nc" id="L2170"> Document doc = searcher.doc(docId,</span>
<span class="nc" id="L2171"> new HashSet<String>(Arrays.asList(uniqueKeyField)));</span>
<span class="nc" id="L2172"> IndexableField indxfld = doc.getField(uniqueKeyField);</span>
// get other doc info
<span class="nc bnc" id="L2174" title="All 2 branches missed."> if (indxfld != null) {</span>
<span class="nc" id="L2175"> document.uniqueKey.put(docId, indxfld.stringValue());</span>
<span class="nc" id="L2176"> MtasDataCollector<?, ?> stats = DataCollector.getCollector(</span>
DataCollector.COLLECTOR_TYPE_DATA, document.dataType,
document.statsType, document.statsItems, null, null, null, null,
null, null);
<span class="nc" id="L2180"> document.statsData.put(docId, stats);</span>
<span class="nc bnc" id="L2181" title="All 2 branches missed."> if (document.statsList != null) {</span>
MtasDataCollector<?, ?> list;
<span class="nc bnc" id="L2183" title="All 2 branches missed."> if (document.listExpand) {</span>
<span class="nc" id="L2184"> SortedSet<String>[] baseStatsItems = new SortedSet[] {</span>
listStatsItems };
<span class="nc" id="L2186"> list = DataCollector.getCollector(</span>
DataCollector.COLLECTOR_TYPE_LIST, CodecUtil.DATA_TYPE_LONG,
listStatsType, listStatsItems, CodecUtil.STATS_TYPE_SUM,
<span class="nc" id="L2189"> CodecUtil.SORT_DESC, 0, document.listNumber,</span>
new String[] { DataCollector.COLLECTOR_TYPE_LIST },
new String[] { CodecUtil.DATA_TYPE_LONG },
new String[] { listStatsType },
<span class="nc" id="L2193"> Arrays.copyOfRange(baseStatsItems, 0,</span>
baseStatsItems.length),
new String[] { CodecUtil.STATS_TYPE_SUM },
<span class="nc" id="L2196"> new String[] { CodecUtil.SORT_DESC }, new Integer[] { 0 },</span>
<span class="nc" id="L2197"> new Integer[] { document.listExpandNumber }, null, null);</span>
<span class="nc" id="L2198"> } else {</span>
<span class="nc" id="L2199"> list = DataCollector.getCollector(</span>
DataCollector.COLLECTOR_TYPE_LIST, CodecUtil.DATA_TYPE_LONG,
listStatsType, listStatsItems, CodecUtil.STATS_TYPE_SUM,
<span class="nc" id="L2202"> CodecUtil.SORT_DESC, 0, document.listNumber, null, null);</span>
}
<span class="nc" id="L2204"> document.statsList.put(docId, list);</span>
}
}
<span class="nc" id="L2207"> }</span>
<span class="nc" id="L2208"> }</span>
// collect
<span class="nc bnc" id="L2210" title="All 2 branches missed."> if (t != null) {</span>
BytesRef term;
TermsEnum termsEnum;
<span class="nc" id="L2213"> PostingsEnum postingsEnum = null;</span>
// loop over termvectors
<span class="nc bnc" id="L2215" title="All 2 branches missed."> for (ComponentDocument document : documentList) {</span>
List<CompiledAutomaton> listAutomata;
Map<String, Automaton> automatonMap;
Map<String, ByteRunAutomaton> byteRunAutomatonMap;
<span class="nc bnc" id="L2220" title="All 2 branches missed."> if (document.list == null) {</span>
<span class="nc" id="L2221"> automatonMap = null;</span>
<span class="nc" id="L2222"> byteRunAutomatonMap = null;</span>
<span class="nc" id="L2223"> listAutomata = new ArrayList<>();</span>
CompiledAutomaton compiledAutomaton;
Automaton automaton;
<span class="nc bnc" id="L2226" title="All 4 branches missed."> if ((document.regexp == null) || (document.regexp.isEmpty())) {</span>
<span class="nc" id="L2227"> RegExp re = new RegExp(</span>
document.prefix + MtasToken.DELIMITER + ".*");
<span class="nc" id="L2229"> automaton = re.toAutomaton();</span>
<span class="nc" id="L2230"> } else {</span>
<span class="nc" id="L2231"> RegExp re = new RegExp(document.prefix + MtasToken.DELIMITER</span>
+ document.regexp + "\u0000*");
<span class="nc" id="L2233"> automaton = re.toAutomaton();</span>
}
<span class="nc" id="L2235"> compiledAutomaton = new CompiledAutomaton(automaton);</span>
<span class="nc" id="L2236"> listAutomata.add(compiledAutomaton);</span>
<span class="nc" id="L2237"> } else {</span>
<span class="nc bnc" id="L2238" title="All 2 branches missed."> automatonMap = MtasToken.createAutomatonMap(document.prefix,</span>
new ArrayList<String>(document.list),
<span class="nc" id="L2240"> document.listRegexp ? false : true);</span>
<span class="nc" id="L2241"> byteRunAutomatonMap = MtasToken.byteRunAutomatonMap(automatonMap);</span>
<span class="nc" id="L2242"> listAutomata = MtasToken.createAutomata(document.prefix,</span>
document.regexp, automatonMap);
}
<span class="nc" id="L2245"> List<ByteRunAutomaton> ignoreByteRunAutomatonList = null;</span>
<span class="nc bnc" id="L2246" title="All 2 branches missed."> if ((document.ignoreRegexp != null)</span>
<span class="nc bnc" id="L2247" title="All 2 branches missed."> && (!document.ignoreRegexp.isEmpty())) {</span>
<span class="nc" id="L2248"> ignoreByteRunAutomatonList = new ArrayList<>();</span>
<span class="nc" id="L2249"> RegExp re = new RegExp(document.prefix + MtasToken.DELIMITER</span>
+ document.ignoreRegexp + "\u0000*");
<span class="nc" id="L2251"> ignoreByteRunAutomatonList</span>
<span class="nc" id="L2252"> .add(new ByteRunAutomaton(re.toAutomaton()));</span>
}
<span class="nc bnc" id="L2254" title="All 2 branches missed."> if (document.ignoreList != null) {</span>
<span class="nc bnc" id="L2255" title="All 2 branches missed."> if (ignoreByteRunAutomatonList == null) {</span>
<span class="nc" id="L2256"> ignoreByteRunAutomatonList = new ArrayList<>();</span>
}
<span class="nc bnc" id="L2258" title="All 2 branches missed."> Map<String, Automaton> list = MtasToken.createAutomatonMap(</span>
document.prefix, new ArrayList<String>(document.ignoreList),
<span class="nc" id="L2260"> document.ignoreListRegexp ? false : true);</span>
<span class="nc bnc" id="L2261" title="All 2 branches missed."> for (Automaton automaton : list.values()) {</span>
<span class="nc" id="L2262"> ignoreByteRunAutomatonList.add(new ByteRunAutomaton(automaton));</span>
<span class="nc" id="L2263"> }</span>
}
<span class="nc bnc" id="L2266" title="All 2 branches missed."> for (CompiledAutomaton compiledAutomaton : listAutomata) {</span>
<span class="nc" id="L2267"> if (!compiledAutomaton.type</span>
<span class="nc bnc" id="L2268" title="All 2 branches missed."> .equals(CompiledAutomaton.AUTOMATON_TYPE.NONE)) {</span>
<span class="nc" id="L2269"> termsEnum = t.intersect(compiledAutomaton, null);</span>
// init
<span class="nc" id="L2271"> int initBaseSize = Math.min((int) t.size(), 1000);</span>
<span class="nc bnc" id="L2272" title="All 2 branches missed."> int initListSize = document.statsList != null</span>
<span class="nc" id="L2273"> ? Math.min(document.statsList.size(), initBaseSize)</span>
: initBaseSize;
<span class="nc" id="L2275"> HashSet<MtasDataCollector<?, ?>> initialised = new HashSet<>();</span>
<span class="nc bnc" id="L2276" title="All 2 branches missed."> for (int docId : docList) {</span>
<span class="nc" id="L2277"> document.statsData.get(docId).initNewList(1);</span>
<span class="nc" id="L2278"> initialised.add(document.statsData.get(docId));</span>
<span class="nc bnc" id="L2279" title="All 2 branches missed."> if (document.statsList != null</span>
<span class="nc bnc" id="L2280" title="All 2 branches missed."> && document.statsList.size() > 0) {</span>
<span class="nc" id="L2281"> document.statsList.get(docId).initNewList(initListSize);</span>
<span class="nc" id="L2282"> initialised.add(document.statsList.get(docId));</span>
}
<span class="nc" id="L2284"> }</span>
// fill
int termDocId;
boolean acceptedTerm;
<span class="nc bnc" id="L2288" title="All 2 branches missed."> while ((term = termsEnum.next()) != null) {</span>
<span class="nc" id="L2289"> Iterator<Integer> docIterator = docList.iterator();</span>
<span class="nc" id="L2290"> postingsEnum = termsEnum.postings(postingsEnum,</span>
PostingsEnum.FREQS);
<span class="nc" id="L2292"> termDocId = -1;</span>
<span class="nc" id="L2293"> acceptedTerm = true;</span>
<span class="nc bnc" id="L2294" title="All 2 branches missed."> if (ignoreByteRunAutomatonList != null) {</span>
<span class="nc bnc" id="L2295" title="All 2 branches missed."> for (ByteRunAutomaton ignoreByteRunAutomaton : ignoreByteRunAutomatonList) {</span>
<span class="nc bnc" id="L2296" title="All 2 branches missed."> if (ignoreByteRunAutomaton.run(term.bytes, term.offset,</span>
term.length)) {
<span class="nc" id="L2298"> acceptedTerm = false;</span>
<span class="nc" id="L2299"> break;</span>
}
<span class="nc" id="L2301"> }</span>
}
<span class="nc bnc" id="L2303" title="All 2 branches missed."> if (acceptedTerm) {</span>
<span class="nc bnc" id="L2304" title="All 2 branches missed."> while (docIterator.hasNext()) {</span>
<span class="nc" id="L2305"> int segmentDocId = docIterator.next() - lrc.docBase;</span>
<span class="nc bnc" id="L2306" title="All 4 branches missed."> if (segmentDocId >= termDocId</span>
&& ((segmentDocId == termDocId)
|| ((termDocId = postingsEnum
<span class="nc bnc" id="L2309" title="All 2 branches missed."> .advance(segmentDocId)) == segmentDocId))) {</span>
// register stats
<span class="nc" id="L2311"> document.statsData.get(segmentDocId + lrc.docBase)</span>
<span class="nc" id="L2312"> .add(new long[] { postingsEnum.freq() }, 1);</span>
// register list
<span class="nc bnc" id="L2314" title="All 2 branches missed."> if (document.statsList != null) {</span>
<span class="nc bnc" id="L2315" title="All 2 branches missed."> if (automatonMap != null) {</span>
MtasDataCollector<?, ?> dataCollector;
MtasDataCollector<?, ?> subSataCollector;
<span class="nc bnc" id="L2318" title="All 2 branches missed."> for (Entry<String, ByteRunAutomaton> entry : byteRunAutomatonMap</span>
<span class="nc" id="L2319"> .entrySet()) {</span>
<span class="nc" id="L2320"> ByteRunAutomaton bra = entry.getValue();</span>
<span class="nc bnc" id="L2321" title="All 2 branches missed."> if (bra.run(term.bytes, term.offset, term.length)) {</span>
<span class="nc" id="L2322"> dataCollector = document.statsList</span>
<span class="nc" id="L2323"> .get(segmentDocId + lrc.docBase);</span>
<span class="nc" id="L2324"> subSataCollector = dataCollector.add(</span>
<span class="nc" id="L2325"> entry.getKey(),</span>
<span class="nc" id="L2326"> new long[] { postingsEnum.freq() }, 1);</span>
<span class="nc bnc" id="L2327" title="All 4 branches missed."> if (document.listExpand</span>
&& subSataCollector != null) {
<span class="nc bnc" id="L2329" title="All 2 branches missed."> if (!initialised.contains(subSataCollector)) {</span>
<span class="nc" id="L2330"> subSataCollector.initNewList(initBaseSize);</span>
<span class="nc" id="L2331"> initialised.add(subSataCollector);</span>
}
<span class="nc" id="L2333"> subSataCollector.add(</span>
<span class="nc" id="L2334"> MtasToken.getPostfixFromValue(term),</span>
<span class="nc" id="L2335"> new long[] { postingsEnum.freq() }, 1);</span>
}
}
<span class="nc" id="L2338"> }</span>
} else {
<span class="nc" id="L2340"> document.statsList.get(segmentDocId + lrc.docBase)</span>
<span class="nc" id="L2341"> .add(MtasToken.getPostfixFromValue(term),</span>
<span class="nc" id="L2342"> new long[] { postingsEnum.freq() }, 1);</span>
}
}
}
<span class="nc" id="L2346"> }</span>
}
<span class="nc" id="L2348"> }</span>
// close
<span class="nc bnc" id="L2350" title="All 2 branches missed."> for (MtasDataCollector<?, ?> item : initialised) {</span>
<span class="nc" id="L2351"> item.closeNewList();</span>
<span class="nc" id="L2352"> }</span>
<span class="nc" id="L2353"> initialised.clear();</span>
}
<span class="nc" id="L2355"> }</span>
<span class="nc" id="L2356"> }</span>
}
}
<span class="nc" id="L2359"> }</span>
/**
* Creates the kwic.
*
* @param kwicList
* the kwic list
* @param spansMatchData
* the spans match data
* @param docList
* the doc list
* @param field
* the field
* @param docBase
* the doc base
* @param uniqueKeyField
* the unique key field
* @param mtasCodecInfo
* the mtas codec info
* @param searcher
* the searcher
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createKwic(List<ComponentKwic> kwicList,
Map<MtasSpanQuery, Map<Integer, List<Match>>> spansMatchData,
List<Integer> docList, String field, int docBase, String uniqueKeyField,
CodecInfo mtasCodecInfo, IndexSearcher searcher) throws IOException {
<span class="nc bnc" id="L2387" title="All 2 branches missed."> if (kwicList != null) {</span>
<span class="nc bnc" id="L2388" title="All 2 branches missed."> for (ComponentKwic kwic : kwicList) {</span>
<span class="nc" id="L2389"> Map<Integer, List<Match>> matchData = spansMatchData.get(kwic.query);</span>
List<Match> matchList;
<span class="nc bnc" id="L2391" title="All 2 branches missed."> if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)) {</span>
<span class="nc bnc" id="L2392" title="All 2 branches missed."> for (int docId : docList) {</span>
<span class="nc bnc" id="L2393" title="All 2 branches missed."> if (matchData != null</span>
<span class="nc bnc" id="L2394" title="All 2 branches missed."> && (matchList = matchData.get(docId)) != null) {</span>
// get unique id
<span class="nc" id="L2396"> Document doc = searcher.doc(docId,</span>
<span class="nc" id="L2397"> new HashSet<String>(Arrays.asList(uniqueKeyField)));</span>
<span class="nc" id="L2398"> IndexableField indxfld = doc.getField(uniqueKeyField);</span>
// get other doc info
<span class="nc bnc" id="L2400" title="All 2 branches missed."> if (indxfld != null) {</span>
<span class="nc" id="L2401"> kwic.uniqueKey.put(docId, indxfld.stringValue());</span>
}
<span class="nc" id="L2403"> kwic.subTotal.put(docId, matchList.size());</span>
<span class="nc" id="L2404"> IndexDoc mDoc = mtasCodecInfo.getDoc(field, (docId - docBase));</span>
<span class="nc bnc" id="L2405" title="All 2 branches missed."> if (mDoc != null) {</span>
<span class="nc" id="L2406"> kwic.minPosition.put(docId, mDoc.minPosition);</span>
<span class="nc" id="L2407"> kwic.maxPosition.put(docId, mDoc.maxPosition);</span>
}
// kwiclist
<span class="nc" id="L2410"> List<KwicHit> kwicItemList = new ArrayList<>();</span>
<span class="nc" id="L2411"> int number = 0;</span>
<span class="nc bnc" id="L2412" title="All 2 branches missed."> for (Match m : matchList) {</span>
<span class="nc bnc" id="L2413" title="All 2 branches missed."> if (kwic.number != null</span>
<span class="nc bnc" id="L2414" title="All 2 branches missed."> && number >= (kwic.start + kwic.number)) {</span>
<span class="nc" id="L2415"> break;</span>
}
<span class="nc bnc" id="L2417" title="All 2 branches missed."> if (number >= kwic.start) {</span>
<span class="nc" id="L2418"> int startPosition = m.startPosition;</span>
<span class="nc" id="L2419"> int endPosition = m.endPosition - 1;</span>
<span class="nc" id="L2420"> List<MtasTreeHit<String>> terms = mtasCodecInfo</span>
<span class="nc" id="L2421"> .getPositionedTermsByPrefixesAndPositionRange(field,</span>
(docId - docBase), kwic.prefixes,
<span class="nc" id="L2423"> Math.max(mDoc.minPosition, startPosition - kwic.left),</span>
<span class="nc" id="L2424"> Math.min(mDoc.maxPosition, endPosition + kwic.right));</span>
// construct hit
<span class="nc" id="L2426"> Map<Integer, List<String>> kwicListHits = new HashMap<>();</span>
<span class="nc" id="L2427"> for (int position = Math.max(mDoc.minPosition,</span>
<span class="nc bnc" id="L2428" title="All 2 branches missed."> startPosition - kwic.left); position <= Math.min(</span>
mDoc.maxPosition,
<span class="nc" id="L2430"> endPosition + kwic.right); position++) {</span>
<span class="nc" id="L2431"> kwicListHits.put(position, new ArrayList<String>());</span>
}
List<String> termList;
<span class="nc bnc" id="L2434" title="All 2 branches missed."> for (MtasTreeHit<String> term : terms) {</span>
<span class="nc" id="L2435"> for (int position = Math.max((startPosition - kwic.left),</span>
<span class="nc bnc" id="L2436" title="All 2 branches missed."> term.startPosition); position <= Math.min(</span>
(endPosition + kwic.right),
<span class="nc" id="L2438"> term.endPosition); position++) {</span>
<span class="nc" id="L2439"> termList = kwicListHits.get(position);</span>
<span class="nc" id="L2440"> termList.add(term.data);</span>
}
<span class="nc" id="L2442"> }</span>
<span class="nc" id="L2443"> kwicItemList.add(new KwicHit(m, kwicListHits));</span>
}
<span class="nc" id="L2445"> number++;</span>
<span class="nc" id="L2446"> }</span>
<span class="nc" id="L2447"> kwic.hits.put(docId, kwicItemList);</span>
}
<span class="nc" id="L2449"> }</span>
<span class="nc bnc" id="L2450" title="All 2 branches missed."> } else if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_TOKEN)) {</span>
<span class="nc bnc" id="L2451" title="All 2 branches missed."> for (int docId : docList) {</span>
<span class="nc bnc" id="L2452" title="All 2 branches missed."> if (matchData != null</span>
<span class="nc bnc" id="L2453" title="All 2 branches missed."> && (matchList = matchData.get(docId)) != null) {</span>
// get unique id
<span class="nc" id="L2455"> Document doc = searcher.doc(docId,</span>
<span class="nc" id="L2456"> new HashSet<String>(Arrays.asList(uniqueKeyField)));</span>
// get other doc info
<span class="nc" id="L2458"> IndexableField indxfld = doc.getField(uniqueKeyField);</span>
<span class="nc bnc" id="L2459" title="All 2 branches missed."> if (indxfld != null) {</span>
<span class="nc" id="L2460"> kwic.uniqueKey.put(docId, indxfld.stringValue());</span>
}
<span class="nc" id="L2462"> kwic.subTotal.put(docId, matchList.size());</span>
<span class="nc" id="L2463"> IndexDoc mDoc = mtasCodecInfo.getDoc(field, (docId - docBase));</span>
<span class="nc bnc" id="L2464" title="All 2 branches missed."> if (mDoc != null) {</span>
<span class="nc" id="L2465"> kwic.minPosition.put(docId, mDoc.minPosition);</span>
<span class="nc" id="L2466"> kwic.maxPosition.put(docId, mDoc.maxPosition);</span>
<span class="nc" id="L2467"> List<KwicToken> kwicItemList = new ArrayList<>();</span>
<span class="nc" id="L2468"> int number = 0;</span>
<span class="nc bnc" id="L2469" title="All 2 branches missed."> for (Match m : matchList) {</span>
<span class="nc bnc" id="L2470" title="All 2 branches missed."> if (kwic.number != null</span>
<span class="nc bnc" id="L2471" title="All 2 branches missed."> && number >= (kwic.start + kwic.number)) {</span>
<span class="nc" id="L2472"> break;</span>
}
<span class="nc bnc" id="L2474" title="All 2 branches missed."> if (number >= kwic.start) {</span>
<span class="nc" id="L2475"> int startPosition = m.startPosition;</span>
<span class="nc" id="L2476"> int endPosition = m.endPosition - 1;</span>
List<MtasTokenString> tokens;
<span class="nc" id="L2478"> tokens = mtasCodecInfo.getPrefixFilteredObjectsByPositions(</span>
field, (docId - docBase), kwic.prefixes,
<span class="nc" id="L2480"> Math.max(mDoc.minPosition, startPosition - kwic.left),</span>
<span class="nc" id="L2481"> Math.min(mDoc.maxPosition, endPosition + kwic.right));</span>
<span class="nc" id="L2482"> kwicItemList.add(new KwicToken(m, tokens));</span>
}
<span class="nc" id="L2484"> number++;</span>
<span class="nc" id="L2485"> }</span>
<span class="nc" id="L2486"> kwic.tokens.put(docId, kwicItemList);</span>
}
}
<span class="nc" id="L2489"> }</span>
}
<span class="nc" id="L2491"> }</span>
}
<span class="nc" id="L2493"> }</span>
/**
* Creates the facet base.
*
* @param cf
* the cf
* @param level
* the level
* @param dataCollector
* the data collector
* @param positionsData
* the positions data
* @param spansNumberData
* the spans number data
* @param facetData
* the facet data
* @param docSet
* the doc set
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createFacetBase(ComponentFacet cf, int level,
MtasDataCollector<?, ?> dataCollector,
Map<Integer, Integer> positionsData,
Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData,
Map<String, SortedMap<String, int[]>> facetData, Integer[] docSet)
throws IOException {
<span class="nc bnc" id="L2521" title="All 2 branches missed."> for (MtasFunctionParserFunction function : cf.baseFunctionParserFunctions[level]) {</span>
<span class="nc bnc" id="L2522" title="All 2 branches missed."> if (function.needArgumentsNumber() > cf.spanQueries.length) {</span>
<span class="nc" id="L2523"> throw new IOException("function " + function + " expects (at least) "</span>
<span class="nc" id="L2524"> + function.needArgumentsNumber() + " queries");</span>
}
}
<span class="nc" id="L2527"> Map<String, int[]> list = facetData.get(cf.baseFields[level]);</span>
<span class="nc bnc" id="L2528" title="All 2 branches missed."> if (dataCollector != null) {</span>
<span class="nc" id="L2529"> MtasDataCollector<?, ?> subDataCollector = null;</span>
<span class="nc" id="L2530"> dataCollector.initNewList(1);</span>
<span class="nc bnc" id="L2531" title="All 2 branches missed."> if (cf.baseFunctionList[level] != null) {</span>
SubComponentFunction[] tmpList;
<span class="nc bnc" id="L2533" title="All 2 branches missed."> if (!cf.baseFunctionList[level].containsKey(dataCollector)) {</span>
<span class="nc" id="L2534"> tmpList = new SubComponentFunction[cf.baseFunctionParserFunctions[level].length];</span>
<span class="nc" id="L2535"> cf.baseFunctionList[level].put(dataCollector, tmpList);</span>
<span class="nc bnc" id="L2536" title="All 2 branches missed."> for (int i = 0; i < cf.baseFunctionParserFunctions[level].length; i++) {</span>
try {
<span class="nc" id="L2538"> tmpList[i] = new SubComponentFunction(</span>
DataCollector.COLLECTOR_TYPE_LIST,
cf.baseFunctionKeys[level][i], cf.baseFunctionTypes[level][i],
<span class="nc" id="L2541"> cf.baseFunctionParserFunctions[level][i], null, null, 0,</span>
<span class="nc" id="L2542"> Integer.MAX_VALUE, null, null);</span>
<span class="nc" id="L2544"> } catch (ParseException e) {</span>
<span class="nc" id="L2545"> throw new IOException(e.getMessage());</span>
<span class="nc" id="L2546"> }</span>
}
} else {
<span class="nc" id="L2549"> tmpList = cf.baseFunctionList[level].get(dataCollector);</span>
}
<span class="nc bnc" id="L2551" title="All 2 branches missed."> for (SubComponentFunction function : tmpList) {</span>
<span class="nc" id="L2552"> function.dataCollector.initNewList(1);</span>
}
}
// check type
<span class="nc" id="L2556"> if (dataCollector.getCollectorType()</span>
<span class="nc bnc" id="L2557" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L2558"> dataCollector.setWithTotal();</span>
// only if documents and facets
<span class="nc bnc" id="L2560" title="All 4 branches missed."> if (docSet.length > 0 && list.size() > 0) {</span>
<span class="nc" id="L2561"> HashMap<String, Integer[]> docLists = new HashMap<>();</span>
<span class="nc" id="L2562"> HashMap<String, String> groupedKeys = new HashMap<>();</span>
<span class="nc" id="L2563"> boolean documentsInFacets = false;</span>
// compute intersections
<span class="nc bnc" id="L2565" title="All 2 branches missed."> for (Entry<String, int[]> entry : list.entrySet()) {</span>
// fill grouped keys
<span class="nc bnc" id="L2567" title="All 2 branches missed."> if (!groupedKeys.containsKey(entry.getKey())) {</span>
<span class="nc" id="L2568"> groupedKeys.put(entry.getKey(), groupedKeyName(entry.getKey(),</span>
cf.baseRangeSizes[level], cf.baseRangeBases[level]));
}
// intersect docSet with docList
<span class="nc" id="L2572"> Integer[] docList = intersectedDocList(entry.getValue(), docSet);</span>
<span class="nc bnc" id="L2573" title="All 4 branches missed."> if (docList != null && docList.length > 0) {</span>
<span class="nc" id="L2574"> documentsInFacets = true;</span>
}
// update docLists
<span class="nc bnc" id="L2577" title="All 2 branches missed."> if (docLists.containsKey(groupedKeys.get(entry.getKey()))) {</span>
<span class="nc" id="L2578"> docLists.put(groupedKeys.get(entry.getKey()), mergeDocLists(</span>
<span class="nc" id="L2579"> docLists.get(groupedKeys.get(entry.getKey())), docList));</span>
} else {
<span class="nc" id="L2581"> docLists.put(groupedKeys.get(entry.getKey()), docList);</span>
}
<span class="nc" id="L2583"> }</span>
// compute stats for each key
<span class="nc bnc" id="L2585" title="All 2 branches missed."> if (documentsInFacets) {</span>
<span class="nc" id="L2586"> Map<Integer, long[]> args = computeArguments(spansNumberData,</span>
cf.spanQueries, docSet);
<span class="nc bnc" id="L2588" title="All 2 branches missed."> if (cf.baseDataTypes[level].equals(CodecUtil.DATA_TYPE_LONG)) {</span>
// check functions
<span class="nc" id="L2590"> boolean applySumRule = false;</span>
<span class="nc bnc" id="L2591" title="All 2 branches missed."> if (cf.baseStatsTypes[level].equals(CodecUtil.STATS_BASIC)</span>
<span class="nc bnc" id="L2592" title="All 6 branches missed."> && cf.baseParsers[level].sumRule()</span>
&& (cf.baseMinimumLongs[level] == null)
&& (cf.baseMaximumLongs[level] == null)) {
<span class="nc" id="L2595"> applySumRule = true;</span>
<span class="nc bnc" id="L2596" title="All 2 branches missed."> if (cf.baseFunctionList[level].get(dataCollector) != null) {</span>
for (SubComponentFunction function : cf.baseFunctionList[level]
<span class="nc bnc" id="L2598" title="All 2 branches missed."> .get(dataCollector)) {</span>
<span class="nc bnc" id="L2599" title="All 2 branches missed."> if (!function.statsType.equals(CodecUtil.STATS_BASIC)</span>
<span class="nc bnc" id="L2600" title="All 2 branches missed."> || !function.parserFunction.sumRule()</span>
<span class="nc bnc" id="L2601" title="All 2 branches missed."> || function.parserFunction.needPositions()) {</span>
<span class="nc" id="L2602"> applySumRule = false;</span>
<span class="nc" id="L2603"> break;</span>
}
}
}
}
<span class="nc bnc" id="L2608" title="All 2 branches missed."> if (applySumRule) {</span>
<span class="nc bnc" id="L2609" title="All 2 branches missed."> for (String key : new LinkedHashSet<String>(</span>
<span class="nc" id="L2610"> groupedKeys.values())) {</span>
<span class="nc bnc" id="L2611" title="All 2 branches missed."> if (docLists.get(key).length > 0) {</span>
// initialise
<span class="nc" id="L2613"> Integer[] subDocSet = docLists.get(key);</span>
<span class="nc" id="L2614"> int length = cf.baseParsers[level].needArgumentsNumber();</span>
<span class="nc" id="L2615"> long[] valueSum = new long[length];</span>
<span class="nc" id="L2616"> long valuePositions = 0;</span>
// collect
<span class="nc bnc" id="L2618" title="All 2 branches missed."> if (subDocSet.length > 0) {</span>
long[] tmpArgs;
<span class="nc bnc" id="L2620" title="All 2 branches missed."> for (int docId : subDocSet) {</span>
<span class="nc" id="L2621"> tmpArgs = args.get(docId);</span>
<span class="nc bnc" id="L2622" title="All 2 branches missed."> if (positionsData != null</span>
<span class="nc bnc" id="L2623" title="All 2 branches missed."> && positionsData.containsKey(docId)</span>
<span class="nc bnc" id="L2624" title="All 2 branches missed."> && positionsData.get(docId) != null) {</span>
<span class="nc" id="L2625"> valuePositions += positionsData.get(docId)</span>
<span class="nc" id="L2626"> .longValue();</span>
}
<span class="nc bnc" id="L2628" title="All 2 branches missed."> if (tmpArgs != null) {</span>
<span class="nc bnc" id="L2629" title="All 2 branches missed."> for (int i = 0; i < length; i++) {</span>
<span class="nc" id="L2630"> valueSum[i] += tmpArgs[i];</span>
}
}
}
long value;
try {
<span class="nc" id="L2636"> value = cf.baseParsers[level].getValueLong(valueSum,</span>
valuePositions);
<span class="nc" id="L2638"> subDataCollector = dataCollector.add(key, value,</span>
subDocSet.length);
<span class="nc" id="L2640"> } catch (IOException e) {</span>
<span class="nc" id="L2641"> log.debug(e);</span>
<span class="nc" id="L2642"> dataCollector.error(key, e.getMessage());</span>
<span class="nc" id="L2643"> subDataCollector = null;</span>
<span class="nc" id="L2644"> }</span>
<span class="nc bnc" id="L2645" title="All 2 branches missed."> if (cf.baseFunctionList[level] != null</span>
&& cf.baseFunctionList[level]
<span class="nc bnc" id="L2647" title="All 2 branches missed."> .containsKey(dataCollector)) {</span>
<span class="nc" id="L2648"> SubComponentFunction[] functionList = cf.baseFunctionList[level]</span>
<span class="nc" id="L2649"> .get(dataCollector);</span>
<span class="nc bnc" id="L2650" title="All 2 branches missed."> for (SubComponentFunction function : functionList) {</span>
<span class="nc" id="L2651"> if (function.dataType</span>
<span class="nc bnc" id="L2652" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
try {
<span class="nc" id="L2654"> long valueLong = function.parserFunction</span>
<span class="nc" id="L2655"> .getValueLong(valueSum, valuePositions);</span>
<span class="nc" id="L2656"> function.dataCollector.add(key, valueLong,</span>
subDocSet.length);
<span class="nc" id="L2658"> } catch (IOException e) {</span>
<span class="nc" id="L2659"> log.debug(e);</span>
<span class="nc" id="L2660"> function.dataCollector.error(key, e.getMessage());</span>
<span class="nc" id="L2661"> }</span>
<span class="nc" id="L2662"> } else if (function.dataType</span>
<span class="nc bnc" id="L2663" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
try {
<span class="nc" id="L2665"> double valueDouble = function.parserFunction</span>
<span class="nc" id="L2666"> .getValueDouble(valueSum, valuePositions);</span>
<span class="nc" id="L2667"> function.dataCollector.add(key, valueDouble,</span>
subDocSet.length);
<span class="nc" id="L2669"> } catch (IOException e) {</span>
<span class="nc" id="L2670"> log.debug(e);</span>
<span class="nc" id="L2671"> function.dataCollector.error(key, e.getMessage());</span>
<span class="nc" id="L2672"> }</span>
}
}
}
<span class="nc bnc" id="L2676" title="All 2 branches missed."> if (subDataCollector != null) {</span>
<span class="nc" id="L2677"> createFacetBase(cf, (level + 1), subDataCollector,</span>
positionsData, spansNumberData, facetData,
subDocSet);
}
}
}
<span class="nc" id="L2683"> }</span>
} else {
<span class="nc bnc" id="L2685" title="All 2 branches missed."> for (String key : new LinkedHashSet<String>(</span>
<span class="nc" id="L2686"> groupedKeys.values())) {</span>
<span class="nc bnc" id="L2687" title="All 2 branches missed."> if (docLists.get(key).length > 0) {</span>
// initialise
<span class="nc" id="L2689"> Integer[] subDocSet = docLists.get(key);</span>
// collect
<span class="nc bnc" id="L2691" title="All 2 branches missed."> if (subDocSet.length > 0 && cf.baseDataTypes[level]</span>
<span class="nc bnc" id="L2692" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
// check for functions
<span class="nc" id="L2694"> long[][] functionValuesLong = null;</span>
<span class="nc" id="L2695"> double[][] functionValuesDouble = null;</span>
<span class="nc" id="L2696"> int[] functionNumber = null;</span>
<span class="nc" id="L2697"> SubComponentFunction[] functionList = null;</span>
<span class="nc bnc" id="L2698" title="All 2 branches missed."> if (cf.baseFunctionList[level] != null</span>
&& cf.baseFunctionList[level]
<span class="nc bnc" id="L2700" title="All 2 branches missed."> .containsKey(dataCollector)) {</span>
<span class="nc" id="L2701"> functionList = cf.baseFunctionList[level]</span>
<span class="nc" id="L2702"> .get(dataCollector);</span>
<span class="nc" id="L2703"> functionValuesLong = new long[functionList.length][];</span>
<span class="nc" id="L2704"> functionValuesDouble = new double[functionList.length][];</span>
<span class="nc" id="L2705"> functionNumber = new int[functionList.length];</span>
<span class="nc bnc" id="L2706" title="All 2 branches missed."> for (int i = 0; i < functionList.length; i++) {</span>
<span class="nc" id="L2707"> functionValuesLong[i] = new long[subDocSet.length];</span>
<span class="nc" id="L2708"> functionValuesDouble[i] = new double[subDocSet.length];</span>
}
}
// check main
<span class="nc" id="L2712"> int number = 0;</span>
<span class="nc" id="L2713"> Integer[] restrictedSubDocSet = new Integer[subDocSet.length];</span>
<span class="nc" id="L2714"> long[] values = new long[subDocSet.length];</span>
<span class="nc bnc" id="L2715" title="All 2 branches missed."> for (int docId : subDocSet) {</span>
<span class="nc" id="L2716"> long[] tmpArgs = args.get(docId);</span>
<span class="nc bnc" id="L2717" title="All 2 branches missed."> int tmpPositions = (positionsData == null) ? 0</span>
<span class="nc bnc" id="L2718" title="All 2 branches missed."> : (positionsData.get(docId) == null ? 0</span>
<span class="nc" id="L2719"> : positionsData.get(docId));</span>
<span class="nc" id="L2720"> long value = cf.baseParsers[level].getValueLong(tmpArgs,</span>
tmpPositions);
<span class="nc bnc" id="L2722" title="All 2 branches missed."> if ((cf.baseMinimumLongs[level] == null</span>
<span class="nc bnc" id="L2723" title="All 4 branches missed."> || value >= cf.baseMinimumLongs[level])</span>
&& (cf.baseMaximumLongs[level] == null
<span class="nc bnc" id="L2725" title="All 2 branches missed."> || value <= cf.baseMaximumLongs[level])) {</span>
<span class="nc" id="L2726"> values[number] = value;</span>
<span class="nc" id="L2727"> restrictedSubDocSet[number] = docId;</span>
<span class="nc" id="L2728"> number++;</span>
<span class="nc bnc" id="L2729" title="All 2 branches missed."> if (functionList != null) {</span>
<span class="nc bnc" id="L2730" title="All 2 branches missed."> for (int i = 0; i < functionList.length; i++) {</span>
<span class="nc" id="L2731"> SubComponentFunction function = functionList[i];</span>
<span class="nc" id="L2732"> if (function.dataType</span>
<span class="nc bnc" id="L2733" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
try {
<span class="nc" id="L2735"> functionValuesLong[i][functionNumber[i]] = function.parserFunction</span>
<span class="nc" id="L2736"> .getValueLong(tmpArgs, tmpPositions);</span>
<span class="nc" id="L2737"> functionNumber[i]++;</span>
<span class="nc" id="L2738"> } catch (IOException e) {</span>
<span class="nc" id="L2739"> log.debug(e);</span>
<span class="nc" id="L2740"> function.dataCollector.error(key,</span>
<span class="nc" id="L2741"> e.getMessage());</span>
<span class="nc" id="L2742"> }</span>
<span class="nc" id="L2743"> } else if (function.dataType</span>
<span class="nc bnc" id="L2744" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
try {
<span class="nc" id="L2746"> functionValuesDouble[i][functionNumber[i]] = function.parserFunction</span>
<span class="nc" id="L2747"> .getValueDouble(tmpArgs, tmpPositions);</span>
<span class="nc" id="L2748"> functionNumber[i]++;</span>
<span class="nc" id="L2749"> } catch (IOException e) {</span>
<span class="nc" id="L2750"> log.debug(e);</span>
<span class="nc" id="L2751"> function.dataCollector.error(key,</span>
<span class="nc" id="L2752"> e.getMessage());</span>
<span class="nc" id="L2753"> }</span>
}
}
}
}
}
<span class="nc bnc" id="L2759" title="All 2 branches missed."> if (number > 0) {</span>
<span class="nc" id="L2760"> subDataCollector = dataCollector.add(key, values,</span>
number);
<span class="nc bnc" id="L2762" title="All 2 branches missed."> if (cf.baseFunctionList[level] != null</span>
&& cf.baseFunctionList[level]
<span class="nc bnc" id="L2764" title="All 2 branches missed."> .containsKey(dataCollector)) {</span>
<span class="nc bnc" id="L2765" title="All 2 branches missed."> for (int i = 0; i < functionList.length; i++) {</span>
<span class="nc" id="L2766"> SubComponentFunction function = functionList[i];</span>
<span class="nc" id="L2767"> if (function.dataType</span>
<span class="nc bnc" id="L2768" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L2769"> function.dataCollector.add(key,</span>
functionValuesLong[i], functionNumber[i]);
<span class="nc" id="L2771"> } else if (function.dataType</span>
<span class="nc bnc" id="L2772" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L2773"> function.dataCollector.add(key,</span>
functionValuesDouble[i], functionNumber[i]);
}
}
}
<span class="nc bnc" id="L2778" title="All 2 branches missed."> if (subDataCollector != null) {</span>
<span class="nc" id="L2779"> createFacetBase(cf, (level + 1), subDataCollector,</span>
positionsData, spansNumberData, facetData, Arrays
<span class="nc" id="L2781"> .copyOfRange(restrictedSubDocSet, 0, number));</span>
}
}
}
}
<span class="nc" id="L2786"> }</span>
}
<span class="nc" id="L2788"> } else {</span>
<span class="nc" id="L2789"> throw new IOException(</span>
"unexpected dataType " + cf.baseDataTypes[level]);
}
}
<span class="nc" id="L2793"> }</span>
} else {
<span class="nc" id="L2795"> throw new IOException(</span>
<span class="nc" id="L2796"> "unexpected type " + dataCollector.getCollectorType());</span>
}
<span class="nc" id="L2798"> dataCollector.closeNewList();</span>
<span class="nc bnc" id="L2799" title="All 2 branches missed."> if (cf.baseFunctionList[level] != null</span>
<span class="nc bnc" id="L2800" title="All 2 branches missed."> && cf.baseFunctionList[level].containsKey(dataCollector)) {</span>
<span class="nc" id="L2801"> SubComponentFunction[] tmpList = cf.baseFunctionList[level]</span>
<span class="nc" id="L2802"> .get(dataCollector);</span>
<span class="nc bnc" id="L2803" title="All 2 branches missed."> for (SubComponentFunction function : tmpList) {</span>
<span class="nc" id="L2804"> function.dataCollector.closeNewList();</span>
}
}
}
<span class="nc" id="L2809"> }</span>
/**
* Grouped key name.
*
* @param key
* the key
* @param baseRangeSize
* the base range size
* @param baseRangeBase
* the base range base
* @return the string
*/
private static String groupedKeyName(String key, Double baseRangeSize,
Double baseRangeBase) {
<span class="nc" id="L2824"> final double precision = 0.000001;</span>
<span class="nc bnc" id="L2825" title="All 4 branches missed."> if (baseRangeSize == null || baseRangeSize <= 0) {</span>
<span class="nc" id="L2826"> return key;</span>
} else {
Double doubleKey;
Double doubleBase;
Double doubleNumber;
Double doubleStart;
Double doubleEnd;
try {
<span class="nc" id="L2834"> doubleKey = Double.parseDouble(key);</span>
<span class="nc bnc" id="L2835" title="All 2 branches missed."> doubleBase = baseRangeBase != null ? baseRangeBase : 0;</span>
<span class="nc" id="L2836"> doubleNumber = Math.floor((doubleKey - doubleBase) / baseRangeSize);</span>
<span class="nc" id="L2837"> doubleStart = doubleBase + doubleNumber * baseRangeSize;</span>
<span class="nc" id="L2838"> doubleEnd = doubleStart + baseRangeSize;</span>
<span class="nc" id="L2839"> } catch (NumberFormatException e) {</span>
<span class="nc" id="L2840"> return key;</span>
<span class="nc" id="L2841"> }</span>
// integer
<span class="nc bnc" id="L2843" title="All 2 branches missed."> if (Math.abs(baseRangeSize - Math.floor(baseRangeSize)) < precision</span>
<span class="nc bnc" id="L2844" title="All 2 branches missed."> && Math.abs(doubleBase - Math.floor(doubleBase)) < precision) {</span>
try {
<span class="nc bnc" id="L2846" title="All 2 branches missed."> if (baseRangeSize > 1) {</span>
<span class="nc" id="L2847"> return String.format("%.0f", doubleStart) + "-"</span>
<span class="nc" id="L2848"> + String.format("%.0f", doubleEnd - 1);</span>
} else {
<span class="nc" id="L2850"> return String.format("%.0f", doubleStart);</span>
}
<span class="nc" id="L2852"> } catch (NumberFormatException e) {</span>
<span class="nc" id="L2853"> return key;</span>
}
} else {
<span class="nc" id="L2856"> return "[" + doubleStart + "," + doubleEnd + ")";</span>
}
}
}
/**
* Merge doc lists.
*
* @param a
* the a
* @param b
* the b
* @return the integer[]
*/
private static Integer[] mergeDocLists(Integer[] a, Integer[] b) {
<span class="nc" id="L2871"> Integer[] answer = new Integer[a.length + b.length];</span>
<span class="nc" id="L2872"> int i = 0;</span>
<span class="nc" id="L2873"> int j = 0;</span>
<span class="nc" id="L2874"> int k = 0;</span>
Integer tmp;
<span class="nc bnc" id="L2876" title="All 4 branches missed."> while (i < a.length && j < b.length) {</span>
<span class="nc bnc" id="L2877" title="All 2 branches missed."> tmp = a[i] < b[j] ? a[i++] : b[j++];</span>
<span class="nc bnc" id="L2878" title="All 4 branches missed."> for (; i < a.length && a[i].equals(tmp); i++)</span>
;
<span class="nc bnc" id="L2880" title="All 4 branches missed."> for (; j < b.length && b[j].equals(tmp); j++)</span>
;
<span class="nc" id="L2882"> answer[k++] = tmp;</span>
}
<span class="nc bnc" id="L2884" title="All 2 branches missed."> while (i < a.length) {</span>
<span class="nc" id="L2885"> tmp = a[i++];</span>
<span class="nc bnc" id="L2886" title="All 4 branches missed."> for (; i < a.length && a[i].equals(tmp); i++)</span>
;
<span class="nc" id="L2888"> answer[k++] = tmp;</span>
}
<span class="nc bnc" id="L2890" title="All 2 branches missed."> while (j < b.length) {</span>
<span class="nc" id="L2891"> tmp = b[j++];</span>
<span class="nc bnc" id="L2892" title="All 4 branches missed."> for (; j < b.length && b[j].equals(tmp); j++)</span>
;
<span class="nc" id="L2894"> answer[k++] = tmp;</span>
}
<span class="nc" id="L2896"> return Arrays.copyOf(answer, k);</span>
}
/**
* Creates the facet.
*
* @param facetList
* the facet list
* @param positionsData
* the positions data
* @param spansNumberData
* the spans number data
* @param facetData
* the facet data
* @param docSet
* the doc set
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createFacet(List<ComponentFacet> facetList,
Map<Integer, Integer> positionsData,
Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData,
Map<String, SortedMap<String, int[]>> facetData, List<Integer> docSet)
throws IOException {
<span class="nc bnc" id="L2921" title="All 2 branches missed."> if (facetList != null) {</span>
<span class="nc bnc" id="L2922" title="All 2 branches missed."> for (ComponentFacet cf : facetList) {</span>
<span class="nc bnc" id="L2923" title="All 2 branches missed."> if (cf.baseFields.length > 0) {</span>
<span class="nc" id="L2924"> createFacetBase(cf, 0, cf.dataCollector, positionsData,</span>
spansNumberData, facetData,
<span class="nc" id="L2926"> docSet.toArray(new Integer[docSet.size()]));</span>
}
<span class="nc" id="L2928"> }</span>
}
<span class="nc" id="L2930"> }</span>
/**
* Creates the termvector full.
*
* @param termVectorList
* the term vector list
* @param positionsData
* the positions data
* @param docSet
* the doc set
* @param t
* the t
* @param r
* the r
* @param lrc
* the lrc
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createTermvectorFull(
List<ComponentTermVector> termVectorList,
Map<Integer, Integer> positionsData, List<Integer> docSet, Terms t,
LeafReader r, LeafReaderContext lrc) throws IOException {
<span class="pc bpc" id="L2954" title="1 of 2 branches missed."> if (t != null) {</span>
BytesRef term;
TermsEnum termsEnum;
<span class="fc" id="L2957"> PostingsEnum postingsEnum = null;</span>
<span class="fc" id="L2958"> String segmentName = "segment" + lrc.ord;</span>
<span class="fc" id="L2959"> int segmentNumber = lrc.parent.leaves().size();</span>
// loop over termvectors
<span class="fc bfc" id="L2961" title="All 2 branches covered."> for (ComponentTermVector termVector : termVectorList) {</span>
<span class="fc bfc" id="L2962" title="All 4 branches covered."> if (termVector.full || termVector.list != null) {</span>
<span class="fc bfc" id="L2963" title="All 2 branches covered."> if (termVector.full) {</span>
<span class="fc" id="L2964"> termVector.subComponentFunction.dataCollector.setWithTotal();</span>
}
List<CompiledAutomaton> listAutomata;
Map<String, Automaton> automatonMap;
<span class="fc bfc" id="L2968" title="All 2 branches covered."> if (termVector.list == null) {</span>
<span class="fc" id="L2969"> listAutomata = new ArrayList<>();</span>
CompiledAutomaton compiledAutomaton;
Automaton automaton;
<span class="pc bpc" id="L2972" title="1 of 4 branches missed."> if ((termVector.regexp == null) || (termVector.regexp.isEmpty())) {</span>
<span class="fc" id="L2973"> RegExp re = new RegExp(</span>
termVector.prefix + MtasToken.DELIMITER + ".*");
<span class="fc" id="L2975"> automaton = re.toAutomaton();</span>
<span class="fc" id="L2976"> } else {</span>
<span class="fc" id="L2977"> RegExp re = new RegExp(termVector.prefix + MtasToken.DELIMITER</span>
+ termVector.regexp + "\u0000*");
<span class="fc" id="L2979"> automaton = re.toAutomaton();</span>
}
<span class="fc" id="L2981"> compiledAutomaton = new CompiledAutomaton(automaton);</span>
<span class="fc" id="L2982"> listAutomata.add(compiledAutomaton);</span>
<span class="fc" id="L2983"> } else {</span>
<span class="fc bfc" id="L2984" title="All 2 branches covered."> automatonMap = MtasToken.createAutomatonMap(termVector.prefix,</span>
new ArrayList<String>(termVector.list),
<span class="fc" id="L2986"> termVector.listRegexp ? false : true);</span>
<span class="fc" id="L2987"> listAutomata = MtasToken.createAutomata(termVector.prefix,</span>
termVector.regexp, automatonMap);
}
<span class="fc" id="L2990"> List<ByteRunAutomaton> ignoreByteRunAutomatonList = null;</span>
<span class="fc bfc" id="L2991" title="All 2 branches covered."> if ((termVector.ignoreRegexp != null)</span>
<span class="pc bpc" id="L2992" title="1 of 2 branches missed."> && (!termVector.ignoreRegexp.isEmpty())) {</span>
<span class="fc" id="L2993"> ignoreByteRunAutomatonList = new ArrayList<>();</span>
<span class="fc" id="L2994"> RegExp re = new RegExp(termVector.prefix + MtasToken.DELIMITER</span>
+ termVector.ignoreRegexp + "\u0000*");
<span class="fc" id="L2996"> ignoreByteRunAutomatonList</span>
<span class="fc" id="L2997"> .add(new ByteRunAutomaton(re.toAutomaton()));</span>
}
<span class="fc bfc" id="L2999" title="All 2 branches covered."> if (termVector.ignoreList != null) {</span>
<span class="pc bpc" id="L3000" title="1 of 2 branches missed."> if (ignoreByteRunAutomatonList == null) {</span>
<span class="nc" id="L3001"> ignoreByteRunAutomatonList = new ArrayList<>();</span>
}
<span class="pc bpc" id="L3003" title="1 of 2 branches missed."> Map<String, Automaton> list = MtasToken.createAutomatonMap(</span>
termVector.prefix, new ArrayList<String>(termVector.ignoreList),
<span class="fc" id="L3005"> termVector.ignoreListRegexp ? false : true);</span>
<span class="fc bfc" id="L3006" title="All 2 branches covered."> for (Automaton automaton : list.values()) {</span>
<span class="fc" id="L3007"> ignoreByteRunAutomatonList.add(new ByteRunAutomaton(automaton));</span>
<span class="fc" id="L3008"> }</span>
}
<span class="fc bfc" id="L3011" title="All 2 branches covered."> for (CompiledAutomaton compiledAutomaton : listAutomata) {</span>
<span class="fc" id="L3012"> if (!compiledAutomaton.type</span>
<span class="fc bfc" id="L3013" title="All 2 branches covered."> .equals(CompiledAutomaton.AUTOMATON_TYPE.NORMAL)) {</span>
<span class="fc" id="L3014"> if (compiledAutomaton.type</span>
<span class="pc bpc" id="L3015" title="1 of 2 branches missed."> .equals(CompiledAutomaton.AUTOMATON_TYPE.NONE)) {</span>
// do nothing
} else {
<span class="nc" id="L3018"> throw new IOException(</span>
"compiledAutomaton is " + compiledAutomaton.type);
}
} else {
<span class="fc" id="L3022"> termsEnum = t.intersect(compiledAutomaton, null);</span>
<span class="fc" id="L3023"> int initSize = Math.min((int) t.size(), 1000);</span>
<span class="fc" id="L3024"> termVector.subComponentFunction.dataCollector.initNewList(</span>
initSize, segmentName, segmentNumber, termVector.boundary);
<span class="fc" id="L3026"> boolean doBasic = termVector.subComponentFunction.dataCollector</span>
<span class="fc" id="L3027"> .getStatsType().equals(CodecUtil.STATS_BASIC);</span>
<span class="pc bpc" id="L3028" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3029" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3030"> function.dataCollector.initNewList(initSize);</span>
<span class="nc bnc" id="L3031" title="All 4 branches missed."> doBasic = doBasic ? (function.parserFunction.sumRule()</span>
<span class="nc bnc" id="L3032" title="All 2 branches missed."> && !function.parserFunction.needPositions()</span>
<span class="nc" id="L3033"> && function.dataCollector.getStatsType()</span>
<span class="nc bnc" id="L3034" title="All 2 branches missed."> .equals(CodecUtil.STATS_BASIC))</span>
: doBasic;
<span class="nc" id="L3036"> }</span>
}
// only if documents
<span class="pc bpc" id="L3039" title="1 of 2 branches missed."> if (!docSet.isEmpty()) {</span>
int termDocId;
boolean acceptedTerm;
String key;
// loop over terms
<span class="fc bfc" id="L3044" title="All 2 branches covered."> while ((term = termsEnum.next()) != null) {</span>
<span class="pc bpc" id="L3045" title="1 of 2 branches missed."> if (validateTermWithStartValue(term, termVector)) {</span>
<span class="fc" id="L3046"> termDocId = -1;</span>
<span class="fc" id="L3047"> acceptedTerm = true;</span>
<span class="fc bfc" id="L3048" title="All 2 branches covered."> if (ignoreByteRunAutomatonList != null) {</span>
<span class="fc bfc" id="L3049" title="All 2 branches covered."> for (ByteRunAutomaton ignoreByteRunAutomaton : ignoreByteRunAutomatonList) {</span>
<span class="fc bfc" id="L3050" title="All 2 branches covered."> if (ignoreByteRunAutomaton.run(term.bytes, term.offset,</span>
term.length)) {
<span class="fc" id="L3052"> acceptedTerm = false;</span>
<span class="fc" id="L3053"> break;</span>
}
<span class="fc" id="L3055"> }</span>
}
<span class="fc bfc" id="L3057" title="All 2 branches covered."> if (acceptedTerm) {</span>
<span class="fc bfc" id="L3058" title="All 2 branches covered."> if (doBasic) {</span>
// compute numbers;
<span class="fc" id="L3060"> TermvectorNumberBasic numberBasic = computeTermvectorNumberBasic(</span>
docSet, termDocId, termsEnum, r, lrc, postingsEnum);
// register
<span class="fc bfc" id="L3063" title="All 2 branches covered."> if (numberBasic.docNumber > 0) {</span>
<span class="fc" id="L3064"> long valueLong = 0;</span>
<span class="fc" id="L3065"> key = MtasToken.getPostfixFromValue(term);</span>
try {
<span class="fc" id="L3067"> valueLong = termVector.subComponentFunction.parserFunction</span>
<span class="fc" id="L3068"> .getValueLong(numberBasic.valueSum, 1);</span>
<span class="nc" id="L3069"> } catch (IOException e) {</span>
<span class="nc" id="L3070"> log.debug(e);</span>
<span class="nc" id="L3071"> termVector.subComponentFunction.dataCollector.error(</span>
<span class="nc" id="L3072"> MtasToken.getPostfixFromValue(term),</span>
<span class="nc" id="L3073"> e.getMessage());</span>
<span class="fc" id="L3074"> }</span>
<span class="fc" id="L3075"> termVector.subComponentFunction.dataCollector.add(key,</span>
valueLong, numberBasic.docNumber);
<span class="pc bpc" id="L3077" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3078" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3079"> if (function.dataType</span>
<span class="nc bnc" id="L3080" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L3081"> long valueFunction = function.parserFunction</span>
<span class="nc" id="L3082"> .getValueLong(numberBasic.valueSum, 0);</span>
<span class="nc" id="L3083"> function.dataCollector.add(key, valueFunction,</span>
numberBasic.docNumber);
<span class="nc" id="L3085"> } else if (function.dataType</span>
<span class="nc bnc" id="L3086" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L3087"> double valueFunction = function.parserFunction</span>
<span class="nc" id="L3088"> .getValueDouble(numberBasic.valueSum, 0);</span>
<span class="nc" id="L3089"> function.dataCollector.add(key, valueFunction,</span>
numberBasic.docNumber);
}
<span class="nc" id="L3092"> }</span>
}
}
<span class="fc" id="L3095"> } else {</span>
<span class="fc" id="L3096"> TermvectorNumberFull numberFull = computeTermvectorNumberFull(</span>
docSet, termDocId, termsEnum, lrc, postingsEnum,
positionsData);
<span class="pc bpc" id="L3099" title="1 of 2 branches missed."> if (numberFull.docNumber > 0) {</span>
<span class="fc" id="L3100"> long[] valuesLong = new long[numberFull.docNumber];</span>
<span class="fc" id="L3101"> key = MtasToken.getPostfixFromValue(term);</span>
<span class="fc bfc" id="L3102" title="All 2 branches covered."> for (int i = 0; i < numberFull.docNumber; i++) {</span>
try {
<span class="fc" id="L3104"> valuesLong[i] = termVector.subComponentFunction.parserFunction</span>
<span class="fc" id="L3105"> .getValueLong(</span>
new long[] { numberFull.args[i] },
numberFull.positions[i]);
<span class="nc" id="L3108"> } catch (IOException e) {</span>
<span class="nc" id="L3109"> log.debug(e);</span>
<span class="nc" id="L3110"> termVector.subComponentFunction.dataCollector</span>
<span class="nc" id="L3111"> .error(key, e.getMessage());</span>
<span class="fc" id="L3112"> }</span>
}
<span class="fc" id="L3114"> termVector.subComponentFunction.dataCollector.add(key,</span>
valuesLong, valuesLong.length);
<span class="pc bpc" id="L3116" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3117" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3118"> if (function.dataType</span>
<span class="nc bnc" id="L3119" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L3120"> valuesLong = new long[numberFull.docNumber];</span>
<span class="nc bnc" id="L3121" title="All 2 branches missed."> for (int i = 0; i < numberFull.docNumber; i++) {</span>
try {
<span class="nc" id="L3123"> valuesLong[i] = function.parserFunction</span>
<span class="nc" id="L3124"> .getValueLong(</span>
new long[] { numberFull.args[i] },
numberFull.positions[i]);
<span class="nc" id="L3127"> } catch (IOException e) {</span>
<span class="nc" id="L3128"> log.debug(e);</span>
<span class="nc" id="L3129"> function.dataCollector.error(key,</span>
<span class="nc" id="L3130"> e.getMessage());</span>
<span class="nc" id="L3131"> }</span>
}
<span class="nc" id="L3133"> function.dataCollector.add(key, valuesLong,</span>
valuesLong.length);
<span class="nc" id="L3135"> } else if (function.dataType</span>
<span class="nc bnc" id="L3136" title="All 2 branches missed."> .equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L3137"> double[] valuesDouble = new double[numberFull.docNumber];</span>
<span class="nc bnc" id="L3138" title="All 2 branches missed."> for (int i = 0; i < numberFull.docNumber; i++) {</span>
try {
<span class="nc" id="L3140"> valuesDouble[i] = function.parserFunction</span>
<span class="nc" id="L3141"> .getValueDouble(</span>
new long[] { numberFull.args[i] },
numberFull.positions[i]);
<span class="nc" id="L3144"> } catch (IOException e) {</span>
<span class="nc" id="L3145"> log.debug(e);</span>
<span class="nc" id="L3146"> function.dataCollector.error(key,</span>
<span class="nc" id="L3147"> e.getMessage());</span>
<span class="nc" id="L3148"> }</span>
}
<span class="nc" id="L3150"> function.dataCollector.add(key, valuesDouble,</span>
valuesDouble.length);
}
<span class="nc" id="L3153"> }</span>
}
}
<span class="fc" id="L3157"> }</span>
}
}
}
}
<span class="fc" id="L3162"> termVector.subComponentFunction.dataCollector.closeNewList();</span>
<span class="pc bpc" id="L3163" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3164" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3165"> function.dataCollector.closeNewList();</span>
<span class="nc" id="L3166"> }</span>
}
}
<span class="fc" id="L3169"> }</span>
}
<span class="fc" id="L3171"> }</span>
}
<span class="fc" id="L3173"> }</span>
/**
* Creates the termvector first round.
*
* @param termVectorList
* the term vector list
* @param positionsData
* the positions data
* @param docSet
* the doc set
* @param t
* the t
* @param r
* the r
* @param lrc
* the lrc
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createTermvectorFirstRound(
List<ComponentTermVector> termVectorList,
Map<Integer, Integer> positionsData, List<Integer> docSet, Terms t,
LeafReader r, LeafReaderContext lrc) throws IOException {
<span class="pc bpc" id="L3197" title="1 of 2 branches missed."> if (t != null) {</span>
BytesRef term;
TermsEnum termsEnum;
<span class="fc" id="L3200"> PostingsEnum postingsEnum = null;</span>
<span class="fc" id="L3201"> String segmentName = "segment" + lrc.ord;</span>
<span class="fc" id="L3202"> String[] mutableKey = new String[1];</span>
<span class="fc" id="L3203"> int segmentNumber = lrc.parent.leaves().size();</span>
// loop over termvectors
<span class="fc bfc" id="L3205" title="All 2 branches covered."> for (ComponentTermVector termVector : termVectorList) {</span>
CompiledAutomaton compiledAutomaton;
<span class="pc bpc" id="L3207" title="1 of 4 branches missed."> if ((termVector.regexp == null) || (termVector.regexp.isEmpty())) {</span>
<span class="fc" id="L3208"> RegExp re = new RegExp(</span>
termVector.prefix + MtasToken.DELIMITER + ".*");
<span class="fc" id="L3210"> compiledAutomaton = new CompiledAutomaton(re.toAutomaton());</span>
<span class="fc" id="L3211"> } else {</span>
<span class="fc" id="L3212"> RegExp re = new RegExp(termVector.prefix + MtasToken.DELIMITER</span>
+ termVector.regexp + "\u0000*");
<span class="fc" id="L3214"> compiledAutomaton = new CompiledAutomaton(re.toAutomaton());</span>
}
<span class="fc" id="L3216"> List<ByteRunAutomaton> ignoreByteRunAutomatonList = null;</span>
<span class="fc bfc" id="L3217" title="All 2 branches covered."> if ((termVector.ignoreRegexp != null)</span>
<span class="pc bpc" id="L3218" title="1 of 2 branches missed."> && (!termVector.ignoreRegexp.isEmpty())) {</span>
<span class="fc" id="L3219"> ignoreByteRunAutomatonList = new ArrayList<>();</span>
<span class="fc" id="L3220"> RegExp re = new RegExp(termVector.prefix + MtasToken.DELIMITER</span>
+ termVector.ignoreRegexp + "\u0000*");
<span class="fc" id="L3222"> ignoreByteRunAutomatonList</span>
<span class="fc" id="L3223"> .add(new ByteRunAutomaton(re.toAutomaton()));</span>
}
<span class="fc bfc" id="L3225" title="All 2 branches covered."> if (termVector.ignoreList != null) {</span>
<span class="pc bpc" id="L3226" title="1 of 2 branches missed."> if (ignoreByteRunAutomatonList == null) {</span>
<span class="nc" id="L3227"> ignoreByteRunAutomatonList = new ArrayList<>();</span>
}
<span class="pc bpc" id="L3229" title="1 of 2 branches missed."> Map<String, Automaton> list = MtasToken.createAutomatonMap(</span>
termVector.prefix, new ArrayList<String>(termVector.ignoreList),
<span class="fc" id="L3231"> termVector.ignoreListRegexp ? false : true);</span>
<span class="fc bfc" id="L3232" title="All 2 branches covered."> for (Automaton automaton : list.values()) {</span>
<span class="fc" id="L3233"> ignoreByteRunAutomatonList.add(new ByteRunAutomaton(automaton));</span>
<span class="fc" id="L3234"> }</span>
}
<span class="fc bfc" id="L3236" title="All 4 branches covered."> if (!termVector.full && termVector.list == null) {</span>
<span class="fc" id="L3237"> termsEnum = t.intersect(compiledAutomaton, null);</span>
<span class="fc" id="L3238"> int initSize = Math.min((int) t.size(), 1000);</span>
<span class="fc" id="L3239"> termVector.subComponentFunction.dataCollector.initNewList(initSize,</span>
segmentName, segmentNumber, termVector.boundary);
<span class="pc bpc" id="L3241" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3242" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3243"> function.dataCollector.initNewList(initSize);</span>
<span class="nc" id="L3244"> }</span>
}
// only if documents
<span class="pc bpc" id="L3247" title="1 of 2 branches missed."> if (!docSet.isEmpty()) {</span>
int termDocId;
<span class="fc" id="L3249"> int termNumberMaximum = termVector.number;</span>
<span class="fc" id="L3250"> HashMap<BytesRef, RegisterStatus> computeFullList = new HashMap<>();</span>
RegisterStatus registerStatus;
// basic, don't need full values
<span class="fc" id="L3253"> if (termVector.subComponentFunction.sortType</span>
<span class="fc bfc" id="L3254" title="All 2 branches covered."> .equals(CodecUtil.SORT_TERM)</span>
|| termVector.subComponentFunction.sortType
<span class="pc bpc" id="L3256" title="1 of 2 branches missed."> .equals(CodecUtil.STATS_TYPE_SUM)</span>
|| termVector.subComponentFunction.sortType
<span class="nc bnc" id="L3258" title="All 2 branches missed."> .equals(CodecUtil.STATS_TYPE_N)) {</span>
<span class="fc" id="L3259"> int termCounter = 0;</span>
boolean continueAfterPreliminaryCheck;
<span class="fc" id="L3262"> boolean preliminaryCheck = false;</span>
<span class="pc bpc" id="L3263" title="1 of 4 branches missed."> if (r.getLiveDocs() == null && (docSet.size() != r.numDocs())) {</span>
<span class="nc" id="L3264"> preliminaryCheck = true;</span>
}
// loop over terms
boolean acceptedTerm;
<span class="fc bfc" id="L3268" title="All 2 branches covered."> while ((term = termsEnum.next()) != null) {</span>
<span class="pc bpc" id="L3269" title="1 of 2 branches missed."> if (validateTermWithStartValue(term, termVector)) {</span>
<span class="fc" id="L3270"> termDocId = -1;</span>
<span class="fc" id="L3271"> acceptedTerm = true;</span>
<span class="fc bfc" id="L3272" title="All 2 branches covered."> if (ignoreByteRunAutomatonList != null) {</span>
<span class="fc bfc" id="L3273" title="All 2 branches covered."> for (ByteRunAutomaton ignoreByteRunAutomaton : ignoreByteRunAutomatonList) {</span>
<span class="pc bpc" id="L3274" title="1 of 2 branches missed."> if (ignoreByteRunAutomaton.run(term.bytes, term.offset,</span>
term.length)) {
<span class="nc" id="L3276"> acceptedTerm = false;</span>
<span class="nc" id="L3277"> break;</span>
}
<span class="fc" id="L3279"> }</span>
}
<span class="pc bpc" id="L3281" title="1 of 2 branches missed."> if (acceptedTerm) {</span>
<span class="fc" id="L3282"> continueAfterPreliminaryCheck = true;</span>
<span class="fc" id="L3283"> mutableKey[0] = null;</span>
<span class="pc bpc" id="L3284" title="1 of 2 branches missed."> if (preliminaryCheck) {</span>
try {
<span class="nc" id="L3286"> TermvectorNumberBasic preliminaryNumberBasic = computeTermvectorNumberBasic(</span>
termsEnum, r);
<span class="nc bnc" id="L3288" title="All 2 branches missed."> if (preliminaryNumberBasic.docNumber > 0) {</span>
<span class="nc" id="L3289"> continueAfterPreliminaryCheck = preliminaryRegisterValue(</span>
term, termVector, preliminaryNumberBasic,
<span class="nc" id="L3291"> termNumberMaximum, segmentNumber, mutableKey);</span>
} else {
<span class="nc" id="L3293"> continueAfterPreliminaryCheck = false;</span>
}
<span class="nc" id="L3295"> } catch (IOException e) {</span>
<span class="nc" id="L3296"> log.debug(e);</span>
<span class="nc" id="L3297"> continueAfterPreliminaryCheck = true;</span>
<span class="nc" id="L3298"> }</span>
}
<span class="pc bpc" id="L3300" title="1 of 2 branches missed."> if (continueAfterPreliminaryCheck) {</span>
// compute numbers;
<span class="fc" id="L3302"> TermvectorNumberBasic numberBasic = computeTermvectorNumberBasic(</span>
docSet, termDocId, termsEnum, r, lrc, postingsEnum);
// register
<span class="fc bfc" id="L3305" title="All 2 branches covered."> if (numberBasic.docNumber > 0) {</span>
<span class="fc" id="L3306"> termCounter++;</span>
<span class="fc" id="L3307"> registerStatus = registerValue(term, termVector,</span>
<span class="fc" id="L3308"> numberBasic, termNumberMaximum, segmentNumber,</span>
false, mutableKey);
<span class="fc bfc" id="L3310" title="All 2 branches covered."> if (registerStatus != null) {</span>
<span class="fc" id="L3311"> computeFullList.put(BytesRef.deepCopyOf(term),</span>
registerStatus);
}
}
}
// stop after termCounterMaximum
<span class="fc" id="L3317"> if (termVector.subComponentFunction.sortType</span>
<span class="fc bfc" id="L3318" title="All 2 branches covered."> .equals(CodecUtil.SORT_TERM)</span>
&& termVector.subComponentFunction.sortDirection
<span class="fc bfc" id="L3320" title="All 4 branches covered."> .equals(CodecUtil.SORT_ASC)</span>
&& termCounter >= termNumberMaximum) {
<span class="fc" id="L3322"> break;</span>
}
}
}
}
// rerun for full
<span class="fc bfc" id="L3328" title="All 2 branches covered."> if (computeFullList.size() > 0) {</span>
<span class="fc" id="L3329"> termsEnum = t.intersect(compiledAutomaton, null);</span>
<span class="fc bfc" id="L3330" title="All 2 branches covered."> while ((term = termsEnum.next()) != null) {</span>
<span class="pc bpc" id="L3331" title="1 of 2 branches missed."> if (validateTermWithStartValue(term, termVector)) {</span>
<span class="fc" id="L3332"> termDocId = -1;</span>
<span class="fc" id="L3333"> mutableKey[0] = null;</span>
// only if (probably) needed
<span class="fc bfc" id="L3335" title="All 2 branches covered."> if (computeFullList.containsKey(term)) {</span>
<span class="fc" id="L3336"> registerStatus = computeFullList.get(term);</span>
boolean doAdd;
<span class="fc" id="L3338"> doAdd = termVector.subComponentFunction.sortType</span>
<span class="fc" id="L3339"> .equals(CodecUtil.SORT_TERM);</span>
<span class="fc" id="L3340"> doAdd |= termVector.subComponentFunction.sortDirection</span>
<span class="fc" id="L3341"> .equals(CodecUtil.SORT_ASC);</span>
<span class="pc bpc" id="L3342" title="1 of 2 branches missed."> doAdd |= termVector.list != null;</span>
<span class="fc" id="L3343"> doAdd |= termVector.boundaryRegistration;</span>
<span class="fc" id="L3344"> doAdd |= registerStatus.force;</span>
<span class="fc" id="L3345"> doAdd |= termVector.subComponentFunction.dataCollector</span>
<span class="fc" id="L3346"> .validateSegmentBoundary(registerStatus.sortValue);</span>
<span class="fc bfc" id="L3347" title="All 2 branches covered."> if (doAdd) {</span>
<span class="fc" id="L3348"> TermvectorNumberFull numberFull = computeTermvectorNumberFull(</span>
docSet, termDocId, termsEnum, lrc, postingsEnum,
positionsData);
<span class="pc bpc" id="L3351" title="1 of 2 branches missed."> if (numberFull.docNumber > 0) {</span>
<span class="fc" id="L3352"> termCounter++;</span>
<span class="fc" id="L3353"> registerValue(term, termVector, numberFull,</span>
mutableKey);
}
}
<span class="fc" id="L3357"> }</span>
}
}
<span class="fc" id="L3360"> computeFullList.clear();</span>
}
<span class="fc" id="L3362"> } else {</span>
<span class="nc" id="L3363"> throw new IOException(</span>
"sort '" + termVector.subComponentFunction.sortType + " "
+ termVector.subComponentFunction.sortDirection
+ "' not supported");
}
// finish if segments are used
<span class="fc" id="L3369"> termVector.subComponentFunction.dataCollector</span>
<span class="fc" id="L3370"> .closeSegmentKeyValueRegistration();</span>
<span class="pc bpc" id="L3371" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3372" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3373"> function.dataCollector.closeSegmentKeyValueRegistration();</span>
<span class="nc" id="L3374"> }</span>
}
}
<span class="fc" id="L3377"> termVector.subComponentFunction.dataCollector.closeNewList();</span>
<span class="pc bpc" id="L3378" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3379" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3380"> function.dataCollector.closeNewList();</span>
<span class="nc" id="L3381"> }</span>
}
}
<span class="fc" id="L3384"> }</span>
}
<span class="fc" id="L3386"> }</span>
/**
* Creates the termvector second round.
*
* @param termVectorList
* the term vector list
* @param positionsData
* the positions data
* @param docSet
* the doc set
* @param t
* the t
* @param r
* the r
* @param lrc
* the lrc
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void createTermvectorSecondRound(
List<ComponentTermVector> termVectorList,
Map<Integer, Integer> positionsData, List<Integer> docSet, Terms t,
LeafReader r, LeafReaderContext lrc) throws IOException {
<span class="pc bpc" id="L3410" title="1 of 2 branches missed."> if (t != null) {</span>
BytesRef term;
TermsEnum termsEnum;
<span class="fc" id="L3413"> PostingsEnum postingsEnum = null;</span>
<span class="fc" id="L3414"> String segmentName = "segment" + lrc.ord;</span>
<span class="fc" id="L3415"> int segmentNumber = lrc.parent.leaves().size();</span>
<span class="fc" id="L3416"> String[] mutableKey = new String[1];</span>
<span class="fc bfc" id="L3417" title="All 2 branches covered."> for (ComponentTermVector termVector : termVectorList) {</span>
<span class="pc bpc" id="L3418" title="2 of 6 branches missed."> if (!termVector.full && termVector.list == null</span>
&& (termVector.subComponentFunction.dataCollector.segmentRecomputeKeyList != null
&& termVector.subComponentFunction.dataCollector.segmentRecomputeKeyList
<span class="fc bfc" id="L3421" title="All 2 branches covered."> .containsKey(segmentName))) {</span>
<span class="fc" id="L3422"> Set<String> recomputeKeyList = termVector.subComponentFunction.dataCollector.segmentRecomputeKeyList</span>
<span class="fc" id="L3423"> .get(segmentName);</span>
<span class="pc bpc" id="L3424" title="1 of 2 branches missed."> if (!recomputeKeyList.isEmpty()) {</span>
<span class="fc" id="L3425"> Map<String, Automaton> automatonMap = MtasToken.createAutomatonMap(</span>
termVector.prefix, new ArrayList<String>(recomputeKeyList),
<span class="fc" id="L3427"> true);</span>
<span class="fc" id="L3428"> List<CompiledAutomaton> listCompiledAutomata = MtasToken</span>
<span class="fc" id="L3429"> .createAutomata(termVector.prefix, termVector.regexp,</span>
automatonMap);
<span class="fc bfc" id="L3431" title="All 2 branches covered."> for (CompiledAutomaton compiledAutomaton : listCompiledAutomata) {</span>
<span class="fc" id="L3432"> termsEnum = t.intersect(compiledAutomaton, null);</span>
<span class="fc" id="L3433"> termVector.subComponentFunction.dataCollector</span>
<span class="fc" id="L3434"> .initNewList(</span>
termVector.subComponentFunction.dataCollector.segmentKeys
<span class="fc" id="L3436"> .size(),</span>
segmentName, segmentNumber, termVector.boundary);
<span class="fc" id="L3438"> RegisterStatus registerStatus = null;</span>
<span class="pc bpc" id="L3439" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3440" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3441"> function.dataCollector.initNewList((int) t.size(),</span>
segmentName, segmentNumber, null);
<span class="nc" id="L3443"> }</span>
}
<span class="pc bpc" id="L3445" title="1 of 2 branches missed."> if (!docSet.isEmpty()) {</span>
int termDocId;
<span class="fc bfc" id="L3447" title="All 2 branches covered."> while ((term = termsEnum.next()) != null) {</span>
<span class="pc bpc" id="L3448" title="1 of 2 branches missed."> if (validateTermWithStartValue(term, termVector)) {</span>
<span class="fc" id="L3449"> termDocId = -1;</span>
<span class="fc" id="L3450"> mutableKey[0] = null;</span>
// compute numbers;
<span class="fc" id="L3452"> TermvectorNumberBasic numberBasic = computeTermvectorNumberBasic(</span>
docSet, termDocId, termsEnum, r, lrc, postingsEnum);
<span class="fc bfc" id="L3454" title="All 2 branches covered."> if (numberBasic.docNumber > 0) {</span>
<span class="fc" id="L3455"> registerStatus = registerValue(term, termVector,</span>
<span class="fc" id="L3456"> numberBasic, 0, segmentNumber, true, mutableKey);</span>
<span class="fc bfc" id="L3457" title="All 2 branches covered."> if (registerStatus != null) {</span>
<span class="fc" id="L3458"> TermvectorNumberFull numberFull = computeTermvectorNumberFull(</span>
docSet, termDocId, termsEnum, lrc, postingsEnum,
positionsData);
<span class="pc bpc" id="L3461" title="1 of 2 branches missed."> if (numberFull.docNumber > 0) {</span>
<span class="fc" id="L3462"> registerValue(term, termVector, numberFull,</span>
mutableKey);
}
}
}
<span class="fc" id="L3467"> }</span>
}
}
<span class="fc" id="L3470"> termVector.subComponentFunction.dataCollector.closeNewList();</span>
<span class="pc bpc" id="L3471" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3472" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc" id="L3473"> function.dataCollector.closeNewList();</span>
<span class="nc" id="L3474"> }</span>
}
<span class="fc" id="L3476"> }</span>
}
}
<span class="fc" id="L3479"> }</span>
}
<span class="fc" id="L3481"> }</span>
/**
* Validate term with start value.
*
* @param term
* the term
* @param termVector
* the term vector
* @return true, if successful
*/
private static boolean validateTermWithStartValue(BytesRef term,
ComponentTermVector termVector) {
<span class="pc bpc" id="L3494" title="1 of 2 branches missed."> if (termVector.startValue == null) {</span>
<span class="fc" id="L3495"> return true;</span>
<span class="nc" id="L3496"> } else if (termVector.subComponentFunction.sortType</span>
<span class="nc bnc" id="L3497" title="All 2 branches missed."> .equals(CodecUtil.SORT_TERM)) {</span>
<span class="nc bnc" id="L3498" title="All 2 branches missed."> if (term.length > termVector.startValue.length) {</span>
<span class="nc" id="L3499"> byte[] zeroBytes = (new BytesRef("\u0000")).bytes;</span>
<span class="nc" id="L3500"> int n = (int) (Math</span>
<span class="nc" id="L3501"> .ceil(((double) (term.length - termVector.startValue.length))</span>
/ zeroBytes.length));
<span class="nc" id="L3503"> byte[] newBytes = new byte[termVector.startValue.length</span>
+ n * zeroBytes.length];
<span class="nc" id="L3505"> System.arraycopy(termVector.startValue.bytes, 0, newBytes, 0,</span>
termVector.startValue.length);
<span class="nc bnc" id="L3507" title="All 2 branches missed."> for (int i = 0; i < n; i++) {</span>
<span class="nc" id="L3508"> System.arraycopy(zeroBytes, 0, newBytes,</span>
termVector.startValue.length + i * zeroBytes.length,
zeroBytes.length);
}
<span class="nc" id="L3512"> termVector.startValue = new BytesRef(newBytes);</span>
}
<span class="nc bnc" id="L3514" title="All 2 branches missed."> if ((termVector.subComponentFunction.sortDirection.equals(</span>
<span class="nc bnc" id="L3515" title="All 2 branches missed."> CodecUtil.SORT_ASC) && (termVector.startValue.compareTo(term) < 0))</span>
|| (termVector.subComponentFunction.sortDirection
<span class="nc bnc" id="L3517" title="All 2 branches missed."> .equals(CodecUtil.SORT_DESC)</span>
<span class="nc bnc" id="L3518" title="All 2 branches missed."> && (termVector.startValue.compareTo(term) > 0))) {</span>
<span class="nc" id="L3519"> return true;</span>
}
}
<span class="nc" id="L3522"> return false;</span>
}
/**
* Need second round termvector.
*
* @param termVectorList
* the term vector list
* @return true, if successful
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static boolean needSecondRoundTermvector(
List<ComponentTermVector> termVectorList) throws IOException {
<span class="fc" id="L3536"> boolean needSecondRound = false;</span>
<span class="fc bfc" id="L3537" title="All 2 branches covered."> for (ComponentTermVector termVector : termVectorList) {</span>
<span class="fc bfc" id="L3538" title="All 4 branches covered."> if (!termVector.full && termVector.list == null) {</span>
boolean doCheck;
<span class="fc bfc" id="L3540" title="All 2 branches covered."> doCheck = termVector.subComponentFunction.dataCollector.segmentRegistration != null</span>
&& (termVector.subComponentFunction.dataCollector.segmentRegistration
<span class="fc bfc" id="L3542" title="All 2 branches covered."> .equals(MtasDataCollector.SEGMENT_SORT_ASC)</span>
|| termVector.subComponentFunction.dataCollector.segmentRegistration
<span class="pc bpc" id="L3544" title="2 of 4 branches missed."> .equals(MtasDataCollector.SEGMENT_SORT_DESC))</span>
&& termVector.number > 0;
<span class="fc bfc" id="L3546" title="All 2 branches covered."> doCheck |= termVector.subComponentFunction.dataCollector.segmentRegistration != null</span>
&& (termVector.subComponentFunction.dataCollector.segmentRegistration
<span class="pc bpc" id="L3548" title="1 of 2 branches missed."> .equals(MtasDataCollector.SEGMENT_BOUNDARY_ASC)</span>
|| termVector.subComponentFunction.dataCollector.segmentRegistration
<span class="pc bpc" id="L3550" title="3 of 4 branches missed."> .equals(MtasDataCollector.SEGMENT_BOUNDARY_DESC))</span>
&& termVector.number > 0;
<span class="fc bfc" id="L3552" title="All 2 branches covered."> if (doCheck) {</span>
<span class="fc" id="L3553"> termVector.subComponentFunction.dataCollector.recomputeSegmentKeys();</span>
<span class="fc" id="L3554"> if (!termVector.subComponentFunction.dataCollector</span>
<span class="fc bfc" id="L3555" title="All 2 branches covered."> .checkExistenceNecessaryKeys()) {</span>
<span class="fc" id="L3556"> needSecondRound = true;</span>
}
<span class="fc" id="L3558"> termVector.subComponentFunction.dataCollector.reduceToSegmentKeys();</span>
}
}
<span class="fc" id="L3561"> }</span>
<span class="fc" id="L3562"> return needSecondRound;</span>
}
/**
* The Class TermvectorNumberBasic.
*/
private static class TermvectorNumberBasic {
/** The value sum. */
public long[] valueSum;
/** The doc number. */
public int docNumber;
/**
* Instantiates a new termvector number basic.
*/
<span class="fc" id="L3579"> TermvectorNumberBasic() {</span>
<span class="fc" id="L3580"> valueSum = new long[] { 0 };</span>
<span class="fc" id="L3581"> docNumber = 0;</span>
<span class="fc" id="L3582"> }</span>
}
/**
* The Class TermvectorNumberFull.
*/
private static class TermvectorNumberFull {
/** The args. */
public long[] args;
/** The positions. */
public int[] positions;
/** The doc number. */
public int docNumber;
/**
* Instantiates a new termvector number full.
*
* @param maxSize
* the max size
*/
<span class="fc" id="L3605"> TermvectorNumberFull(int maxSize) {</span>
<span class="fc" id="L3606"> args = new long[maxSize];</span>
<span class="fc" id="L3607"> positions = new int[maxSize];</span>
<span class="fc" id="L3608"> docNumber = 0;</span>
<span class="fc" id="L3609"> }</span>
}
/**
* The Class RegisterStatus.
*/
private static class RegisterStatus {
/** The sort value. */
public long sortValue;
/** The force. */
public boolean force;
/**
* Instantiates a new register status.
*
* @param sortValue
* the sort value
* @param force
* the force
*/
<span class="fc" id="L3631"> RegisterStatus(long sortValue, boolean force) {</span>
<span class="fc" id="L3632"> this.sortValue = sortValue;</span>
<span class="fc" id="L3633"> this.force = force;</span>
<span class="fc" id="L3634"> }</span>
}
/**
* Register value.
*
* @param term
* the term
* @param termVector
* the term vector
* @param number
* the number
* @param termNumberMaximum
* the term number maximum
* @param segmentNumber
* the segment number
* @param forceAccept
* the force accept
* @param mutableKey
* the mutable key
* @return the register status
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@SuppressWarnings("unchecked")
private static RegisterStatus registerValue(BytesRef term,
ComponentTermVector termVector, TermvectorNumberBasic number,
Integer termNumberMaximum, Integer segmentNumber, boolean forceAccept,
String[] mutableKey) throws IOException {
<span class="fc" id="L3663"> long value = termVector.subComponentFunction.parserFunction</span>
<span class="fc" id="L3664"> .getValueLong(number.valueSum, 0);</span>
<span class="fc" id="L3665"> long sortValue = 0;</span>
<span class="fc" id="L3666"> if (termVector.subComponentFunction.sortType</span>
<span class="fc bfc" id="L3667" title="All 2 branches covered."> .equals(CodecUtil.STATS_TYPE_SUM)) {</span>
<span class="fc" id="L3668"> sortValue = value;</span>
<span class="fc" id="L3669"> } else if (termVector.subComponentFunction.sortType</span>
<span class="pc bpc" id="L3670" title="1 of 2 branches missed."> .equals(CodecUtil.STATS_TYPE_N)) {</span>
<span class="nc" id="L3671"> sortValue = number.docNumber;</span>
}
<span class="fc" id="L3673"> boolean addItem = false;</span>
<span class="fc" id="L3674"> boolean addItemForced = false;</span>
<span class="fc" id="L3675"> MtasDataCollector<Long, ?> dataCollector = (MtasDataCollector<Long, ?>) termVector.subComponentFunction.dataCollector;</span>
// sort on term
<span class="fc bfc" id="L3677" title="All 2 branches covered."> if (termVector.subComponentFunction.sortType.equals(CodecUtil.SORT_TERM)) {</span>
<span class="fc" id="L3678"> addItem = true;</span>
<span class="fc" id="L3679"> addItemForced = true;</span>
// sort on sum or n
<span class="fc" id="L3681"> } else if (termVector.subComponentFunction.sortType</span>
<span class="pc bpc" id="L3682" title="1 of 2 branches missed."> .equals(CodecUtil.STATS_TYPE_SUM)</span>
|| termVector.subComponentFunction.sortType
<span class="nc bnc" id="L3684" title="All 2 branches missed."> .equals(CodecUtil.STATS_TYPE_N)) {</span>
// always accept
<span class="fc bfc" id="L3686" title="All 2 branches covered."> if (forceAccept) {</span>
<span class="fc" id="L3687"> addItem = true;</span>
<span class="fc" id="L3688"> addItemForced = addItem;</span>
// check boundary
<span class="pc bpc" id="L3690" title="1 of 2 branches missed."> } else if (termVector.boundaryRegistration) {</span>
<span class="nc" id="L3691"> addItem = dataCollector.validateSegmentBoundary(sortValue);</span>
<span class="nc bnc" id="L3692" title="All 2 branches missed."> if (addItem) {</span>
<span class="nc bnc" id="L3693" title="All 2 branches missed."> if (mutableKey[0] == null) {</span>
<span class="nc" id="L3694"> mutableKey[0] = MtasToken.getPostfixFromValue(term);</span>
}
<span class="nc" id="L3696"> String segmentStatus = dataCollector.validateSegmentValue(</span>
<span class="nc" id="L3697"> mutableKey[0], sortValue, termNumberMaximum, segmentNumber,</span>
false);
<span class="nc bnc" id="L3699" title="All 2 branches missed."> if (segmentStatus != null) {</span>
<span class="nc bnc" id="L3700" title="All 2 branches missed."> if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY)) {</span>
<span class="nc" id="L3701"> addItemForced = true;</span>
}
} else {
// shouldn't happen
}
<span class="nc" id="L3706"> }</span>
// no boundary
} else {
<span class="fc" id="L3709"> String segmentStatus = dataCollector.validateSegmentValue(sortValue,</span>
<span class="fc" id="L3710"> termNumberMaximum, segmentNumber);</span>
<span class="fc bfc" id="L3711" title="All 2 branches covered."> if (segmentStatus != null) {</span>
boolean possibleAddItem;
<span class="fc bfc" id="L3713" title="All 2 branches covered."> if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY_OR_NEW)) {</span>
<span class="fc" id="L3714"> possibleAddItem = true;</span>
<span class="fc" id="L3715"> } else if (segmentStatus</span>
<span class="pc bpc" id="L3716" title="1 of 2 branches missed."> .equals(MtasDataCollector.SEGMENT_POSSIBLE_KEY)) {</span>
<span class="fc" id="L3717"> mutableKey[0] = MtasToken.getPostfixFromValue(term);</span>
<span class="fc" id="L3718"> segmentStatus = dataCollector.validateSegmentValue(mutableKey[0],</span>
<span class="fc" id="L3719"> sortValue, termNumberMaximum, segmentNumber, true);</span>
<span class="fc bfc" id="L3720" title="All 2 branches covered."> if (segmentStatus != null) {</span>
<span class="fc" id="L3721"> possibleAddItem = true;</span>
} else {
<span class="fc" id="L3723"> possibleAddItem = false;</span>
}
} else {
// should never happen?
<span class="nc" id="L3727"> possibleAddItem = false;</span>
}
// further checks, passed initial
<span class="fc bfc" id="L3730" title="All 2 branches covered."> if (possibleAddItem) {</span>
<span class="fc bfc" id="L3731" title="All 2 branches covered."> if (mutableKey[0] == null) {</span>
<span class="fc" id="L3732"> mutableKey[0] = MtasToken.getPostfixFromValue(term);</span>
}
<span class="fc" id="L3734"> segmentStatus = dataCollector.validateSegmentValue(mutableKey[0],</span>
<span class="fc" id="L3735"> sortValue, termNumberMaximum, segmentNumber, false);</span>
<span class="pc bpc" id="L3736" title="1 of 2 branches missed."> if (segmentStatus != null) {</span>
<span class="fc" id="L3737"> addItem = true;</span>
<span class="fc bfc" id="L3738" title="All 2 branches covered."> if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY)) {</span>
<span class="fc" id="L3739"> addItemForced = true;</span>
}
}
}
<span class="fc" id="L3743"> } else {</span>
<span class="fc" id="L3744"> addItem = false;</span>
}
<span class="fc" id="L3746"> }</span>
// don't sort?
} else {
<span class="nc" id="L3749"> addItem = false;</span>
}
<span class="fc bfc" id="L3751" title="All 2 branches covered."> if (addItem) {</span>
<span class="fc" id="L3752"> boolean computeFull = false;</span>
<span class="fc bfc" id="L3753" title="All 2 branches covered."> if (mutableKey[0] == null) {</span>
<span class="fc" id="L3754"> mutableKey[0] = MtasToken.getPostfixFromValue(term);</span>
}
// check dataCollector type
<span class="fc" id="L3757"> if (termVector.subComponentFunction.statsType</span>
<span class="fc bfc" id="L3758" title="All 2 branches covered."> .equals(CodecUtil.STATS_BASIC)) {</span>
<span class="fc" id="L3759"> dataCollector.add(mutableKey[0], value, number.docNumber);</span>
} else {
<span class="fc" id="L3761"> computeFull = true;</span>
}
// functions
<span class="pc bpc" id="L3764" title="1 of 2 branches missed."> if (termVector.functions != null) {</span>
<span class="pc bpc" id="L3765" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc bnc" id="L3766" title="All 2 branches missed."> if (function.parserFunction.sumRule()</span>
<span class="nc bnc" id="L3767" title="All 2 branches missed."> && !function.parserFunction.needPositions()</span>
<span class="nc bnc" id="L3768" title="All 2 branches missed."> && function.statsType.equals(CodecUtil.STATS_BASIC)) {</span>
<span class="nc bnc" id="L3769" title="All 2 branches missed."> if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L3770"> long valueFunction = function.parserFunction</span>
<span class="nc" id="L3771"> .getValueLong(number.valueSum, 0);</span>
<span class="nc" id="L3772"> function.dataCollector.add(mutableKey[0], valueFunction,</span>
number.docNumber);
<span class="nc bnc" id="L3774" title="All 2 branches missed."> } else if (function.dataType.equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L3775"> double valueFunction = function.parserFunction</span>
<span class="nc" id="L3776"> .getValueDouble(number.valueSum, 0);</span>
<span class="nc" id="L3777"> function.dataCollector.add(mutableKey[0], valueFunction,</span>
number.docNumber);
<span class="nc" id="L3779"> }</span>
} else {
<span class="nc" id="L3781"> computeFull = true;</span>
}
<span class="nc" id="L3783"> }</span>
}
// add as full?
<span class="fc bfc" id="L3786" title="All 2 branches covered."> return computeFull ? new RegisterStatus(sortValue, addItemForced) : null;</span>
} else {
<span class="fc" id="L3788"> return null;</span>
}
}
/**
* Preliminary register value.
*
* @param term
* the term
* @param termVector
* the term vector
* @param number
* the number
* @param termNumberMaximum
* the term number maximum
* @param segmentNumber
* the segment number
* @param mutableKey
* the mutable key
* @return true, if successful
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static boolean preliminaryRegisterValue(BytesRef term,
ComponentTermVector termVector, TermvectorNumberBasic number,
Integer termNumberMaximum, Integer segmentNumber, String[] mutableKey)
throws IOException {
<span class="nc" id="L3815"> long sortValue = 0;</span>
<span class="nc" id="L3816"> if (termVector.subComponentFunction.sortDirection</span>
<span class="nc bnc" id="L3817" title="All 2 branches missed."> .equals(CodecUtil.SORT_DESC)</span>
&& termVector.subComponentFunction.sortType
<span class="nc bnc" id="L3819" title="All 2 branches missed."> .equals(CodecUtil.STATS_TYPE_SUM)) {</span>
<span class="nc" id="L3820"> sortValue = termVector.subComponentFunction.parserFunction</span>
<span class="nc" id="L3821"> .getValueLong(number.valueSum, 0);</span>
<span class="nc" id="L3822"> } else if (termVector.subComponentFunction.sortDirection</span>
<span class="nc bnc" id="L3823" title="All 2 branches missed."> .equals(CodecUtil.SORT_DESC)</span>
&& termVector.subComponentFunction.sortType
<span class="nc bnc" id="L3825" title="All 2 branches missed."> .equals(CodecUtil.STATS_TYPE_N)) {</span>
<span class="nc" id="L3826"> sortValue = number.docNumber;</span>
} else {
<span class="nc" id="L3828"> return true;</span>
}
<span class="nc" id="L3830"> MtasDataCollector<Long, ?> dataCollector = (MtasDataCollector<Long, ?>) termVector.subComponentFunction.dataCollector;</span>
<span class="nc bnc" id="L3831" title="All 2 branches missed."> if (termVector.boundaryRegistration) {</span>
<span class="nc" id="L3832"> return dataCollector.validateSegmentBoundary(sortValue);</span>
} else {
<span class="nc" id="L3834"> String segmentStatus = dataCollector.validateSegmentValue(sortValue,</span>
<span class="nc" id="L3835"> termNumberMaximum, segmentNumber);</span>
<span class="nc bnc" id="L3836" title="All 2 branches missed."> if (segmentStatus != null) {</span>
<span class="nc bnc" id="L3837" title="All 2 branches missed."> if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY_OR_NEW)) {</span>
<span class="nc" id="L3838"> return true;</span>
<span class="nc" id="L3839"> } else if (segmentStatus</span>
<span class="nc bnc" id="L3840" title="All 2 branches missed."> .equals(MtasDataCollector.SEGMENT_POSSIBLE_KEY)) {</span>
<span class="nc" id="L3841"> mutableKey[0] = MtasToken.getPostfixFromValue(term);</span>
<span class="nc" id="L3842"> segmentStatus = dataCollector.validateSegmentValue(mutableKey[0],</span>
<span class="nc" id="L3843"> sortValue, termNumberMaximum, segmentNumber, true);</span>
<span class="nc bnc" id="L3844" title="All 2 branches missed."> return segmentStatus != null;</span>
} else {
// should never happen?
<span class="nc" id="L3847"> return false;</span>
}
} else {
<span class="nc" id="L3850"> return false;</span>
}
}
}
/**
* Register value.
*
* @param term
* the term
* @param termVector
* the term vector
* @param number
* the number
* @param mutableKey
* the mutable key
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@SuppressWarnings("unchecked")
private static void registerValue(BytesRef term,
ComponentTermVector termVector, TermvectorNumberFull number,
String[] mutableKey) throws IOException {
<span class="pc bpc" id="L3873" title="1 of 2 branches missed."> if (number.docNumber > 0) {</span>
<span class="fc bfc" id="L3874" title="All 2 branches covered."> if (mutableKey[0] == null) {</span>
<span class="fc" id="L3875"> mutableKey[0] = MtasToken.getPostfixFromValue(term);</span>
}
<span class="fc" id="L3877"> MtasDataCollector<Long, ?> dataCollector = (MtasDataCollector<Long, ?>) termVector.subComponentFunction.dataCollector;</span>
<span class="fc" id="L3878"> long[] valuesLong = new long[number.docNumber];</span>
<span class="fc bfc" id="L3879" title="All 2 branches covered."> for (int i = 0; i < number.docNumber; i++) {</span>
try {
<span class="fc" id="L3881"> valuesLong[i] = termVector.subComponentFunction.parserFunction</span>
<span class="fc" id="L3882"> .getValueLong(new long[] { number.args[i] }, number.positions[i]);</span>
<span class="nc" id="L3883"> } catch (IOException e) {</span>
<span class="nc" id="L3884"> log.debug(e);</span>
<span class="nc" id="L3885"> dataCollector.error(mutableKey[0], e.getMessage());</span>
<span class="fc" id="L3886"> }</span>
}
<span class="fc" id="L3888"> if (!termVector.subComponentFunction.statsType</span>
<span class="pc bpc" id="L3889" title="1 of 2 branches missed."> .equals(CodecUtil.STATS_BASIC)) {</span>
<span class="fc" id="L3890"> dataCollector.add(mutableKey[0], valuesLong, valuesLong.length);</span>
}
<span class="pc bpc" id="L3892" title="1 of 2 branches missed."> for (SubComponentFunction function : termVector.functions) {</span>
<span class="nc bnc" id="L3893" title="All 2 branches missed."> if (!function.parserFunction.sumRule()</span>
<span class="nc bnc" id="L3894" title="All 2 branches missed."> || function.parserFunction.needPositions()</span>
<span class="nc bnc" id="L3895" title="All 2 branches missed."> || !function.statsType.equals(CodecUtil.STATS_BASIC)) {</span>
<span class="nc bnc" id="L3896" title="All 2 branches missed."> if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {</span>
<span class="nc" id="L3897"> valuesLong = new long[number.docNumber];</span>
<span class="nc bnc" id="L3898" title="All 2 branches missed."> for (int i = 0; i < number.docNumber; i++) {</span>
try {
<span class="nc" id="L3900"> valuesLong[i] = function.parserFunction.getValueLong(</span>
new long[] { number.args[i] }, number.positions[i]);
<span class="nc" id="L3902"> } catch (IOException e) {</span>
<span class="nc" id="L3903"> log.debug(e);</span>
<span class="nc" id="L3904"> function.dataCollector.error(mutableKey[0], e.getMessage());</span>
<span class="nc" id="L3905"> }</span>
}
<span class="nc" id="L3907"> function.dataCollector.add(mutableKey[0], valuesLong,</span>
valuesLong.length);
<span class="nc bnc" id="L3909" title="All 2 branches missed."> } else if (function.dataType.equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span>
<span class="nc" id="L3910"> double[] valuesDouble = new double[number.docNumber];</span>
<span class="nc bnc" id="L3911" title="All 2 branches missed."> for (int i = 0; i < number.docNumber; i++) {</span>
try {
<span class="nc" id="L3913"> valuesDouble[i] = function.parserFunction.getValueDouble(</span>
new long[] { number.args[i] }, number.positions[i]);
<span class="nc" id="L3915"> } catch (IOException e) {</span>
<span class="nc" id="L3916"> log.debug(e);</span>
<span class="nc" id="L3917"> function.dataCollector.error(mutableKey[0], e.getMessage());</span>
<span class="nc" id="L3918"> }</span>
}
<span class="nc" id="L3920"> function.dataCollector.add(mutableKey[0], valuesDouble,</span>
valuesDouble.length);
}
}
<span class="nc" id="L3924"> }</span>
}
<span class="fc" id="L3926"> }</span>
/**
* Compute termvector number basic.
*
* @param termsEnum
* the terms enum
* @param r
* the r
* @return the termvector number basic
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static TermvectorNumberBasic computeTermvectorNumberBasic(
TermsEnum termsEnum, LeafReader r) throws IOException {
<span class="fc" id="L3941"> TermvectorNumberBasic result = new TermvectorNumberBasic();</span>
<span class="pc bpc" id="L3942" title="1 of 2 branches missed."> boolean hasDeletedDocuments = (r.getLiveDocs() != null);</span>
<span class="pc bpc" id="L3943" title="1 of 2 branches missed."> if (!hasDeletedDocuments) {</span>
<span class="fc" id="L3944"> result.valueSum[0] = termsEnum.totalTermFreq();</span>
<span class="fc" id="L3945"> result.docNumber = termsEnum.docFreq();</span>
<span class="pc bpc" id="L3946" title="1 of 2 branches missed."> if (result.valueSum[0] > -1) {</span>
<span class="fc" id="L3947"> return result;</span>
}
}
<span class="nc" id="L3950"> throw new IOException("should not call this");</span>
}
/**
* Compute termvector number basic.
*
* @param docSet
* the doc set
* @param termDocId
* the term doc id
* @param termsEnum
* the terms enum
* @param r
* the r
* @param lrc
* the lrc
* @param postingsEnum
* the postings enum
* @return the termvector number basic
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static TermvectorNumberBasic computeTermvectorNumberBasic(
List<Integer> docSet, int termDocId, TermsEnum termsEnum, LeafReader r,
LeafReaderContext lrc, PostingsEnum postingsEnum) throws IOException {
<span class="fc" id="L3975"> TermvectorNumberBasic result = new TermvectorNumberBasic();</span>
<span class="fc bfc" id="L3976" title="All 2 branches covered."> boolean hasDeletedDocuments = (r.getLiveDocs() != null);</span>
<span class="pc bpc" id="L3977" title="1 of 4 branches missed."> if ((docSet.size() == r.numDocs()) && !hasDeletedDocuments) {</span>
try {
<span class="fc" id="L3979"> return computeTermvectorNumberBasic(termsEnum, r);</span>
<span class="nc" id="L3980"> } catch (IOException e) {</span>
<span class="nc" id="L3981"> log.debug("problem", e);</span>
// problem
}
}
<span class="fc" id="L3985"> result.docNumber = 0;</span>
<span class="fc" id="L3986"> result.valueSum[0] = 0;</span>
<span class="fc" id="L3987"> int localTermDocId = termDocId;</span>
<span class="fc" id="L3988"> Iterator<Integer> docIterator = docSet.iterator();</span>
<span class="fc" id="L3989"> postingsEnum = termsEnum.postings(postingsEnum, PostingsEnum.FREQS);</span>
int docId;
<span class="fc bfc" id="L3991" title="All 2 branches covered."> while (docIterator.hasNext()) {</span>
<span class="fc" id="L3992"> docId = docIterator.next() - lrc.docBase;</span>
<span class="pc bpc" id="L3993" title="2 of 4 branches missed."> if (docId >= localTermDocId && ((docId == localTermDocId)</span>
<span class="fc bfc" id="L3994" title="All 2 branches covered."> || ((localTermDocId = postingsEnum.advance(docId)) == docId))) {</span>
<span class="fc" id="L3995"> result.docNumber++;</span>
<span class="fc" id="L3996"> result.valueSum[0] += postingsEnum.freq();</span>
}
<span class="pc bpc" id="L3998" title="1 of 2 branches missed."> if (localTermDocId == DocIdSetIterator.NO_MORE_DOCS) {</span>
<span class="nc" id="L3999"> break;</span>
}
}
<span class="fc" id="L4002"> return result;</span>
}
/**
* Compute termvector number full.
*
* @param docSet
* the doc set
* @param termDocId
* the term doc id
* @param termsEnum
* the terms enum
* @param lrc
* the lrc
* @param postingsEnum
* the postings enum
* @param positionsData
* the positions data
* @return the termvector number full
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static TermvectorNumberFull computeTermvectorNumberFull(
List<Integer> docSet, int termDocId, TermsEnum termsEnum,
LeafReaderContext lrc, PostingsEnum postingsEnum,
Map<Integer, Integer> positionsData) throws IOException {
<span class="fc" id="L4028"> TermvectorNumberFull result = new TermvectorNumberFull(docSet.size());</span>
<span class="fc" id="L4029"> Iterator<Integer> docIterator = docSet.iterator();</span>
<span class="fc" id="L4030"> int localTermDocId = termDocId;</span>
<span class="fc" id="L4031"> postingsEnum = termsEnum.postings(postingsEnum, PostingsEnum.FREQS);</span>
<span class="fc bfc" id="L4032" title="All 2 branches covered."> while (docIterator.hasNext()) {</span>
<span class="fc" id="L4033"> int docId = docIterator.next() - lrc.docBase;</span>
<span class="fc bfc" id="L4034" title="All 4 branches covered."> if (docId >= localTermDocId && ((docId == localTermDocId)</span>
<span class="fc bfc" id="L4035" title="All 2 branches covered."> || ((localTermDocId = postingsEnum.advance(docId)) == docId))) {</span>
<span class="fc" id="L4036"> result.args[result.docNumber] = postingsEnum.freq();</span>
<span class="pc bpc" id="L4037" title="1 of 2 branches missed."> result.positions[result.docNumber] = (positionsData == null) ? 0</span>
<span class="pc" id="L4038"> : positionsData.get(docId + lrc.docBase);</span>
<span class="fc" id="L4039"> result.docNumber++;</span>
}
<span class="fc" id="L4041"> }</span>
<span class="fc" id="L4042"> return result;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>