CodecInfo.java.html
38.9 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
<?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>CodecInfo.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">CodecInfo.java</span></div><h1>CodecInfo.java</h1><pre class="source lang-java linenums">package mtas.codec.util;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import mtas.analysis.token.MtasToken;
import mtas.analysis.token.MtasTokenString;
import mtas.codec.MtasCodecPostingsFormat;
import mtas.codec.tree.IntervalRBTree;
import mtas.codec.tree.IntervalTreeNodeData;
import mtas.codec.util.CodecSearchTree.MtasTreeHit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.index.Terms;
import org.apache.lucene.store.IndexInput;
/**
* The Class CodecInfo.
*/
public class CodecInfo {
/** The log. */
<span class="fc" id="L32"> private static Log log = LogFactory.getLog(CodecInfo.class);</span>
/** The index input list. */
HashMap<String, IndexInput> indexInputList;
/** The index input offset list. */
HashMap<String, Long> indexInputOffsetList;
/** The version. */
int version;
/** The field references. */
private HashMap<String, FieldReferences> fieldReferences;
/** The prefix references. */
private HashMap<String, LinkedHashMap<String, Long>> prefixReferences;
/**
* Instantiates a new codec info.
*
* @param indexInputList
* the index input list
* @param indexInputOffsetList
* the index input offset list
* @param version
* the version
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public CodecInfo(HashMap<String, IndexInput> indexInputList,
HashMap<String, Long> indexInputOffsetList, int version)
<span class="fc" id="L63"> throws IOException {</span>
<span class="fc" id="L64"> this.indexInputList = indexInputList;</span>
<span class="fc" id="L65"> this.indexInputOffsetList = indexInputOffsetList;</span>
<span class="fc" id="L66"> this.version = version;</span>
<span class="fc" id="L67"> init();</span>
<span class="fc" id="L68"> }</span>
/**
* Gets the codec info from terms.
*
* @param t
* the t
* @return the codec info from terms
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@SuppressWarnings("unchecked")
public static CodecInfo getCodecInfoFromTerms(Terms t) throws IOException {
try {
<span class="fc" id="L82"> HashMap<String, IndexInput> indexInputList = null;</span>
<span class="fc" id="L83"> HashMap<String, Long> indexInputOffsetList = null;</span>
<span class="fc" id="L84"> Object version = null;</span>
<span class="fc" id="L85"> Method[] methods = t.getClass().getMethods();</span>
<span class="fc" id="L86"> Object[] emptyArgs = null;</span>
<span class="fc bfc" id="L87" title="All 2 branches covered."> for (Method m : methods) {</span>
<span class="fc bfc" id="L88" title="All 2 branches covered."> if (m.getName().equals("getIndexInputList")) {</span>
<span class="fc" id="L89"> indexInputList = (HashMap<String, IndexInput>) m.invoke(t, emptyArgs);</span>
<span class="fc bfc" id="L90" title="All 2 branches covered."> } else if (m.getName().equals("getIndexInputOffsetList")) {</span>
<span class="fc" id="L91"> indexInputOffsetList = (HashMap<String, Long>) m.invoke(t, emptyArgs);</span>
<span class="fc bfc" id="L92" title="All 2 branches covered."> } else if (m.getName().equals("getVersion")) {</span>
<span class="fc" id="L93"> version = m.invoke(t, emptyArgs);</span>
}
}
<span class="pc bpc" id="L96" title="3 of 6 branches missed."> if (indexInputList == null || indexInputOffsetList == null</span>
|| version == null) {
<span class="nc" id="L98"> throw new IOException("Reader doesn't provide MtasFieldsProducer");</span>
} else {
<span class="fc" id="L100"> return new CodecInfo(indexInputList, indexInputOffsetList,</span>
<span class="fc" id="L101"> (int) version);</span>
}
<span class="nc" id="L103"> } catch (IllegalAccessException | InvocationTargetException e) {</span>
<span class="nc" id="L104"> throw new IOException("Can't get codecInfo", e);</span>
}
}
/**
* Inits the.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void init() throws IOException {
// move to begin
<span class="fc" id="L116"> IndexInput inField = indexInputList.get("field");</span>
<span class="fc" id="L117"> inField.seek(indexInputOffsetList.get("field"));</span>
// store field references in memory
<span class="fc" id="L119"> fieldReferences = new HashMap<String, FieldReferences>();</span>
<span class="fc" id="L120"> boolean doInit = true;</span>
<span class="fc bfc" id="L121" title="All 2 branches covered."> while (doInit) {</span>
try {
<span class="fc" id="L123"> String field = inField.readString();</span>
<span class="fc" id="L124"> long refIndexDoc = inField.readVLong();</span>
<span class="fc" id="L125"> long refIndexDocId = inField.readVLong();</span>
<span class="fc" id="L126"> int numberOfDocs = inField.readVInt();</span>
<span class="fc" id="L127"> inField.readVLong(); // refTerm</span>
<span class="fc" id="L128"> inField.readVInt(); // numberOfTerms</span>
<span class="fc" id="L129"> long refPrefix = inField.readVLong();</span>
<span class="fc" id="L130"> int numberOfPrefixes = inField.readVInt();</span>
<span class="fc" id="L131"> fieldReferences.put(field, new FieldReferences(refIndexDoc,</span>
refIndexDocId, numberOfDocs, refPrefix, numberOfPrefixes));
<span class="fc" id="L133"> } catch (IOException e) {</span>
<span class="fc" id="L134"> log.debug(e);</span>
<span class="fc" id="L135"> doInit = false;</span>
<span class="fc" id="L136"> }</span>
}
// prefixReferences
<span class="fc" id="L139"> prefixReferences = new HashMap<String, LinkedHashMap<String, Long>>();</span>
<span class="fc" id="L140"> }</span>
/**
* Gets the object by id.
*
* @param field
* the field
* @param docId
* the doc id
* @param mtasId
* the mtas id
* @return the object by id
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public MtasToken getObjectById(String field, int docId, int mtasId)
throws IOException {
try {
Long ref;
Long objectRefApproxCorrection;
<span class="nc" id="L160"> IndexDoc doc = getDoc(field, docId);</span>
<span class="nc" id="L161"> IndexInput inObjectId = indexInputList.get("indexObjectId");</span>
<span class="nc" id="L162"> IndexInput inObject = indexInputList.get("object");</span>
<span class="nc" id="L163"> IndexInput inTerm = indexInputList.get("term");</span>
<span class="nc bnc" id="L164" title="All 2 branches missed."> if (doc.storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_BYTE) {</span>
<span class="nc" id="L165"> inObjectId.seek(doc.fpIndexObjectId + (mtasId * 1L));</span>
<span class="nc" id="L166"> objectRefApproxCorrection = Long.valueOf(inObjectId.readByte());</span>
<span class="nc bnc" id="L167" title="All 2 branches missed."> } else if (doc.storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_SHORT) {</span>
<span class="nc" id="L168"> inObjectId.seek(doc.fpIndexObjectId + (mtasId * 2L));</span>
<span class="nc" id="L169"> objectRefApproxCorrection = Long.valueOf(inObjectId.readShort());</span>
<span class="nc bnc" id="L170" title="All 2 branches missed."> } else if (doc.storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_INTEGER) {</span>
<span class="nc" id="L171"> inObjectId.seek(doc.fpIndexObjectId + (mtasId * 4L));</span>
<span class="nc" id="L172"> objectRefApproxCorrection = Long.valueOf(inObjectId.readInt());</span>
} else {
<span class="nc" id="L174"> inObjectId.seek(doc.fpIndexObjectId + (mtasId * 8L));</span>
<span class="nc" id="L175"> objectRefApproxCorrection = Long.valueOf(inObjectId.readLong());</span>
}
<span class="nc" id="L177"> ref = objectRefApproxCorrection + doc.objectRefApproxOffset</span>
+ (mtasId * (long) doc.objectRefApproxQuotient);
<span class="nc" id="L179"> return MtasCodecPostingsFormat.getToken(inObject, inTerm, ref);</span>
<span class="nc" id="L180"> } catch (Exception e) {</span>
<span class="nc" id="L181"> throw new IOException(e);</span>
}
}
/**
* Gets the objects by parent id.
*
* @param field
* the field
* @param docId
* the doc id
* @param position
* the position
* @return the objects by parent id
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public List<MtasTokenString> getObjectsByParentId(String field, int docId,
int position) throws IOException {
<span class="nc" id="L200"> IndexDoc doc = getDoc(field, docId);</span>
<span class="nc" id="L201"> IndexInput inIndexObjectParent = indexInputList.get("indexObjectParent");</span>
<span class="nc" id="L202"> ArrayList<MtasTreeHit<?>> hits = CodecSearchTree.searchMtasTree(position,</span>
inIndexObjectParent, doc.fpIndexObjectParent,
doc.smallestObjectFilepointer);
<span class="nc" id="L205"> return getObjects(hits);</span>
}
/**
* Gets the objects by position.
*
* @param field
* the field
* @param docId
* the doc id
* @param position
* the position
* @return the objects by position
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public ArrayList<MtasTokenString> getObjectsByPosition(String field,
int docId, int position) throws IOException {
<span class="nc" id="L223"> IndexDoc doc = getDoc(field, docId);</span>
<span class="nc" id="L224"> IndexInput inIndexObjectPosition = indexInputList</span>
<span class="nc" id="L225"> .get("indexObjectPosition");</span>
<span class="nc" id="L226"> ArrayList<MtasTreeHit<?>> hits = CodecSearchTree.searchMtasTree(position,</span>
inIndexObjectPosition, doc.fpIndexObjectPosition,
doc.smallestObjectFilepointer);
<span class="nc" id="L229"> return getObjects(hits);</span>
}
public ArrayList<MtasTokenString> getObjectsByPositions(String field,
int docId, int startPosition, int endPosition) throws IOException {
<span class="nc" id="L234"> IndexDoc doc = getDoc(field, docId);</span>
<span class="nc" id="L235"> IndexInput inIndexObjectPosition = indexInputList</span>
<span class="nc" id="L236"> .get("indexObjectPosition");</span>
<span class="nc" id="L237"> ArrayList<MtasTreeHit<?>> hits = CodecSearchTree.searchMtasTree(</span>
startPosition, endPosition, inIndexObjectPosition,
doc.fpIndexObjectPosition, doc.smallestObjectFilepointer);
<span class="nc" id="L240"> return getObjects(hits);</span>
}
/**
* Gets the prefix filtered objects by positions.
*
* @param field
* the field
* @param docId
* the doc id
* @param prefixes
* the prefixes
* @param startPosition
* the start position
* @param endPosition
* the end position
* @return the prefix filtered objects by positions
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public List<MtasTokenString> getPrefixFilteredObjectsByPositions(String field,
int docId, List<String> prefixes, int startPosition, int endPosition)
throws IOException {
<span class="nc" id="L263"> IndexDoc doc = getDoc(field, docId);</span>
<span class="nc" id="L264"> IndexInput inIndexObjectPosition = indexInputList</span>
<span class="nc" id="L265"> .get("indexObjectPosition");</span>
<span class="nc bnc" id="L266" title="All 2 branches missed."> if (doc != null) {</span>
<span class="nc" id="L267"> ArrayList<MtasTreeHit<?>> hits = CodecSearchTree.searchMtasTree(</span>
startPosition, endPosition, inIndexObjectPosition,
doc.fpIndexObjectPosition, doc.smallestObjectFilepointer);
<span class="nc" id="L270"> return getPrefixFilteredObjects(hits, prefixes);</span>
} else {
<span class="nc" id="L272"> return new ArrayList<>();</span>
}
}
/**
* Gets the prefix filtered objects.
*
* @param hits
* the hits
* @param prefixes
* the prefixes
* @return the prefix filtered objects
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private List<MtasTokenString> getPrefixFilteredObjects(
List<MtasTreeHit<?>> hits, List<String> prefixes) throws IOException {
<span class="nc" id="L289"> ArrayList<MtasTokenString> tokens = new ArrayList<>();</span>
<span class="nc" id="L290"> IndexInput inObject = indexInputList.get("object");</span>
<span class="nc" id="L291"> IndexInput inTerm = indexInputList.get("term");</span>
<span class="nc bnc" id="L292" title="All 2 branches missed."> for (MtasTreeHit<?> hit : hits) {</span>
<span class="nc" id="L293"> MtasTokenString token = MtasCodecPostingsFormat.getToken(inObject, inTerm,</span>
<span class="nc" id="L294"> hit.ref);</span>
<span class="nc bnc" id="L295" title="All 2 branches missed."> if (token != null) {</span>
<span class="nc bnc" id="L296" title="All 4 branches missed."> if (prefixes != null && !prefixes.isEmpty()) {</span>
<span class="nc bnc" id="L297" title="All 2 branches missed."> if (prefixes.contains(token.getPrefix())) {</span>
<span class="nc" id="L298"> tokens.add(token);</span>
}
} else {
<span class="nc" id="L301"> tokens.add(token);</span>
}
}
<span class="nc" id="L304"> }</span>
<span class="nc" id="L305"> return tokens;</span>
}
/**
* Gets the positioned terms by prefixes and position.
*
* @param field
* the field
* @param docId
* the doc id
* @param prefixes
* the prefixes
* @param position
* the position
* @return the positioned terms by prefixes and position
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public List<MtasTreeHit<String>> getPositionedTermsByPrefixesAndPosition(
String field, int docId, List<String> prefixes, int position)
throws IOException {
<span class="nc" id="L326"> return getPositionedTermsByPrefixesAndPositionRange(field, docId, prefixes,</span>
position, position);
}
/**
* Gets the positioned terms by prefixes and position range.
*
* @param field
* the field
* @param docId
* the doc id
* @param prefixes
* the prefixes
* @param startPosition
* the start position
* @param endPosition
* the end position
* @return the positioned terms by prefixes and position range
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public List<MtasTreeHit<String>> getPositionedTermsByPrefixesAndPositionRange(
String field, int docId, List<String> prefixes, int startPosition,
int endPosition) throws IOException {
<span class="nc" id="L350"> IndexDoc doc = getDoc(field, docId);</span>
<span class="nc" id="L351"> IndexInput inIndexObjectPosition = indexInputList</span>
<span class="nc" id="L352"> .get("indexObjectPosition");</span>
<span class="nc bnc" id="L353" title="All 2 branches missed."> if (doc != null) {</span>
<span class="nc" id="L354"> ArrayList<MtasTreeHit<?>> hitItems = CodecSearchTree.searchMtasTree(</span>
startPosition, endPosition, inIndexObjectPosition,
doc.fpIndexObjectPosition, doc.smallestObjectFilepointer);
<span class="nc" id="L357"> List<MtasTreeHit<String>> hits = new ArrayList<>();</span>
<span class="nc" id="L358"> Map<String, Integer> prefixIds = getPrefixesIds(field, prefixes);</span>
<span class="nc bnc" id="L359" title="All 4 branches missed."> if (prefixIds != null && prefixIds.size() > 0) {</span>
<span class="nc" id="L360"> ArrayList<MtasTreeHit<?>> filteredHitItems = new ArrayList<MtasTreeHit<?>>();</span>
<span class="nc bnc" id="L362" title="All 2 branches missed."> for (MtasTreeHit<?> hitItem : hitItems) {</span>
<span class="nc bnc" id="L363" title="All 2 branches missed."> if (prefixIds.containsValue(hitItem.additionalId)) {</span>
<span class="nc" id="L364"> filteredHitItems.add(hitItem);</span>
}
<span class="nc" id="L366"> }</span>
<span class="nc bnc" id="L367" title="All 2 branches missed."> if (filteredHitItems.size() > 0) {</span>
<span class="nc" id="L368"> ArrayList<MtasTokenString> objects = getObjects(filteredHitItems);</span>
<span class="nc bnc" id="L369" title="All 2 branches missed."> for (MtasTokenString token : objects) {</span>
<span class="nc" id="L370"> MtasTreeHit<String> hit = new MtasTreeHit<String>(</span>
<span class="nc" id="L371"> token.getPositionStart(), token.getPositionEnd(),</span>
<span class="nc" id="L372"> token.getTokenRef(), 0, 0, token.getValue());</span>
<span class="nc" id="L373"> hits.add(hit);</span>
<span class="nc" id="L374"> }</span>
}
}
<span class="nc" id="L377"> return hits;</span>
} else {
<span class="nc" id="L379"> return new ArrayList<MtasTreeHit<String>>();</span>
}
}
/**
* Collect terms by prefixes for list of hit positions.
*
* @param field
* the field
* @param docId
* the doc id
* @param prefixes
* the prefixes
* @param positionsHits
* the positions hits
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void collectTermsByPrefixesForListOfHitPositions(String field,
int docId, ArrayList<String> prefixes,
ArrayList<IntervalTreeNodeData<String>> positionsHits)
throws IOException {
<span class="fc" id="L401"> IndexDoc doc = getDoc(field, docId);</span>
<span class="fc" id="L402"> IndexInput inIndexObjectPosition = indexInputList</span>
<span class="fc" id="L403"> .get("indexObjectPosition");</span>
<span class="fc" id="L404"> IndexInput inTerm = indexInputList.get("term");</span>
// create tree interval hits
<span class="fc" id="L406"> IntervalRBTree<String> positionTree = new IntervalRBTree<String>(</span>
positionsHits);
// find prefixIds
<span class="fc" id="L410"> Map<String, Integer> prefixIds = getPrefixesIds(field, prefixes);</span>
// search matching tokens
<span class="pc bpc" id="L412" title="1 of 2 branches missed."> if (prefixIds != null) {</span>
<span class="fc" id="L413"> CodecSearchTree.searchMtasTreeWithIntervalTree(prefixIds.values(),</span>
positionTree, inIndexObjectPosition, doc.fpIndexObjectPosition,
doc.smallestObjectFilepointer);
// reverse list
<span class="fc" id="L418"> Map<Integer, String> idPrefixes = new HashMap<>();</span>
<span class="fc bfc" id="L419" title="All 2 branches covered."> for (Entry<String, Integer> entry : prefixIds.entrySet()) {</span>
<span class="fc" id="L420"> idPrefixes.put(entry.getValue(), entry.getKey());</span>
<span class="fc" id="L421"> }</span>
// term administration
<span class="fc" id="L423"> Map<Long, String> refTerms = new HashMap<>();</span>
<span class="fc bfc" id="L425" title="All 2 branches covered."> for (IntervalTreeNodeData<String> positionHit : positionsHits) {</span>
<span class="fc bfc" id="L426" title="All 2 branches covered."> for (MtasTreeHit<String> hit : positionHit.list) {</span>
<span class="pc bpc" id="L427" title="1 of 2 branches missed."> if (hit.idData == null) {</span>
<span class="fc" id="L428"> hit.idData = idPrefixes.get(hit.additionalId);</span>
<span class="fc bfc" id="L429" title="All 2 branches covered."> if (!refTerms.containsKey(hit.additionalRef)) {</span>
<span class="fc" id="L430"> refTerms.put(hit.additionalRef,</span>
<span class="fc" id="L431"> MtasCodecPostingsFormat.getTerm(inTerm, hit.additionalRef));</span>
}
<span class="fc" id="L433"> hit.refData = refTerms.get(hit.additionalRef);</span>
}
<span class="fc" id="L435"> }</span>
<span class="fc" id="L436"> }</span>
}
<span class="fc" id="L438"> }</span>
/**
* Gets the objects.
*
* @param hits
* the hits
* @return the objects
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public ArrayList<MtasTokenString> getObjects(List<MtasTreeHit<?>> hits)
throws IOException {
<span class="nc" id="L451"> ArrayList<MtasTokenString> tokens = new ArrayList<>();</span>
<span class="nc" id="L452"> IndexInput inObject = indexInputList.get("object");</span>
<span class="nc" id="L453"> IndexInput inTerm = indexInputList.get("term");</span>
<span class="nc bnc" id="L454" title="All 2 branches missed."> for (MtasTreeHit<?> hit : hits) {</span>
<span class="nc" id="L455"> MtasTokenString token = MtasCodecPostingsFormat.getToken(inObject, inTerm,</span>
<span class="nc" id="L456"> hit.ref);</span>
<span class="nc bnc" id="L457" title="All 2 branches missed."> if (token != null) {</span>
<span class="nc" id="L458"> tokens.add(token);</span>
}
<span class="nc" id="L460"> }</span>
<span class="nc" id="L461"> return tokens;</span>
}
/**
* Gets the terms.
*
* @param refs
* the refs
* @return the terms
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public ArrayList<MtasTreeHit<String>> getTerms(ArrayList<MtasTreeHit<?>> refs)
throws IOException {
try {
<span class="nc" id="L476"> ArrayList<MtasTreeHit<String>> terms = new ArrayList<MtasTreeHit<String>>();</span>
<span class="nc" id="L477"> IndexInput inTerm = indexInputList.get("term");</span>
<span class="nc bnc" id="L478" title="All 2 branches missed."> for (MtasTreeHit<?> hit : refs) {</span>
<span class="nc" id="L479"> inTerm.seek(hit.ref);</span>
<span class="nc" id="L480"> String term = inTerm.readString();</span>
<span class="nc" id="L481"> MtasTreeHit<String> newHit = new MtasTreeHit<String>(hit.startPosition,</span>
hit.endPosition, hit.ref, hit.additionalId, hit.additionalRef,
term);
<span class="nc" id="L484"> terms.add(newHit);</span>
<span class="nc" id="L485"> }</span>
<span class="nc" id="L486"> return terms;</span>
<span class="nc" id="L487"> } catch (Exception e) {</span>
<span class="nc" id="L488"> throw new IOException(e);</span>
}
}
/**
* Gets the prefixes ids.
*
* @param field
* the field
* @param prefixes
* the prefixes
* @return the prefixes ids
*/
Map<String, Integer> getPrefixesIds(String field, List<String> prefixes) {
<span class="fc" id="L502"> LinkedHashMap<String, Long> refs = getPrefixRefs(field);</span>
<span class="pc bpc" id="L503" title="1 of 2 branches missed."> if (refs != null) {</span>
<span class="fc" id="L504"> List<String> list = new ArrayList<>(refs.keySet());</span>
<span class="fc" id="L505"> Map<String, Integer> result = new HashMap<>();</span>
<span class="fc bfc" id="L506" title="All 2 branches covered."> for (String prefix : prefixes) {</span>
<span class="fc" id="L507"> int id = list.indexOf(prefix);</span>
<span class="pc bpc" id="L508" title="1 of 2 branches missed."> if (id >= 0) {</span>
<span class="fc" id="L509"> result.put(prefix, id + 1);</span>
}
<span class="fc" id="L511"> }</span>
<span class="fc" id="L512"> return result;</span>
} else {
<span class="nc" id="L514"> return null;</span>
}
}
public Set<String> getPrefixes(String field) {
<span class="nc" id="L519"> LinkedHashMap<String, Long> prefixRefs = this.getPrefixRefs(field);</span>
<span class="nc" id="L520"> return prefixRefs.keySet();</span>
}
/**
* Gets the prefixes.
*
* @param field
* the field
* @return the prefixes
*/
private LinkedHashMap<String, Long> getPrefixRefs(String field) {
<span class="pc bpc" id="L531" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L532"> FieldReferences fr = fieldReferences.get(field);</span>
<span class="fc bfc" id="L533" title="All 2 branches covered."> if (!prefixReferences.containsKey(field)) {</span>
<span class="fc" id="L534"> LinkedHashMap<String, Long> refs = new LinkedHashMap<String, Long>();</span>
try {
<span class="fc" id="L536"> IndexInput inPrefix = indexInputList.get("prefix");</span>
<span class="fc" id="L537"> inPrefix.seek(fr.refPrefix);</span>
<span class="fc bfc" id="L538" title="All 2 branches covered."> for (int i = 0; i < fr.numberOfPrefixes; i++) {</span>
<span class="fc" id="L539"> Long ref = inPrefix.getFilePointer();</span>
<span class="fc" id="L540"> String prefix = inPrefix.readString();</span>
<span class="fc" id="L541"> refs.put(prefix, ref);</span>
}
<span class="nc" id="L543"> } catch (Exception e) {</span>
<span class="nc" id="L544"> log.error(e);</span>
<span class="nc" id="L545"> refs.clear();</span>
<span class="fc" id="L546"> }</span>
<span class="fc" id="L547"> prefixReferences.put(field, refs);</span>
<span class="fc" id="L548"> return refs;</span>
} else {
<span class="fc" id="L550"> return prefixReferences.get(field);</span>
}
} else {
<span class="nc" id="L553"> return null;</span>
}
}
/**
* Gets the doc.
*
* @param field
* the field
* @param docId
* the doc id
* @return the doc
*/
public IndexDoc getDoc(String field, int docId) {
<span class="pc bpc" id="L567" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L568"> FieldReferences fr = fieldReferences.get(field);</span>
try {
<span class="fc" id="L570"> IndexInput inIndexDocId = indexInputList.get("indexDocId");</span>
<span class="fc" id="L571"> ArrayList<MtasTreeHit<?>> list = CodecSearchTree.searchMtasTree(docId,</span>
inIndexDocId, fr.refIndexDocId, fr.refIndexDoc);
<span class="pc bpc" id="L573" title="1 of 2 branches missed."> if (list.size() == 1) {</span>
<span class="fc" id="L574"> return new IndexDoc(list.get(0).ref);</span>
}
<span class="nc" id="L576"> } catch (IOException e) {</span>
<span class="nc" id="L577"> log.debug(e);</span>
<span class="nc" id="L578"> return null;</span>
<span class="nc" id="L579"> }</span>
}
<span class="nc" id="L581"> return null;</span>
}
/**
* Gets the next doc.
*
* @param field
* the field
* @param previousDocId
* the previous doc id
* @return the next doc
*/
public IndexDoc getNextDoc(String field, int previousDocId) {
<span class="pc bpc" id="L594" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L595"> FieldReferences fr = fieldReferences.get(field);</span>
try {
<span class="fc bfc" id="L597" title="All 2 branches covered."> if (previousDocId < 0) {</span>
<span class="fc" id="L598"> return new IndexDoc(fr.refIndexDoc);</span>
} else {
<span class="fc" id="L600"> int nextDocId = previousDocId + 1;</span>
<span class="fc" id="L601"> IndexInput inIndexDocId = indexInputList.get("indexDocId");</span>
<span class="fc" id="L602"> ArrayList<MtasTreeHit<?>> list = CodecSearchTree.advanceMtasTree(</span>
nextDocId, inIndexDocId, fr.refIndexDocId, fr.refIndexDoc);
<span class="fc bfc" id="L604" title="All 2 branches covered."> if (list.size() == 1) {</span>
<span class="fc" id="L605"> IndexInput inDoc = indexInputList.get("doc");</span>
<span class="fc" id="L606"> inDoc.seek(list.get(0).ref);</span>
<span class="fc" id="L607"> return new IndexDoc(inDoc.getFilePointer());</span>
}
}
<span class="nc" id="L610"> } catch (IOException e) {</span>
<span class="nc" id="L611"> log.debug(e);</span>
<span class="nc" id="L612"> return null;</span>
<span class="fc" id="L613"> }</span>
}
<span class="fc" id="L615"> return null;</span>
}
/**
* Gets the number of docs.
*
* @param field
* the field
* @return the number of docs
*/
public int getNumberOfDocs(String field) {
<span class="nc bnc" id="L626" title="All 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="nc" id="L627"> FieldReferences fr = fieldReferences.get(field);</span>
<span class="nc" id="L628"> return fr.numberOfDocs;</span>
} else {
<span class="nc" id="L630"> return 0;</span>
}
}
/**
* Gets the number of positions.
*
* @param field
* the field
* @param docId
* the doc id
* @return the number of positions
*/
public Integer getNumberOfPositions(String field, int docId) {
<span class="pc bpc" id="L644" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L645"> IndexDoc doc = getDoc(field, docId);</span>
<span class="pc bpc" id="L646" title="1 of 2 branches missed."> if (doc != null) {</span>
<span class="fc" id="L647"> return 1 + doc.maxPosition - doc.minPosition;</span>
}
}
<span class="nc" id="L650"> return null;</span>
}
/**
* Gets the all number of positions.
*
* @param field
* the field
* @param docBase
* the doc base
* @return the all number of positions
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public HashMap<Integer, Integer> getAllNumberOfPositions(String field,
int docBase) throws IOException {
<span class="fc" id="L666"> HashMap<Integer, Integer> numbers = new HashMap<Integer, Integer>();</span>
<span class="pc bpc" id="L667" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L668"> FieldReferences fr = fieldReferences.get(field);</span>
<span class="fc" id="L669"> IndexInput inIndexDoc = indexInputList.get("doc");</span>
<span class="fc" id="L670"> inIndexDoc.seek(fr.refIndexDoc);</span>
IndexDoc doc;
<span class="fc bfc" id="L672" title="All 2 branches covered."> for (int i = 0; i < fr.numberOfDocs; i++) {</span>
<span class="fc" id="L673"> doc = new IndexDoc(null);</span>
<span class="fc" id="L674"> numbers.put((doc.docId + docBase),</span>
<span class="fc" id="L675"> (1 + doc.maxPosition - doc.minPosition));</span>
}
}
<span class="fc" id="L678"> return numbers;</span>
}
/**
* Gets the number of tokens.
*
* @param field
* the field
* @param docId
* the doc id
* @return the number of tokens
*/
public Integer getNumberOfTokens(String field, int docId) {
<span class="pc bpc" id="L691" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L692"> IndexDoc doc = getDoc(field, docId);</span>
<span class="pc bpc" id="L693" title="1 of 2 branches missed."> if (doc != null) {</span>
<span class="fc" id="L694"> return doc.size;</span>
}
}
<span class="nc" id="L697"> return null;</span>
}
/**
* Gets the all number of tokens.
*
* @param field
* the field
* @param docBase
* the doc base
* @return the all number of tokens
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public HashMap<Integer, Integer> getAllNumberOfTokens(String field,
int docBase) throws IOException {
<span class="fc" id="L713"> HashMap<Integer, Integer> numbers = new HashMap<Integer, Integer>();</span>
<span class="pc bpc" id="L714" title="1 of 2 branches missed."> if (fieldReferences.containsKey(field)) {</span>
<span class="fc" id="L715"> FieldReferences fr = fieldReferences.get(field);</span>
<span class="fc" id="L716"> IndexInput inIndexDoc = indexInputList.get("doc");</span>
<span class="fc" id="L717"> inIndexDoc.seek(fr.refIndexDoc);</span>
IndexDoc doc;
<span class="fc bfc" id="L719" title="All 2 branches covered."> for (int i = 0; i < fr.numberOfDocs; i++) {</span>
<span class="fc" id="L720"> doc = new IndexDoc(null);</span>
<span class="fc" id="L721"> numbers.put((doc.docId + docBase), doc.size);</span>
}
}
<span class="fc" id="L724"> return numbers;</span>
}
/**
* The Class IndexDoc.
*/
public class IndexDoc {
/** The doc id. */
public int docId;
/** The fp index object id. */
public long fpIndexObjectId;
/** The fp index object position. */
public long fpIndexObjectPosition;
/** The fp index object parent. */
public long fpIndexObjectParent;
/** The smallest object filepointer. */
public long smallestObjectFilepointer;
/** The object ref approx offset. */
public long objectRefApproxOffset;
/** The object ref approx quotient. */
public int objectRefApproxQuotient;
/** The storage flags. */
public byte storageFlags;
/** The size. */
public int size;
/** The min position. */
public int minPosition;
/** The max position. */
public int maxPosition;
/**
* Instantiates a new index doc.
*
* @param ref
* the ref
* @throws IOException
* Signals that an I/O exception has occurred.
*/
<span class="fc" id="L773"> public IndexDoc(Long ref) throws IOException {</span>
try {
<span class="fc" id="L775"> IndexInput inIndexDoc = indexInputList.get("doc");</span>
<span class="fc bfc" id="L776" title="All 2 branches covered."> if (ref != null) {</span>
<span class="fc" id="L777"> inIndexDoc.seek(ref);</span>
}
<span class="fc" id="L779"> docId = inIndexDoc.readVInt(); // docId</span>
<span class="fc" id="L780"> fpIndexObjectId = inIndexDoc.readVLong(); // ref indexObjectId</span>
<span class="fc" id="L781"> fpIndexObjectPosition = inIndexDoc.readVLong(); // ref</span>
// indexObjectPosition
<span class="fc" id="L783"> fpIndexObjectParent = inIndexDoc.readVLong(); // ref indexObjectParent</span>
<span class="fc" id="L784"> smallestObjectFilepointer = inIndexDoc.readVLong(); // offset</span>
<span class="fc" id="L785"> objectRefApproxQuotient = inIndexDoc.readVInt(); // slope</span>
<span class="fc" id="L786"> objectRefApproxOffset = inIndexDoc.readZLong(); // offset</span>
<span class="fc" id="L787"> storageFlags = inIndexDoc.readByte(); // flag</span>
<span class="fc" id="L788"> size = inIndexDoc.readVInt(); // number of objects</span>
<span class="fc" id="L789"> minPosition = inIndexDoc.readVInt(); // minimum position</span>
<span class="fc" id="L790"> maxPosition = inIndexDoc.readVInt(); // maximum position</span>
<span class="nc" id="L791"> } catch (Exception e) {</span>
<span class="nc" id="L792"> throw new IOException(e);</span>
<span class="fc" id="L793"> }</span>
<span class="fc" id="L794"> }</span>
}
/**
* The Class FieldReferences.
*/
private static class FieldReferences {
/** The ref index doc. */
public long refIndexDoc;
/** The ref index doc id. */
public long refIndexDocId;
/** The ref prefix. */
public long refPrefix;
/** The number of docs. */
public int numberOfDocs;
/** The number of prefixes. */
public int numberOfPrefixes;
/**
* Instantiates a new field references.
*
* @param refIndexDoc
* the ref index doc
* @param refIndexDocId
* the ref index doc id
* @param numberOfDocs
* the number of docs
* @param refPrefix
* the ref prefix
* @param numberOfPrefixes
* the number of prefixes
*/
public FieldReferences(long refIndexDoc, long refIndexDocId,
<span class="fc" id="L832"> int numberOfDocs, long refPrefix, int numberOfPrefixes) {</span>
<span class="fc" id="L833"> this.refIndexDoc = refIndexDoc;</span>
<span class="fc" id="L834"> this.refIndexDocId = refIndexDocId;</span>
<span class="fc" id="L835"> this.numberOfDocs = numberOfDocs;</span>
<span class="fc" id="L836"> this.refPrefix = refPrefix;</span>
<span class="fc" id="L837"> this.numberOfPrefixes = numberOfPrefixes;</span>
<span class="fc" id="L838"> }</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>