ferret 0.11.3 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
data/ext/q_parser.c CHANGED
@@ -95,6 +95,7 @@
95
95
  #include <string.h>
96
96
  #include <ctype.h>
97
97
  #include <wctype.h>
98
+ #include "except.h"
98
99
  #include "search.h"
99
100
  #include "array.h"
100
101
 
@@ -137,7 +138,7 @@ int qp_default_fuzzy_pre_len = 0;
137
138
 
138
139
  #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
139
140
  typedef union YYSTYPE
140
- #line 26 "src/q_parser.y"
141
+ #line 27 "src/q_parser.y"
141
142
  {
142
143
  Query *query;
143
144
  BooleanClause *bcls;
@@ -147,7 +148,7 @@ typedef union YYSTYPE
147
148
  char *str;
148
149
  }
149
150
  /* Line 193 of yacc.c. */
150
- #line 151 "y.tab.c"
151
+ #line 152 "y.tab.c"
151
152
  YYSTYPE;
152
153
  # define yystype YYSTYPE /* obsolescent; will be withdrawn */
153
154
  # define YYSTYPE_IS_DECLARED 1
@@ -157,7 +158,7 @@ typedef union YYSTYPE
157
158
 
158
159
 
159
160
  /* Copy the second part of user declarations. */
160
- #line 34 "src/q_parser.y"
161
+ #line 35 "src/q_parser.y"
161
162
 
162
163
  static int yylex(YYSTYPE *lvalp, QParser *qp);
163
164
  static int yyerror(QParser *qp, char const *msg);
@@ -169,6 +170,7 @@ static BCArray *first_cls(BooleanClause *boolean_clause);
169
170
  static BCArray *add_and_cls(BCArray *bca, BooleanClause *clause);
170
171
  static BCArray *add_or_cls(BCArray *bca, BooleanClause *clause);
171
172
  static BCArray *add_default_cls(QParser *qp, BCArray *bca, BooleanClause *clause);
173
+ static void bca_destroy(BCArray *bca);
172
174
 
173
175
  static BooleanClause *get_bool_cls(Query *q, unsigned int occur);
174
176
 
@@ -184,35 +186,55 @@ static Query *get_phrase_q(QParser *qp, Phrase *phrase, char *slop);
184
186
  static Phrase *ph_first_word(char *word);
185
187
  static Phrase *ph_add_word(Phrase *self, char *word);
186
188
  static Phrase *ph_add_multi_word(Phrase *self, char *word);
189
+ static void ph_destroy(Phrase *self);
187
190
 
188
191
  static Query *get_r_q(QParser *qp, char *field, char *from, char *to,
189
192
  bool inc_lower, bool inc_upper);
190
193
 
191
194
  #define FLDS(q, func) do {\
192
- char *field;\
193
- if (qp->fields->size == 0) {\
194
- q = NULL;\
195
- } else if (qp->fields->size == 1) {\
196
- field = (char *)qp->fields->elems[0];\
197
- q = func;\
198
- } else {\
199
- int i;Query *sq;\
200
- q = bq_new(false);\
201
- for (i = 0; i < qp->fields->size; i++) {\
202
- field = (char *)qp->fields->elems[i];\
203
- sq = func;\
204
- if (sq) bq_add_query_nr(q, sq, BC_SHOULD);\
205
- }\
206
- if (((BooleanQuery *)q)->clause_cnt == 0) {\
207
- q_deref(q);\
195
+ TRY {\
196
+ char *field;\
197
+ if (qp->fields->size == 0) {\
208
198
  q = NULL;\
199
+ } else if (qp->fields->size == 1) {\
200
+ field = (char *)qp->fields->elems[0];\
201
+ q = func;\
202
+ } else {\
203
+ int i;Query *sq;\
204
+ q = bq_new_max(false, qp->max_clauses);\
205
+ for (i = 0; i < qp->fields->size; i++) {\
206
+ field = (char *)qp->fields->elems[i];\
207
+ sq = func;\
208
+ TRY\
209
+ if (sq) bq_add_query_nr(q, sq, BC_SHOULD);\
210
+ XCATCHALL\
211
+ if (sq) q_deref(sq);\
212
+ XENDTRY\
213
+ }\
214
+ if (((BooleanQuery *)q)->clause_cnt == 0) {\
215
+ q_deref(q);\
216
+ q = NULL;\
217
+ }\
209
218
  }\
210
- }\
219
+ } XCATCHALL\
220
+ qp->destruct = true;\
221
+ HANDLED();\
222
+ XENDTRY\
223
+ if (qp->destruct && !qp->recovering && q) {q_deref(q); q = NULL;}\
211
224
  } while (0)
212
225
 
226
+ #define Y if (qp->destruct) goto yyerrorlab;
227
+ #define T TRY
228
+ #define E\
229
+ XCATCHALL\
230
+ qp->destruct = true;\
231
+ HANDLED();\
232
+ XENDTRY\
233
+ if (qp->destruct) Y;
234
+
213
235
 
214
236
  /* Line 216 of yacc.c. */
215
- #line 216 "y.tab.c"
237
+ #line 238 "y.tab.c"
216
238
 
217
239
  #ifdef short
218
240
  # undef short
@@ -515,12 +537,12 @@ static const yytype_int8 yyrhs[] =
515
537
  /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
516
538
  static const yytype_uint8 yyrline[] =
517
539
  {
518
- 0, 102, 102, 103, 105, 106, 107, 108, 110, 111,
519
- 112, 114, 115, 117, 118, 119, 120, 121, 122, 123,
520
- 125, 126, 127, 129, 131, 131, 133, 133, 133, 136,
521
- 137, 139, 140, 141, 142, 144, 145, 146, 147, 148,
522
- 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
523
- 160, 161
540
+ 0, 128, 128, 129, 131, 132, 133, 134, 136, 137,
541
+ 138, 140, 141, 143, 144, 145, 146, 147, 148, 149,
542
+ 151, 152, 153, 155, 157, 157, 159, 159, 159, 162,
543
+ 163, 165, 166, 167, 168, 170, 171, 172, 173, 174,
544
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
545
+ 186, 187
524
546
  };
525
547
  #endif
526
548
 
@@ -1178,6 +1200,61 @@ yydestruct (yymsg, yytype, yyvaluep, qp)
1178
1200
 
1179
1201
  switch (yytype)
1180
1202
  {
1203
+ case 27: /* "bool_q" */
1204
+ #line 123 "src/q_parser.y"
1205
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1206
+ #line 1207 "y.tab.c"
1207
+ break;
1208
+ case 28: /* "bool_clss" */
1209
+ #line 125 "src/q_parser.y"
1210
+ { if ((yyvaluep->bclss) && qp->destruct) bca_destroy((yyvaluep->bclss)); };
1211
+ #line 1212 "y.tab.c"
1212
+ break;
1213
+ case 29: /* "bool_cls" */
1214
+ #line 124 "src/q_parser.y"
1215
+ { if ((yyvaluep->bcls) && qp->destruct) bc_deref((yyvaluep->bcls)); };
1216
+ #line 1217 "y.tab.c"
1217
+ break;
1218
+ case 30: /* "boosted_q" */
1219
+ #line 123 "src/q_parser.y"
1220
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1221
+ #line 1222 "y.tab.c"
1222
+ break;
1223
+ case 31: /* "q" */
1224
+ #line 123 "src/q_parser.y"
1225
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1226
+ #line 1227 "y.tab.c"
1227
+ break;
1228
+ case 32: /* "term_q" */
1229
+ #line 123 "src/q_parser.y"
1230
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1231
+ #line 1232 "y.tab.c"
1232
+ break;
1233
+ case 33: /* "wild_q" */
1234
+ #line 123 "src/q_parser.y"
1235
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1236
+ #line 1237 "y.tab.c"
1237
+ break;
1238
+ case 34: /* "field_q" */
1239
+ #line 123 "src/q_parser.y"
1240
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1241
+ #line 1242 "y.tab.c"
1242
+ break;
1243
+ case 39: /* "phrase_q" */
1244
+ #line 123 "src/q_parser.y"
1245
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1246
+ #line 1247 "y.tab.c"
1247
+ break;
1248
+ case 40: /* "ph_words" */
1249
+ #line 126 "src/q_parser.y"
1250
+ { if ((yyvaluep->phrase) && qp->destruct) ph_destroy((yyvaluep->phrase)); };
1251
+ #line 1252 "y.tab.c"
1252
+ break;
1253
+ case 41: /* "range_q" */
1254
+ #line 123 "src/q_parser.y"
1255
+ { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); };
1256
+ #line 1257 "y.tab.c"
1257
+ break;
1181
1258
 
1182
1259
  default:
1183
1260
  break;
@@ -1485,228 +1562,228 @@ yyreduce:
1485
1562
  switch (yyn)
1486
1563
  {
1487
1564
  case 2:
1488
- #line 102 "src/q_parser.y"
1489
- { qp->result = (yyval.query) = NULL; }
1565
+ #line 128 "src/q_parser.y"
1566
+ { qp->result = (yyval.query) = NULL; }
1490
1567
  break;
1491
1568
 
1492
1569
  case 3:
1493
- #line 103 "src/q_parser.y"
1494
- { qp->result = (yyval.query) = get_bool_q((yyvsp[(1) - (1)].bclss)); }
1570
+ #line 129 "src/q_parser.y"
1571
+ { T qp->result = (yyval.query) = get_bool_q((yyvsp[(1) - (1)].bclss)); E }
1495
1572
  break;
1496
1573
 
1497
1574
  case 4:
1498
- #line 105 "src/q_parser.y"
1499
- { (yyval.bclss) = first_cls((yyvsp[(1) - (1)].bcls)); }
1575
+ #line 131 "src/q_parser.y"
1576
+ { T (yyval.bclss) = first_cls((yyvsp[(1) - (1)].bcls)); E }
1500
1577
  break;
1501
1578
 
1502
1579
  case 5:
1503
- #line 106 "src/q_parser.y"
1504
- { (yyval.bclss) = add_and_cls((yyvsp[(1) - (3)].bclss), (yyvsp[(3) - (3)].bcls)); }
1580
+ #line 132 "src/q_parser.y"
1581
+ { T (yyval.bclss) = add_and_cls((yyvsp[(1) - (3)].bclss), (yyvsp[(3) - (3)].bcls)); E }
1505
1582
  break;
1506
1583
 
1507
1584
  case 6:
1508
- #line 107 "src/q_parser.y"
1509
- { (yyval.bclss) = add_or_cls((yyvsp[(1) - (3)].bclss), (yyvsp[(3) - (3)].bcls)); }
1585
+ #line 133 "src/q_parser.y"
1586
+ { T (yyval.bclss) = add_or_cls((yyvsp[(1) - (3)].bclss), (yyvsp[(3) - (3)].bcls)); E }
1510
1587
  break;
1511
1588
 
1512
1589
  case 7:
1513
- #line 108 "src/q_parser.y"
1514
- { (yyval.bclss) = add_default_cls(qp, (yyvsp[(1) - (2)].bclss), (yyvsp[(2) - (2)].bcls)); }
1590
+ #line 134 "src/q_parser.y"
1591
+ { T (yyval.bclss) = add_default_cls(qp, (yyvsp[(1) - (2)].bclss), (yyvsp[(2) - (2)].bcls)); E }
1515
1592
  break;
1516
1593
 
1517
1594
  case 8:
1518
- #line 110 "src/q_parser.y"
1519
- { (yyval.bcls) = get_bool_cls((yyvsp[(2) - (2)].query), BC_MUST); }
1595
+ #line 136 "src/q_parser.y"
1596
+ { T (yyval.bcls) = get_bool_cls((yyvsp[(2) - (2)].query), BC_MUST); E }
1520
1597
  break;
1521
1598
 
1522
1599
  case 9:
1523
- #line 111 "src/q_parser.y"
1524
- { (yyval.bcls) = get_bool_cls((yyvsp[(2) - (2)].query), BC_MUST_NOT); }
1600
+ #line 137 "src/q_parser.y"
1601
+ { T (yyval.bcls) = get_bool_cls((yyvsp[(2) - (2)].query), BC_MUST_NOT); E }
1525
1602
  break;
1526
1603
 
1527
1604
  case 10:
1528
- #line 112 "src/q_parser.y"
1529
- { (yyval.bcls) = get_bool_cls((yyvsp[(1) - (1)].query), BC_SHOULD); }
1605
+ #line 138 "src/q_parser.y"
1606
+ { T (yyval.bcls) = get_bool_cls((yyvsp[(1) - (1)].query), BC_SHOULD); E }
1530
1607
  break;
1531
1608
 
1532
1609
  case 12:
1533
- #line 115 "src/q_parser.y"
1534
- { if ((yyvsp[(1) - (3)].query)) sscanf((yyvsp[(3) - (3)].str),"%f",&((yyvsp[(1) - (3)].query)->boost)); (yyval.query)=(yyvsp[(1) - (3)].query); }
1610
+ #line 141 "src/q_parser.y"
1611
+ { T if ((yyvsp[(1) - (3)].query)) sscanf((yyvsp[(3) - (3)].str),"%f",&((yyvsp[(1) - (3)].query)->boost)); (yyval.query)=(yyvsp[(1) - (3)].query); E }
1535
1612
  break;
1536
1613
 
1537
1614
  case 14:
1538
- #line 118 "src/q_parser.y"
1539
- { (yyval.query) = bq_new(true); }
1615
+ #line 144 "src/q_parser.y"
1616
+ { T (yyval.query) = bq_new_max(true, qp->max_clauses); E }
1540
1617
  break;
1541
1618
 
1542
1619
  case 15:
1543
- #line 119 "src/q_parser.y"
1544
- { (yyval.query) = get_bool_q((yyvsp[(2) - (3)].bclss)); }
1620
+ #line 145 "src/q_parser.y"
1621
+ { T (yyval.query) = get_bool_q((yyvsp[(2) - (3)].bclss)); E }
1545
1622
  break;
1546
1623
 
1547
1624
  case 20:
1548
- #line 125 "src/q_parser.y"
1549
- { FLDS((yyval.query), get_term_q(qp, field, (yyvsp[(1) - (1)].str))); }
1625
+ #line 151 "src/q_parser.y"
1626
+ { FLDS((yyval.query), get_term_q(qp, field, (yyvsp[(1) - (1)].str))); Y}
1550
1627
  break;
1551
1628
 
1552
1629
  case 21:
1553
- #line 126 "src/q_parser.y"
1554
- { FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str))); }
1630
+ #line 152 "src/q_parser.y"
1631
+ { FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str))); Y}
1555
1632
  break;
1556
1633
 
1557
1634
  case 22:
1558
- #line 127 "src/q_parser.y"
1559
- { FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[(1) - (2)].str), NULL)); }
1635
+ #line 153 "src/q_parser.y"
1636
+ { FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[(1) - (2)].str), NULL)); Y}
1560
1637
  break;
1561
1638
 
1562
1639
  case 23:
1563
- #line 129 "src/q_parser.y"
1564
- { FLDS((yyval.query), get_wild_q(qp, field, (yyvsp[(1) - (1)].str))); }
1640
+ #line 155 "src/q_parser.y"
1641
+ { FLDS((yyval.query), get_wild_q(qp, field, (yyvsp[(1) - (1)].str))); Y}
1565
1642
  break;
1566
1643
 
1567
1644
  case 24:
1568
- #line 131 "src/q_parser.y"
1645
+ #line 157 "src/q_parser.y"
1569
1646
  { qp->fields = qp->def_fields; }
1570
1647
  break;
1571
1648
 
1572
1649
  case 25:
1573
- #line 132 "src/q_parser.y"
1650
+ #line 158 "src/q_parser.y"
1574
1651
  { (yyval.query) = (yyvsp[(3) - (4)].query); }
1575
1652
  break;
1576
1653
 
1577
1654
  case 26:
1578
- #line 133 "src/q_parser.y"
1655
+ #line 159 "src/q_parser.y"
1579
1656
  { qp->fields = qp->all_fields; }
1580
1657
  break;
1581
1658
 
1582
1659
  case 27:
1583
- #line 133 "src/q_parser.y"
1660
+ #line 159 "src/q_parser.y"
1584
1661
  {qp->fields = qp->def_fields;}
1585
1662
  break;
1586
1663
 
1587
1664
  case 28:
1588
- #line 134 "src/q_parser.y"
1665
+ #line 160 "src/q_parser.y"
1589
1666
  { (yyval.query) = (yyvsp[(4) - (5)].query); }
1590
1667
  break;
1591
1668
 
1592
1669
  case 29:
1593
- #line 136 "src/q_parser.y"
1670
+ #line 162 "src/q_parser.y"
1594
1671
  { (yyval.hashset) = first_field(qp, (yyvsp[(1) - (1)].str)); }
1595
1672
  break;
1596
1673
 
1597
1674
  case 30:
1598
- #line 137 "src/q_parser.y"
1675
+ #line 163 "src/q_parser.y"
1599
1676
  { (yyval.hashset) = add_field(qp, (yyvsp[(3) - (3)].str));}
1600
1677
  break;
1601
1678
 
1602
1679
  case 31:
1603
- #line 139 "src/q_parser.y"
1680
+ #line 165 "src/q_parser.y"
1604
1681
  { (yyval.query) = get_phrase_q(qp, (yyvsp[(2) - (3)].phrase), NULL); }
1605
1682
  break;
1606
1683
 
1607
1684
  case 32:
1608
- #line 140 "src/q_parser.y"
1685
+ #line 166 "src/q_parser.y"
1609
1686
  { (yyval.query) = get_phrase_q(qp, (yyvsp[(2) - (5)].phrase), (yyvsp[(5) - (5)].str)); }
1610
1687
  break;
1611
1688
 
1612
1689
  case 33:
1613
- #line 141 "src/q_parser.y"
1690
+ #line 167 "src/q_parser.y"
1614
1691
  { (yyval.query) = NULL; }
1615
1692
  break;
1616
1693
 
1617
1694
  case 34:
1618
- #line 142 "src/q_parser.y"
1619
- { (yyval.query) = NULL; }
1695
+ #line 168 "src/q_parser.y"
1696
+ { (yyval.query) = NULL; (void)(yyvsp[(4) - (4)].str);}
1620
1697
  break;
1621
1698
 
1622
1699
  case 35:
1623
- #line 144 "src/q_parser.y"
1700
+ #line 170 "src/q_parser.y"
1624
1701
  { (yyval.phrase) = ph_first_word((yyvsp[(1) - (1)].str)); }
1625
1702
  break;
1626
1703
 
1627
1704
  case 36:
1628
- #line 145 "src/q_parser.y"
1705
+ #line 171 "src/q_parser.y"
1629
1706
  { (yyval.phrase) = ph_first_word(NULL); }
1630
1707
  break;
1631
1708
 
1632
1709
  case 37:
1633
- #line 146 "src/q_parser.y"
1710
+ #line 172 "src/q_parser.y"
1634
1711
  { (yyval.phrase) = ph_add_word((yyvsp[(1) - (2)].phrase), (yyvsp[(2) - (2)].str)); }
1635
1712
  break;
1636
1713
 
1637
1714
  case 38:
1638
- #line 147 "src/q_parser.y"
1715
+ #line 173 "src/q_parser.y"
1639
1716
  { (yyval.phrase) = ph_add_word((yyvsp[(1) - (3)].phrase), NULL); }
1640
1717
  break;
1641
1718
 
1642
1719
  case 39:
1643
- #line 148 "src/q_parser.y"
1720
+ #line 174 "src/q_parser.y"
1644
1721
  { (yyval.phrase) = ph_add_multi_word((yyvsp[(1) - (3)].phrase), (yyvsp[(3) - (3)].str)); }
1645
1722
  break;
1646
1723
 
1647
1724
  case 40:
1648
- #line 150 "src/q_parser.y"
1649
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), true, true)); }
1725
+ #line 176 "src/q_parser.y"
1726
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), true, true)); Y}
1650
1727
  break;
1651
1728
 
1652
1729
  case 41:
1653
- #line 151 "src/q_parser.y"
1654
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), true, false)); }
1730
+ #line 177 "src/q_parser.y"
1731
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), true, false)); Y}
1655
1732
  break;
1656
1733
 
1657
1734
  case 42:
1658
- #line 152 "src/q_parser.y"
1659
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), false, true)); }
1735
+ #line 178 "src/q_parser.y"
1736
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), false, true)); Y}
1660
1737
  break;
1661
1738
 
1662
1739
  case 43:
1663
- #line 153 "src/q_parser.y"
1664
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), false, false)); }
1740
+ #line 179 "src/q_parser.y"
1741
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), false, false)); Y}
1665
1742
  break;
1666
1743
 
1667
1744
  case 44:
1668
- #line 154 "src/q_parser.y"
1669
- { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (3)].str), false, false)); }
1745
+ #line 180 "src/q_parser.y"
1746
+ { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (3)].str), false, false)); Y}
1670
1747
  break;
1671
1748
 
1672
1749
  case 45:
1673
- #line 155 "src/q_parser.y"
1674
- { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (3)].str), false, true)); }
1750
+ #line 181 "src/q_parser.y"
1751
+ { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (3)].str), false, true)); Y}
1675
1752
  break;
1676
1753
 
1677
1754
  case 46:
1678
- #line 156 "src/q_parser.y"
1679
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (3)].str), NULL,true, false)); }
1755
+ #line 182 "src/q_parser.y"
1756
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (3)].str), NULL,true, false)); Y}
1680
1757
  break;
1681
1758
 
1682
1759
  case 47:
1683
- #line 157 "src/q_parser.y"
1684
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (3)].str), NULL,false, false)); }
1760
+ #line 183 "src/q_parser.y"
1761
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (3)].str), NULL,false, false)); Y}
1685
1762
  break;
1686
1763
 
1687
1764
  case 48:
1688
- #line 158 "src/q_parser.y"
1689
- { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (2)].str), false, false)); }
1765
+ #line 184 "src/q_parser.y"
1766
+ { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (2)].str), false, false)); Y}
1690
1767
  break;
1691
1768
 
1692
1769
  case 49:
1693
- #line 159 "src/q_parser.y"
1694
- { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(3) - (3)].str), false, true)); }
1770
+ #line 185 "src/q_parser.y"
1771
+ { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(3) - (3)].str), false, true)); Y}
1695
1772
  break;
1696
1773
 
1697
1774
  case 50:
1698
- #line 160 "src/q_parser.y"
1699
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(3) - (3)].str), NULL,true, false)); }
1775
+ #line 186 "src/q_parser.y"
1776
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(3) - (3)].str), NULL,true, false)); Y}
1700
1777
  break;
1701
1778
 
1702
1779
  case 51:
1703
- #line 161 "src/q_parser.y"
1704
- { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (2)].str), NULL,false, false)); }
1780
+ #line 187 "src/q_parser.y"
1781
+ { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (2)].str), NULL,false, false)); Y}
1705
1782
  break;
1706
1783
 
1707
1784
 
1708
1785
  /* Line 1267 of yacc.c. */
1709
- #line 1710 "y.tab.c"
1786
+ #line 1787 "y.tab.c"
1710
1787
  default: break;
1711
1788
  }
1712
1789
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1920,7 +1997,7 @@ yyreturn:
1920
1997
  }
1921
1998
 
1922
1999
 
1923
- #line 163 "src/q_parser.y"
2000
+ #line 189 "src/q_parser.y"
1924
2001
 
1925
2002
 
1926
2003
  const char *special_char = "&:()[]{}!\"~^|<>=*?+-";
@@ -2039,6 +2116,7 @@ static int yylex(YYSTYPE *lvalp, QParser *qp)
2039
2116
 
2040
2117
  static int yyerror(QParser *qp, char const *msg)
2041
2118
  {
2119
+ qp->destruct = true;
2042
2120
  if (!qp->handle_parse_errors) {
2043
2121
  char buf[1024];
2044
2122
  buf[1023] = '\0';
@@ -2047,8 +2125,9 @@ static int yyerror(QParser *qp, char const *msg)
2047
2125
  free(qp->qstr);
2048
2126
  }
2049
2127
  mutex_unlock(&qp->mutex);
2050
- RAISE(PARSE_ERROR, "couldn't parse query ``%s''. Error message "
2051
- " was %s", buf, (char *)msg);
2128
+ snprintf(xmsg_buffer, XMSG_BUFFER_SIZE,
2129
+ "couldn't parse query ``%s''. Error message "
2130
+ " was %s", buf, (char *)msg);
2052
2131
  }
2053
2132
  return 0;
2054
2133
  }
@@ -2177,6 +2256,16 @@ static BCArray *add_default_cls(QParser *qp, BCArray *bca,
2177
2256
  return bca;
2178
2257
  }
2179
2258
 
2259
+ static void bca_destroy(BCArray *bca)
2260
+ {
2261
+ int i;
2262
+ for (i = 0; i < bca->size; i++) {
2263
+ bc_deref(bca->clauses[i]);
2264
+ }
2265
+ free(bca->clauses);
2266
+ free(bca);
2267
+ }
2268
+
2180
2269
  static BooleanClause *get_bool_cls(Query *q, unsigned int occur)
2181
2270
  {
2182
2271
  if (q) {
@@ -2400,7 +2489,7 @@ static Query *get_phrase_query(QParser *qp, char *field,
2400
2489
  }
2401
2490
  else {
2402
2491
  int i;
2403
- q = bq_new(false);
2492
+ q = bq_new_max(false, qp->max_clauses);
2404
2493
  for (i = 0; i < word_count; i++) {
2405
2494
  bq_add_query_nr(q, get_term_q(qp, field, words[i]), BC_SHOULD);
2406
2495
  }
@@ -2465,7 +2554,7 @@ static Query *get_phrase_query(QParser *qp, char *field,
2465
2554
 
2466
2555
  static Query *get_phrase_q(QParser *qp, Phrase *phrase, char *slop_str)
2467
2556
  {
2468
- Query *q;
2557
+ Query *q = NULL;
2469
2558
  FLDS(q, get_phrase_query(qp, field, phrase, slop_str));
2470
2559
  ph_destroy(phrase);
2471
2560
  return q;
@@ -2664,7 +2753,8 @@ char *qp_clean_str(char *str)
2664
2753
 
2665
2754
  Query *qp_get_bad_query(QParser *qp, char *str)
2666
2755
  {
2667
- Query *q;
2756
+ Query *volatile q = NULL;
2757
+ qp->recovering = true;
2668
2758
  FLDS(q, get_term_q(qp, field, str));
2669
2759
  return q;
2670
2760
  }
@@ -2673,6 +2763,7 @@ Query *qp_parse(QParser *self, char *qstr)
2673
2763
  {
2674
2764
  Query *result = NULL;
2675
2765
  mutex_lock(&self->mutex);
2766
+ self->recovering = self->destruct = false;
2676
2767
  if (self->clean_str) {
2677
2768
  self->qstrp = self->qstr = qp_clean_str(qstr);
2678
2769
  }
@@ -2682,15 +2773,14 @@ Query *qp_parse(QParser *self, char *qstr)
2682
2773
  self->fields = self->def_fields;
2683
2774
  self->result = NULL;
2684
2775
 
2685
- TRY
2686
- yyparse(self);
2687
- result = self->result;
2688
- XCATCHALL
2689
- if (self->handle_parse_errors) HANDLED();
2690
- XENDTRY
2776
+ if (0 == yyparse(self)) result = self->result;
2691
2777
  if (!result && self->handle_parse_errors) {
2778
+ self->destruct = false;
2692
2779
  result = qp_get_bad_query(self, self->qstr);
2693
2780
  }
2781
+ if (self->destruct && !self->handle_parse_errors) {
2782
+ xraise(PARSE_ERROR, xmsg_buffer);
2783
+ }
2694
2784
  if (!result) {
2695
2785
  result = bq_new(false);
2696
2786
  }