| 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 | |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 5 | import de.ids_mannheim.korap.util.QueryException; |
| 6 | |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 7 | import de.ids_mannheim.korap.query.SpanFocusQuery; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 8 | import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 9 | |
| 10 | import java.util.*; |
| 11 | |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 12 | // Support maybeUnsorted! |
| 13 | // Rename this to SpanFocusQueryWrapper |
| 14 | // Support multiple classes |
| 15 | |
| 16 | // Sorting: |
| 17 | // - Sort with a buffer of matches, e.g. 25/50, |
| 18 | // So gather 50 hits, sort them, return the first 25, |
| 19 | // Add new 25, sort the last 50, return 25 etc. |
| 20 | // On processing, there should be an ability to raise |
| 21 | // a warning, in case an unordered result bubbles up. |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 22 | |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 23 | public class SpanFocusQueryWrapper extends SpanQueryWrapper { |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 24 | private SpanQueryWrapper subquery; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 25 | private byte number; |
| 26 | |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 27 | public SpanFocusQueryWrapper (SpanQueryWrapper subquery, byte number) { |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 28 | this.subquery = subquery; |
| 29 | this.number = number; |
| 30 | }; |
| 31 | |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 32 | public SpanFocusQueryWrapper (SpanQueryWrapper subquery, short number) { |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 33 | this.subquery = subquery; |
| 34 | this.number = (byte) number; |
| 35 | }; |
| 36 | |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 37 | public SpanFocusQueryWrapper (SpanQueryWrapper subquery, int number) { |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 38 | this.subquery = subquery; |
| 39 | this.number = (byte) number; |
| 40 | }; |
| 41 | |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 42 | public SpanFocusQueryWrapper (SpanQueryWrapper subquery) { |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 43 | this.subquery = subquery; |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 44 | this.number = (byte) 1; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 47 | public SpanQuery toQuery () throws QueryException { |
| Nils Diewald | b9dd413 | 2015-02-16 16:32:41 +0000 | [diff] [blame] | 48 | if (this.subquery.isNull()) |
| 49 | return (SpanQuery) null; |
| Nils Diewald | cec40f9 | 2015-02-19 22:20:02 +0000 | [diff] [blame^] | 50 | return new SpanFocusQuery( |
| Nils Diewald | b9dd413 | 2015-02-16 16:32:41 +0000 | [diff] [blame] | 51 | this.subquery.retrieveNode(this.retrieveNode).toQuery(), this.number |
| 52 | ); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 53 | }; |
| Nils Diewald | 6b33281 | 2014-07-22 18:51:05 +0000 | [diff] [blame] | 54 | |
| 55 | public boolean isOptional () { |
| Nils Diewald | 602c922 | 2014-07-23 19:49:53 +0000 | [diff] [blame] | 56 | return this.subquery.isOptional(); |
| Nils Diewald | 6b33281 | 2014-07-22 18:51:05 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | public boolean isNull () { |
| 60 | return this.subquery.isNull(); |
| 61 | }; |
| Nils Diewald | cc7c0b3 | 2014-07-31 19:58:22 +0000 | [diff] [blame] | 62 | |
| 63 | public boolean isNegative () { |
| 64 | return this.subquery.isNegative(); |
| 65 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 66 | }; |