| 64 | private long p; |
| 65 | |
| 66 | @Override |
| 67 | public boolean next(final QueryContext qc) throws QueryException { |
| 68 | while(true) { |
| 69 | // next iteration, reset iterator and counter |
| 70 | Item item = null; |
| 71 | if(iter != null) { |
| 72 | if(scoring) { |
| 73 | final boolean s = qc.scoring; |
| 74 | try { |
| 75 | qc.scoring = true; |
| 76 | item = qc.next(iter); |
| 77 | } finally { |
| 78 | qc.scoring = s; |
| 79 | } |
| 80 | } else { |
| 81 | item = qc.next(iter); |
| 82 | } |
| 83 | } |
| 84 | if(item != null) { |
| 85 | // there's another item to serve |
| 86 | ++p; |
| 87 | qc.set(var, item); |
| 88 | if(pos != null) qc.set(pos, Itr.get(p)); |
| 89 | if(score != null) qc.set(score, Dbl.get(item.score())); |
| 90 | return true; |
| 91 | } |
| 92 | if(empty && iter != null && p == 0) { |
| 93 | // expression yields no items, bind the empty sequence instead |
| 94 | qc.set(var, Empty.VALUE); |
| 95 | if(pos != null) qc.set(pos, Itr.get(p)); |
| 96 | if(score != null) qc.set(score, Dbl.ZERO); |
| 97 | iter = null; |
| 98 | return true; |
| 99 | } |
| 100 | // no more iterations from above, we're done here |
| 101 | if(!sub.next(qc)) return false; |
| 102 | |
| 103 | // next iteration, reset iterator and counter |
| 104 | if(scoring) { |
| 105 | final boolean s = qc.scoring; |
| 106 | try { |
| 107 | qc.scoring = true; |
| 108 | iter = expr.iter(qc); |
| 109 | } finally { |
| 110 | qc.scoring = s; |
| 111 | } |
| 112 | } else { |
| 113 | iter = expr.iter(qc); |
| 114 | } |
| 115 | p = 0; |
| 116 | } |
| 117 | } |
| 118 | }; |
| 119 | } |
| 120 | |