| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.query.wrap; |
| 2 | |
| 3 | import org.apache.lucene.search.spans.SpanQuery; |
| 4 | |
| 5 | import de.ids_mannheim.korap.query.SpanClassQuery; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 6 | import de.ids_mannheim.korap.util.QueryException; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 7 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 8 | |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 9 | // TODO: If this.subquery.isNegative(), it may be an Expansion! |
| 10 | // SpanExpansionQuery(x, y.negative, min, max. direction???, classNumber, true) |
| 11 | |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 12 | public class SpanClassQueryWrapper extends SpanQueryWrapper { |
| 13 | private SpanQueryWrapper subquery; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 14 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 15 | |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 16 | public SpanClassQueryWrapper (SpanQueryWrapper subquery, byte number) { |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 17 | this.subquery = subquery; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 18 | this.number = number; |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 19 | if (number != (byte) 0) |
| 20 | this.hasClass = true; |
| Akron | a26184e | 2018-12-05 15:37:34 +0100 | [diff] [blame] | 21 | this.maybeUnsorted = subquery.maybeUnsorted(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 24 | |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 25 | public SpanClassQueryWrapper (SpanQueryWrapper subquery, short number) { |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 26 | this(subquery, (byte) number); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 29 | |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 30 | public SpanClassQueryWrapper (SpanQueryWrapper subquery, int number) { |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 31 | this(subquery, (byte) number); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 34 | |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 35 | public SpanClassQueryWrapper (SpanQueryWrapper subquery) { |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 36 | this(subquery, (byte) 0); |
| 37 | }; |
| 38 | |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 39 | |
| 40 | @Override |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 41 | public boolean isEmpty () { |
| 42 | return this.subquery.isEmpty(); |
| 43 | }; |
| 44 | |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 45 | |
| 46 | @Override |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 47 | public boolean isOptional () { |
| 48 | return this.subquery.isOptional(); |
| 49 | }; |
| 50 | |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 51 | |
| 52 | @Override |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 53 | public boolean isNull () { |
| 54 | return this.subquery.isNull(); |
| 55 | }; |
| 56 | |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 57 | |
| 58 | @Override |
| Nils Diewald | 0cc4f2e | 2015-01-30 20:13:08 +0000 | [diff] [blame] | 59 | public boolean isNegative () { |
| 60 | return this.subquery.isNegative(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 63 | public SpanQuery toFragmentQuery () throws QueryException { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 64 | if (this.subquery.isNull()) |
| Nils Diewald | 6409a92 | 2015-01-29 20:50:42 +0000 | [diff] [blame] | 65 | return (SpanQuery) null; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 66 | |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 67 | SpanQuery sq = (SpanQuery) this.subquery.retrieveNode(this.retrieveNode) |
| 68 | .toFragmentQuery(); |
| Nils Diewald | 6409a92 | 2015-01-29 20:50:42 +0000 | [diff] [blame] | 69 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 70 | if (sq == null) |
| 71 | return (SpanQuery) null; |
| 72 | |
| Nils Diewald | 6409a92 | 2015-01-29 20:50:42 +0000 | [diff] [blame] | 73 | if (this.number == (byte) 0) { |
| 74 | return new SpanClassQuery(sq); |
| 75 | }; |
| 76 | return new SpanClassQuery(sq, (byte) this.number); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 77 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 78 | }; |