MtasSpanSequenceQuery.java.html
32.4 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
<?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>MtasSpanSequenceQuery.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.search.spans</a> > <span class="el_source">MtasSpanSequenceQuery.java</span></div><h1>MtasSpanSequenceQuery.java</h1><pre class="source lang-java linenums">package mtas.search.spans;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.index.Terms;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.spans.SpanWeight;
import org.apache.lucene.search.spans.Spans;
import mtas.search.spans.util.MtasExpandSpanQuery;
import mtas.search.spans.util.MtasIgnoreItem;
import mtas.search.spans.util.MtasSpanQuery;
import mtas.search.spans.util.MtasSpanWeight;
import mtas.search.spans.util.MtasSpans;
/**
* The Class MtasSpanSequenceQuery.
*/
public class MtasSpanSequenceQuery extends MtasSpanQuery {
/** The items. */
private List<MtasSpanSequenceItem> items;
/** The left minimum. */
private int leftMinimum;
/** The left maximum. */
private int leftMaximum;
/** The right minimum. */
private int rightMinimum;
/** The right maximum. */
private int rightMaximum;
/** The ignore query. */
private MtasSpanQuery ignoreQuery;
/** The maximum ignore length. */
private Integer maximumIgnoreLength;
/** The field. */
private String field;
/**
* Instantiates a new mtas span sequence query.
*
* @param items the items
* @param ignoreQuery the ignore query
* @param maximumIgnoreLength the maximum ignore length
*/
public MtasSpanSequenceQuery(List<MtasSpanSequenceItem> items,
MtasSpanQuery ignoreQuery, Integer maximumIgnoreLength) {
<span class="fc" id="L63"> this(items, 0, 0, 0, 0, ignoreQuery, maximumIgnoreLength);</span>
<span class="fc" id="L64"> }</span>
/**
* Instantiates a new mtas span sequence query.
*
* @param items the items
* @param leftMinimum the left minimum
* @param leftMaximum the left maximum
* @param rightMinimum the right minimum
* @param rightMaximum the right maximum
* @param ignoreQuery the ignore query
* @param maximumIgnoreLength the maximum ignore length
*/
public MtasSpanSequenceQuery(List<MtasSpanSequenceItem> items,
int leftMinimum, int leftMaximum, int rightMinimum, int rightMaximum,
MtasSpanQuery ignoreQuery, Integer maximumIgnoreLength) {
<span class="fc" id="L80"> super(null, null);</span>
<span class="fc" id="L81"> this.items = items;</span>
<span class="fc" id="L82"> this.leftMinimum = leftMinimum;</span>
<span class="fc" id="L83"> this.leftMaximum = leftMaximum;</span>
<span class="fc" id="L84"> this.rightMinimum = rightMinimum;</span>
<span class="fc" id="L85"> this.rightMaximum = rightMaximum;</span>
// get field and do checks
<span class="fc" id="L87"> Integer minimum = leftMinimum + rightMinimum;</span>
<span class="fc" id="L88"> Integer maximum = leftMaximum + rightMaximum;</span>
<span class="fc bfc" id="L89" title="All 2 branches covered."> for (MtasSpanSequenceItem item : items) {</span>
<span class="fc bfc" id="L90" title="All 2 branches covered."> if (field == null) {</span>
<span class="fc" id="L91"> field = item.getQuery().getField();</span>
<span class="pc bpc" id="L92" title="1 of 2 branches missed."> } else if (item.getQuery().getField() != null</span>
<span class="pc bpc" id="L93" title="1 of 2 branches missed."> && !item.getQuery().getField().equals(field)) {</span>
<span class="nc" id="L94"> throw new IllegalArgumentException("Clauses must have same field.");</span>
}
<span class="fc bfc" id="L96" title="All 4 branches covered."> if (minimum != null && !item.isOptional()) {</span>
<span class="fc bfc" id="L97" title="All 2 branches covered."> minimum = item.getQuery().getMinimumWidth() != null</span>
<span class="fc" id="L98"> ? minimum + item.getQuery().getMinimumWidth() : null;</span>
}
<span class="fc bfc" id="L100" title="All 2 branches covered."> if (maximum != null) {</span>
<span class="fc bfc" id="L101" title="All 2 branches covered."> maximum = item.getQuery().getMaximumWidth() != null</span>
<span class="fc" id="L102"> ? maximum + item.getQuery().getMaximumWidth() : null;</span>
}
<span class="fc" id="L104"> }</span>
// check ignore
<span class="pc bpc" id="L106" title="1 of 4 branches missed."> if (field != null && ignoreQuery != null) {</span>
<span class="pc bpc" id="L107" title="1 of 2 branches missed."> if (ignoreQuery.getField() == null</span>
<span class="pc bpc" id="L108" title="1 of 2 branches missed."> || field.equals(ignoreQuery.getField())) {</span>
<span class="fc" id="L109"> this.ignoreQuery = ignoreQuery;</span>
<span class="pc bpc" id="L110" title="1 of 2 branches missed."> if (maximumIgnoreLength == null) {</span>
<span class="nc" id="L111"> this.maximumIgnoreLength = MtasIgnoreItem.DEFAULT_MAXIMUM_IGNORE_LENGTH;</span>
} else {
<span class="fc" id="L113"> this.maximumIgnoreLength = maximumIgnoreLength;</span>
}
} else {
<span class="nc" id="L116"> throw new IllegalArgumentException(</span>
"ignore must have same field as clauses");
}
<span class="pc bpc" id="L119" title="2 of 4 branches missed."> if (maximum != null && items.size() > 1) {</span>
<span class="pc bpc" id="L120" title="1 of 2 branches missed."> if (this.ignoreQuery.getMaximumWidth() != null) {</span>
<span class="fc" id="L121"> maximum += (items.size() - 1) * this.maximumIgnoreLength</span>
<span class="fc" id="L122"> * this.ignoreQuery.getMaximumWidth();</span>
} else {
<span class="nc" id="L124"> maximum = null;</span>
}
}
} else {
<span class="fc" id="L128"> this.ignoreQuery = null;</span>
<span class="fc" id="L129"> this.maximumIgnoreLength = null;</span>
}
<span class="fc" id="L131"> setWidth(minimum, maximum);</span>
<span class="fc" id="L132"> }</span>
/*
* (non-Javadoc)
*
* @see org.apache.lucene.search.spans.SpanQuery#getField()
*/
@Override
public String getField() {
<span class="fc" id="L141"> return field;</span>
}
/**
* Gets the items.
*
* @return the items
*/
public List<MtasSpanSequenceItem> getItems() {
<span class="fc" id="L150"> return items;</span>
}
/**
* Gets the ignore query.
*
* @return the ignore query
*/
public MtasSpanQuery getIgnoreQuery() {
<span class="fc" id="L159"> return ignoreQuery;</span>
}
/**
* Gets the maximum ignore length.
*
* @return the maximum ignore length
*/
public Integer getMaximumIgnoreLength() {
<span class="nc" id="L168"> return maximumIgnoreLength;</span>
}
/*
* (non-Javadoc)
*
* @see
* org.apache.lucene.search.Query#rewrite(org.apache.lucene.index.IndexReader)
*/
@Override
public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
<span class="fc bfc" id="L179" title="All 2 branches covered."> if (items.size() == 1) {</span>
<span class="fc" id="L180"> MtasSpanQuery singleQuery = items.get(0).getQuery();</span>
<span class="fc bfc" id="L181" title="All 4 branches covered."> if (leftMaximum != 0 || rightMaximum != 0) {</span>
<span class="fc" id="L182"> singleQuery = new MtasExpandSpanQuery(singleQuery, leftMinimum,</span>
leftMaximum, rightMinimum, rightMaximum);
}
<span class="fc" id="L185"> return singleQuery.rewrite(reader);</span>
} else {
MtasSpanSequenceItem newItem;
<span class="fc" id="L188"> MtasSpanSequenceItem previousNewItem = null;</span>
<span class="fc" id="L189"> ArrayList<MtasSpanSequenceItem> newItems = new ArrayList<>(items.size());</span>
<span class="fc" id="L190"> int newLeftMinimum = leftMinimum;</span>
<span class="fc" id="L191"> int newLeftMaximum = leftMaximum;</span>
<span class="fc" id="L192"> int newRightMinimum = rightMinimum;</span>
<span class="fc" id="L193"> int newRightMaximum = rightMaximum;</span>
<span class="fc bfc" id="L194" title="All 2 branches covered."> MtasSpanQuery newIgnoreClause = ignoreQuery != null</span>
<span class="fc" id="L195"> ? ignoreQuery.rewrite(reader) : null;</span>
<span class="fc bfc" id="L196" title="All 2 branches covered."> boolean actuallyRewritten = ignoreQuery != null</span>
<span class="fc bfc" id="L197" title="All 2 branches covered."> ? !newIgnoreClause.equals(ignoreQuery) : false;</span>
<span class="fc bfc" id="L198" title="All 2 branches covered."> for (int i = 0; i < items.size(); i++) {</span>
<span class="fc" id="L199"> newItem = items.get(i).rewrite(reader);</span>
<span class="pc bpc" id="L200" title="1 of 2 branches missed."> if (newItem.getQuery() instanceof MtasSpanMatchNoneQuery) {</span>
<span class="nc bnc" id="L201" title="All 2 branches missed."> if (!newItem.isOptional()) {</span>
<span class="nc" id="L202"> return new MtasSpanMatchNoneQuery(field);</span>
} else {
<span class="nc" id="L204"> actuallyRewritten = true;</span>
}
} else {
<span class="fc bfc" id="L207" title="All 2 branches covered."> actuallyRewritten |= !items.get(i).equals(newItem);</span>
<span class="fc" id="L208"> MtasSpanSequenceItem previousMergedItem = MtasSpanSequenceItem.merge(</span>
previousNewItem, newItem, ignoreQuery, maximumIgnoreLength);
<span class="pc bpc" id="L210" title="1 of 2 branches missed."> if (previousMergedItem != null) {</span>
<span class="nc" id="L211"> newItems.set((newItems.size() - 1), previousMergedItem);</span>
<span class="nc" id="L212"> actuallyRewritten = true;</span>
} else {
<span class="fc" id="L214"> newItems.add(newItem);</span>
}
<span class="fc" id="L216"> previousNewItem = newItem;</span>
}
}
// check first and last
<span class="fc bfc" id="L220" title="All 2 branches covered."> if (ignoreQuery == null) {</span>
<span class="fc" id="L221"> ArrayList<MtasSpanSequenceItem> possibleTrimmedItems = new ArrayList<>(</span>
<span class="fc" id="L222"> newItems.size());</span>
<span class="fc" id="L223"> MtasSpanSequenceItem firstItem = newItems.get(0);</span>
<span class="fc" id="L224"> MtasSpanQuery firstQuery = firstItem.getQuery();</span>
<span class="fc bfc" id="L225" title="All 2 branches covered."> if (firstQuery instanceof MtasSpanMatchAllQuery) {</span>
<span class="fc" id="L226"> newLeftMaximum++;</span>
<span class="fc bfc" id="L227" title="All 2 branches covered."> if (!firstItem.isOptional()) {</span>
<span class="fc" id="L228"> newLeftMinimum++;</span>
}
<span class="fc bfc" id="L230" title="All 2 branches covered."> } else if (firstQuery instanceof MtasSpanRecurrenceQuery) {</span>
<span class="fc" id="L231"> MtasSpanRecurrenceQuery firstRecurrenceQuery = (MtasSpanRecurrenceQuery) firstQuery;</span>
<span class="fc bfc" id="L232" title="All 2 branches covered."> if (firstRecurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery</span>
<span class="pc bpc" id="L233" title="1 of 2 branches missed."> && firstRecurrenceQuery.getIgnoreQuery() == null) {</span>
<span class="pc bpc" id="L234" title="1 of 2 branches missed."> if (!firstItem.isOptional()) {</span>
<span class="nc" id="L235"> newLeftMinimum += firstRecurrenceQuery.getMinimumRecurrence();</span>
<span class="nc" id="L236"> newLeftMaximum += firstRecurrenceQuery.getMaximumRecurrence();</span>
} else {
<span class="pc bpc" id="L238" title="1 of 2 branches missed."> if (firstRecurrenceQuery.getMinimumRecurrence() == 1</span>
|| firstRecurrenceQuery
<span class="nc bnc" id="L240" title="All 2 branches missed."> .getMinimumRecurrence() <= newLeftMinimum) {</span>
<span class="fc" id="L241"> newLeftMinimum += 0;</span>
<span class="fc" id="L242"> newLeftMaximum += firstRecurrenceQuery.getMaximumRecurrence();</span>
} else {
<span class="nc" id="L244"> possibleTrimmedItems.add(firstItem);</span>
}
}
} else {
<span class="fc" id="L248"> possibleTrimmedItems.add(firstItem);</span>
}
<span class="fc" id="L250"> } else {</span>
<span class="fc" id="L251"> possibleTrimmedItems.add(firstItem);</span>
}
<span class="fc bfc" id="L253" title="All 2 branches covered."> for (int i = 1; i < (newItems.size() - 1); i++) {</span>
<span class="fc" id="L254"> possibleTrimmedItems.add(newItems.get(i));</span>
}
<span class="pc bpc" id="L256" title="1 of 2 branches missed."> if (newItems.size() > 1) {</span>
<span class="fc" id="L257"> MtasSpanSequenceItem lastItem = newItems.get((newItems.size() - 1));</span>
<span class="fc" id="L258"> MtasSpanQuery lastQuery = lastItem.getQuery();</span>
<span class="fc bfc" id="L259" title="All 2 branches covered."> if (lastQuery instanceof MtasSpanMatchAllQuery) {</span>
<span class="fc" id="L260"> newRightMaximum++;</span>
<span class="fc bfc" id="L261" title="All 2 branches covered."> if (!lastItem.isOptional()) {</span>
<span class="fc" id="L262"> newRightMinimum++;</span>
}
<span class="fc bfc" id="L264" title="All 2 branches covered."> } else if (lastQuery instanceof MtasSpanRecurrenceQuery) {</span>
<span class="fc" id="L265"> MtasSpanRecurrenceQuery lastRecurrenceQuery = (MtasSpanRecurrenceQuery) lastQuery;</span>
<span class="fc bfc" id="L266" title="All 2 branches covered."> if (lastRecurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery</span>
<span class="pc bpc" id="L267" title="1 of 2 branches missed."> && lastRecurrenceQuery.getIgnoreQuery() == null) {</span>
<span class="fc bfc" id="L268" title="All 2 branches covered."> if (!lastItem.isOptional()) {</span>
<span class="fc" id="L269"> newRightMinimum += lastRecurrenceQuery.getMinimumRecurrence();</span>
<span class="fc" id="L270"> newRightMaximum += lastRecurrenceQuery.getMaximumRecurrence();</span>
<span class="pc bpc" id="L271" title="1 of 2 branches missed."> } else if (lastRecurrenceQuery.getMinimumRecurrence() == 1</span>
|| lastRecurrenceQuery
<span class="nc bnc" id="L273" title="All 2 branches missed."> .getMinimumRecurrence() <= newRightMinimum) {</span>
<span class="fc" id="L274"> newRightMinimum += 0;</span>
<span class="fc" id="L275"> newRightMaximum += lastRecurrenceQuery.getMaximumRecurrence();</span>
} else {
<span class="nc" id="L277"> possibleTrimmedItems.add(lastItem);</span>
}
} else {
<span class="fc" id="L280"> possibleTrimmedItems.add(lastItem);</span>
}
<span class="fc" id="L282"> } else {</span>
<span class="fc" id="L283"> possibleTrimmedItems.add(lastItem);</span>
}
}
<span class="fc bfc" id="L286" title="All 2 branches covered."> if (possibleTrimmedItems.size() < newItems.size()) {</span>
<span class="fc" id="L287"> actuallyRewritten = true;</span>
<span class="fc" id="L288"> newItems = possibleTrimmedItems;</span>
}
}
<span class="fc bfc" id="L291" title="All 2 branches covered."> if (!actuallyRewritten) {</span>
<span class="fc bfc" id="L292" title="All 4 branches covered."> if (leftMaximum != 0 || rightMaximum != 0) {</span>
<span class="fc" id="L293"> newLeftMinimum = leftMinimum;</span>
<span class="fc" id="L294"> newLeftMaximum = leftMaximum;</span>
<span class="fc" id="L295"> newRightMinimum = rightMinimum;</span>
<span class="fc" id="L296"> newRightMaximum = rightMaximum;</span>
<span class="fc" id="L297"> leftMinimum = 0;</span>
<span class="fc" id="L298"> leftMaximum = 0;</span>
<span class="fc" id="L299"> rightMinimum = 0;</span>
<span class="fc" id="L300"> rightMaximum = 0;</span>
<span class="fc" id="L301"> MtasSpanQuery finalQuery = new MtasExpandSpanQuery(this,</span>
newLeftMinimum, newLeftMaximum, newRightMinimum, newRightMaximum);
<span class="fc" id="L303"> return finalQuery.rewrite(reader);</span>
} else {
<span class="fc" id="L305"> return super.rewrite(reader);</span>
}
} else {
<span class="pc bpc" id="L308" title="1 of 2 branches missed."> if (!newItems.isEmpty()) {</span>
<span class="fc" id="L309"> return new MtasSpanSequenceQuery(newItems, newLeftMinimum,</span>
newLeftMaximum, newRightMinimum, newRightMaximum, newIgnoreClause,
<span class="fc" id="L311"> maximumIgnoreLength).rewrite(reader);</span>
} else {
<span class="nc" id="L313"> return new MtasSpanMatchNoneQuery(field);</span>
}
}
}
}
/*
* (non-Javadoc)
*
* @see org.apache.lucene.search.Query#toString(java.lang.String)
*/
@Override
public String toString(String field) {
<span class="nc" id="L326"> StringBuilder buffer = new StringBuilder();</span>
<span class="nc" id="L327"> buffer.append(this.getClass().getSimpleName() + "([");</span>
<span class="nc" id="L328"> Iterator<MtasSpanSequenceItem> i = items.iterator();</span>
<span class="nc bnc" id="L329" title="All 2 branches missed."> while (i.hasNext()) {</span>
<span class="nc" id="L330"> MtasSpanSequenceItem item = i.next();</span>
<span class="nc" id="L331"> MtasSpanQuery clause = item.getQuery();</span>
<span class="nc" id="L332"> buffer.append(clause.toString(field));</span>
<span class="nc bnc" id="L333" title="All 2 branches missed."> if (item.isOptional()) {</span>
<span class="nc" id="L334"> buffer.append("{OPTIONAL}");</span>
}
<span class="nc bnc" id="L336" title="All 2 branches missed."> if (i.hasNext()) {</span>
<span class="nc" id="L337"> buffer.append(", ");</span>
}
<span class="nc" id="L339"> }</span>
<span class="nc" id="L340"> buffer.append("[" + leftMinimum + "," + leftMaximum + "]");</span>
<span class="nc" id="L341"> buffer.append("[" + rightMinimum + "," + rightMaximum + "]");</span>
<span class="nc" id="L342"> buffer.append("]");</span>
<span class="nc" id="L343"> buffer.append(", ");</span>
<span class="nc" id="L344"> buffer.append(ignoreQuery);</span>
<span class="nc" id="L345"> buffer.append(")");</span>
<span class="nc" id="L346"> return buffer.toString();</span>
}
/*
* (non-Javadoc)
*
* @see org.apache.lucene.search.Query#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
<span class="fc bfc" id="L356" title="All 2 branches covered."> if (this == obj)</span>
<span class="fc" id="L357"> return true;</span>
<span class="pc bpc" id="L358" title="1 of 2 branches missed."> if (obj == null)</span>
<span class="nc" id="L359"> return false;</span>
<span class="fc bfc" id="L360" title="All 2 branches covered."> if (getClass() != obj.getClass())</span>
<span class="fc" id="L361"> return false;</span>
<span class="fc" id="L362"> MtasSpanSequenceQuery other = (MtasSpanSequenceQuery) obj;</span>
boolean isEqual;
<span class="fc" id="L364"> isEqual = field.equals(other.field);</span>
<span class="fc" id="L365"> isEqual &= items.equals(other.items);</span>
<span class="pc bpc" id="L366" title="1 of 2 branches missed."> isEqual &= leftMinimum == other.leftMinimum;</span>
<span class="pc bpc" id="L367" title="1 of 2 branches missed."> isEqual &= leftMaximum == other.leftMaximum;</span>
<span class="pc bpc" id="L368" title="1 of 2 branches missed."> isEqual &= rightMinimum == other.rightMinimum;</span>
<span class="pc bpc" id="L369" title="1 of 2 branches missed."> isEqual &= rightMaximum == other.rightMaximum;</span>
<span class="pc bpc" id="L370" title="3 of 8 branches missed."> isEqual &= ((ignoreQuery == null && other.ignoreQuery == null)</span>
|| (ignoreQuery != null && other.ignoreQuery != null
<span class="pc bpc" id="L372" title="1 of 2 branches missed."> && ignoreQuery.equals(other.ignoreQuery)));</span>
<span class="fc" id="L373"> return isEqual;</span>
}
/*
* (non-Javadoc)
*
* @see org.apache.lucene.search.Query#hashCode()
*/
@Override
public int hashCode() {
<span class="fc" id="L383"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="fc" id="L384"> h = (h * 3) ^ field.hashCode();</span>
<span class="fc" id="L385"> h = (h * 5) ^ items.hashCode();</span>
<span class="fc" id="L386"> h = Integer.rotateLeft(h, leftMinimum) + leftMinimum;</span>
<span class="fc" id="L387"> h ^= 11;</span>
<span class="fc" id="L388"> h = Integer.rotateLeft(h, leftMaximum) + leftMaximum;</span>
<span class="fc" id="L389"> h ^= 13;</span>
<span class="fc" id="L390"> h = Integer.rotateLeft(h, rightMinimum) + rightMinimum;</span>
<span class="fc" id="L391"> h ^= 17;</span>
<span class="fc" id="L392"> h = Integer.rotateLeft(h, rightMaximum) + rightMaximum;</span>
<span class="pc bpc" id="L393" title="1 of 2 branches missed."> if (ignoreQuery != null) {</span>
<span class="nc" id="L394"> h = (h * 7) ^ ignoreQuery.hashCode();</span>
<span class="nc" id="L395"> h = (h * 11) ^ maximumIgnoreLength.hashCode();</span>
}
<span class="fc" id="L397"> return h;</span>
}
/*
* (non-Javadoc)
*
* @see
* org.apache.lucene.search.spans.SpanQuery#createWeight(org.apache.lucene.
* search.IndexSearcher, boolean)
*/
@Override
public MtasSpanWeight createWeight(IndexSearcher searcher,
boolean needsScores) throws IOException {
<span class="fc" id="L410"> List<MtasSpanSequenceQueryWeight> subWeights = new ArrayList<>();</span>
<span class="fc" id="L411"> SpanWeight ignoreWeight = null;</span>
<span class="fc bfc" id="L412" title="All 2 branches covered."> for (MtasSpanSequenceItem item : items) {</span>
<span class="fc" id="L413"> subWeights.add(new MtasSpanSequenceQueryWeight(</span>
<span class="fc" id="L414"> item.getQuery().createWeight(searcher, false), item.isOptional()));</span>
<span class="fc" id="L415"> }</span>
<span class="fc bfc" id="L416" title="All 2 branches covered."> if (ignoreQuery != null) {</span>
<span class="fc" id="L417"> ignoreWeight = ignoreQuery.createWeight(searcher, false);</span>
}
<span class="pc bpc" id="L419" title="1 of 2 branches missed."> return new SpanSequenceWeight(subWeights, ignoreWeight, maximumIgnoreLength,</span>
<span class="pc" id="L420"> searcher, needsScores ? getTermContexts(subWeights) : null);</span>
}
/**
* Gets the term contexts.
*
* @param items the items
* @return the term contexts
*/
protected Map<Term, TermContext> getTermContexts(
List<MtasSpanSequenceQueryWeight> items) {
<span class="nc" id="L431"> List<SpanWeight> weights = new ArrayList<>();</span>
<span class="nc bnc" id="L432" title="All 2 branches missed."> for (MtasSpanSequenceQueryWeight item : items) {</span>
<span class="nc" id="L433"> weights.add(item.spanWeight);</span>
<span class="nc" id="L434"> }</span>
<span class="nc" id="L435"> return getTermContexts(weights);</span>
}
/*
* (non-Javadoc)
*
* @see mtas.search.spans.util.MtasSpanQuery#disableTwoPhaseIterator()
*/
@Override
public void disableTwoPhaseIterator() {
<span class="fc" id="L445"> super.disableTwoPhaseIterator();</span>
<span class="fc bfc" id="L446" title="All 2 branches covered."> for (MtasSpanSequenceItem item : items) {</span>
<span class="fc" id="L447"> item.getQuery().disableTwoPhaseIterator();</span>
<span class="fc" id="L448"> }</span>
<span class="fc bfc" id="L449" title="All 2 branches covered."> if (ignoreQuery != null) {</span>
<span class="fc" id="L450"> ignoreQuery.disableTwoPhaseIterator();</span>
}
<span class="fc" id="L452"> }</span>
/**
* The Class SpanSequenceWeight.
*/
protected class SpanSequenceWeight extends MtasSpanWeight {
/** The sub weights. */
final List<MtasSpanSequenceQueryWeight> subWeights;
/** The ignore weight. */
final SpanWeight ignoreWeight;
/** The maximum ignore length. */
final Integer maximumIgnoreLength;
/**
* Instantiates a new span sequence weight.
*
* @param subWeights the sub weights
* @param ignoreWeight the ignore weight
* @param maximumIgnoreLength the maximum ignore length
* @param searcher the searcher
* @param terms the terms
* @throws IOException Signals that an I/O exception has occurred.
*/
public SpanSequenceWeight(List<MtasSpanSequenceQueryWeight> subWeights,
SpanWeight ignoreWeight, Integer maximumIgnoreLength,
IndexSearcher searcher, Map<Term, TermContext> terms)
<span class="fc" id="L481"> throws IOException {</span>
<span class="fc" id="L482"> super(MtasSpanSequenceQuery.this, searcher, terms);</span>
<span class="fc" id="L483"> this.subWeights = subWeights;</span>
<span class="fc" id="L484"> this.ignoreWeight = ignoreWeight;</span>
<span class="fc" id="L485"> this.maximumIgnoreLength = maximumIgnoreLength;</span>
<span class="fc" id="L486"> }</span>
/*
* (non-Javadoc)
*
* @see
* org.apache.lucene.search.spans.SpanWeight#extractTermContexts(java.util.
* Map)
*/
@Override
public void extractTermContexts(Map<Term, TermContext> contexts) {
<span class="fc bfc" id="L497" title="All 2 branches covered."> for (MtasSpanSequenceQueryWeight w : subWeights) {</span>
<span class="fc" id="L498"> w.spanWeight.extractTermContexts(contexts);</span>
<span class="fc" id="L499"> }</span>
<span class="pc bpc" id="L500" title="1 of 2 branches missed."> if (ignoreWeight != null) {</span>
<span class="nc" id="L501"> ignoreWeight.extractTermContexts(contexts);</span>
}
<span class="fc" id="L503"> }</span>
/*
* (non-Javadoc)
*
* @see
* org.apache.lucene.search.spans.SpanWeight#getSpans(org.apache.lucene.
* index.LeafReaderContext,
* org.apache.lucene.search.spans.SpanWeight.Postings)
*/
@Override
public MtasSpans getSpans(LeafReaderContext context,
Postings requiredPostings) throws IOException {
<span class="pc bpc" id="L516" title="1 of 2 branches missed."> if (field == null) {</span>
<span class="nc" id="L517"> return null;</span>
} else {
<span class="fc" id="L519"> Terms terms = context.reader().terms(field);</span>
<span class="pc bpc" id="L520" title="1 of 2 branches missed."> if (terms == null) {</span>
<span class="nc" id="L521"> return null; // field does not exist</span>
}
<span class="fc" id="L523"> List<MtasSpanSequenceQuerySpans> setSequenceSpans = new ArrayList<>(</span>
<span class="fc" id="L524"> items.size());</span>
<span class="fc" id="L525"> Spans ignoreSpans = null;</span>
<span class="fc" id="L526"> boolean allSpansEmpty = true;</span>
<span class="fc bfc" id="L527" title="All 2 branches covered."> for (MtasSpanSequenceQueryWeight w : subWeights) {</span>
<span class="fc" id="L528"> Spans sequenceSpans = w.spanWeight.getSpans(context,</span>
requiredPostings);
<span class="pc bpc" id="L530" title="1 of 2 branches missed."> if (sequenceSpans != null) {</span>
<span class="fc" id="L531"> setSequenceSpans.add(new MtasSpanSequenceQuerySpans(</span>
MtasSpanSequenceQuery.this, sequenceSpans, w.optional));
<span class="fc" id="L533"> allSpansEmpty = false;</span>
} else {
<span class="nc bnc" id="L535" title="All 2 branches missed."> if (w.optional) {</span>
<span class="nc" id="L536"> setSequenceSpans.add(new MtasSpanSequenceQuerySpans(</span>
MtasSpanSequenceQuery.this, null, w.optional));
} else {
<span class="nc" id="L539"> return null;</span>
}
}
<span class="fc" id="L542"> }</span>
<span class="pc bpc" id="L543" title="1 of 2 branches missed."> if (allSpansEmpty) {</span>
<span class="nc" id="L544"> return null; // at least one required</span>
<span class="fc bfc" id="L545" title="All 2 branches covered."> } else if (ignoreWeight != null) {</span>
<span class="fc" id="L546"> ignoreSpans = ignoreWeight.getSpans(context, requiredPostings);</span>
}
<span class="fc" id="L548"> return new MtasSpanSequenceSpans(MtasSpanSequenceQuery.this,</span>
setSequenceSpans, ignoreSpans, maximumIgnoreLength);
}
}
/*
* (non-Javadoc)
*
* @see org.apache.lucene.search.Weight#extractTerms(java.util.Set)
*/
@Override
public void extractTerms(Set<Term> terms) {
<span class="nc bnc" id="L560" title="All 2 branches missed."> for (MtasSpanSequenceQueryWeight w : subWeights) {</span>
<span class="nc" id="L561"> w.spanWeight.extractTerms(terms);</span>
<span class="nc" id="L562"> }</span>
<span class="nc bnc" id="L563" title="All 2 branches missed."> if (ignoreWeight != null) {</span>
<span class="nc" id="L564"> ignoreWeight.extractTerms(terms);</span>
}
<span class="nc" id="L566"> }</span>
}
/**
* The Class MtasSpanSequenceQuerySpans.
*/
protected static class MtasSpanSequenceQuerySpans {
/** The spans. */
public Spans spans;
/** The optional. */
public boolean optional;
/**
* Instantiates a new mtas span sequence query spans.
*
* @param query the query
* @param spans the spans
* @param optional the optional
*/
public MtasSpanSequenceQuerySpans(MtasSpanSequenceQuery query, Spans spans,
<span class="fc" id="L589"> boolean optional) {</span>
<span class="pc bpc" id="L590" title="1 of 2 branches missed."> this.spans = spans != null ? spans : new MtasSpanMatchNoneSpans(query);</span>
<span class="fc" id="L591"> this.optional = optional;</span>
<span class="fc" id="L592"> }</span>
}
/**
* The Class MtasSpanSequenceQueryWeight.
*/
private static class MtasSpanSequenceQueryWeight {
/** The span weight. */
public SpanWeight spanWeight;
/** The optional. */
public boolean optional;
/**
* Instantiates a new mtas span sequence query weight.
*
* @param spanWeight the span weight
* @param optional the optional
*/
public MtasSpanSequenceQueryWeight(SpanWeight spanWeight,
<span class="fc" id="L613"> boolean optional) {</span>
<span class="fc" id="L614"> this.spanWeight = spanWeight;</span>
<span class="fc" id="L615"> this.optional = optional;</span>
<span class="fc" id="L616"> }</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>