ferret 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/ind.c +1 -0
- data/ext/q_fuzzy.c +0 -3
- data/ext/q_parser.c +56 -52
- data/lib/ferret.rb +1 -1
- data/lib/ferret/query_parser/query_parser.tab.rb +4 -4
- data/lib/rferret.rb +1 -1
- data/test/unit/index/tc_index.rb +26 -0
- metadata +2 -2
data/ext/ind.c
CHANGED
@@ -283,6 +283,7 @@ TopDocs *index_search_str(Index *self, char *qstr, int first_doc,
|
|
283
283
|
Query *query;
|
284
284
|
TopDocs *td;
|
285
285
|
query = index_get_query(self, qstr); /* will ensure_searcher is open */
|
286
|
+
//printf(">> %s <<\n", query->to_s(query, ""));
|
286
287
|
td = sea_search(self->sea, query, first_doc, num_docs, filter, sort);
|
287
288
|
q_deref(query);
|
288
289
|
return td;
|
data/ext/q_fuzzy.c
CHANGED
@@ -65,7 +65,6 @@ float fuzq_score(FuzzyQuery *fuzq, char *target)
|
|
65
65
|
if (((m+1) * (n+1)) >= fuzq->da_capa) {
|
66
66
|
fuzq->da_capa = ((m+1) * (n+1)) * 2;
|
67
67
|
REALLOC_N(fuzq->da, int, fuzq->da_capa);
|
68
|
-
printf("making capa %d -> %d\n", fuzq->da_capa, (int)fuzq->da);
|
69
68
|
d = fuzq->da;
|
70
69
|
}
|
71
70
|
|
@@ -253,9 +252,7 @@ void fuzq_destroy(Query *self)
|
|
253
252
|
{
|
254
253
|
FuzzyQuery *fuzq = (FuzzyQuery *)self->data;
|
255
254
|
if (self->destroy_all) term_destroy((Term *)fuzq->term);
|
256
|
-
printf("freeing %d -> %d\n", fuzq->da_capa, (int)fuzq->da);
|
257
255
|
free(fuzq->da);
|
258
|
-
printf("success\n");
|
259
256
|
free(fuzq);
|
260
257
|
q_destroy_i(self);
|
261
258
|
}
|
data/ext/q_parser.c
CHANGED
@@ -179,12 +179,16 @@ Query *get_range_q(char *field, char *from, char *to,
|
|
179
179
|
sq = func;\
|
180
180
|
if (sq) bq_add_query(q, sq, BC_SHOULD);\
|
181
181
|
}\
|
182
|
+
if (((BooleanQuery *)q->data)->clause_cnt == 0) {\
|
183
|
+
q_deref(q);\
|
184
|
+
q = NULL;\
|
185
|
+
}\
|
182
186
|
}\
|
183
187
|
} while (0)
|
184
188
|
|
185
189
|
|
186
190
|
/* Line 219 of yacc.c. */
|
187
|
-
#line
|
191
|
+
#line 192 "y.tab.c"
|
188
192
|
|
189
193
|
#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
|
190
194
|
# define YYSIZE_T __SIZE_TYPE__
|
@@ -423,12 +427,12 @@ static const yysigned_char yyrhs[] =
|
|
423
427
|
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
|
424
428
|
static const unsigned char yyrline[] =
|
425
429
|
{
|
426
|
-
0,
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
430
|
+
0, 90, 90, 91, 93, 94, 95, 96, 98, 99,
|
431
|
+
100, 102, 103, 105, 106, 107, 108, 109, 110, 112,
|
432
|
+
113, 114, 116, 118, 118, 120, 120, 120, 123, 124,
|
433
|
+
126, 127, 128, 129, 131, 132, 133, 134, 135, 137,
|
434
|
+
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
|
435
|
+
148
|
432
436
|
};
|
433
437
|
#endif
|
434
438
|
|
@@ -1236,217 +1240,217 @@ yyreduce:
|
|
1236
1240
|
switch (yyn)
|
1237
1241
|
{
|
1238
1242
|
case 2:
|
1239
|
-
#line
|
1243
|
+
#line 90 "src/query_parser/q_parser.y"
|
1240
1244
|
{ qp->result = (yyval.query) = NULL; }
|
1241
1245
|
break;
|
1242
1246
|
|
1243
1247
|
case 3:
|
1244
|
-
#line
|
1248
|
+
#line 91 "src/query_parser/q_parser.y"
|
1245
1249
|
{ qp->result = (yyval.query) = get_bool_q((yyvsp[0].array)); }
|
1246
1250
|
break;
|
1247
1251
|
|
1248
1252
|
case 4:
|
1249
|
-
#line
|
1253
|
+
#line 93 "src/query_parser/q_parser.y"
|
1250
1254
|
{ (yyval.array) = first_cls((yyvsp[0].bcls)); }
|
1251
1255
|
break;
|
1252
1256
|
|
1253
1257
|
case 5:
|
1254
|
-
#line
|
1258
|
+
#line 94 "src/query_parser/q_parser.y"
|
1255
1259
|
{ (yyval.array) = add_and_cls((yyvsp[-2].array), (yyvsp[0].bcls)); }
|
1256
1260
|
break;
|
1257
1261
|
|
1258
1262
|
case 6:
|
1259
|
-
#line
|
1263
|
+
#line 95 "src/query_parser/q_parser.y"
|
1260
1264
|
{ (yyval.array) = add_or_cls((yyvsp[-2].array), (yyvsp[0].bcls)); }
|
1261
1265
|
break;
|
1262
1266
|
|
1263
1267
|
case 7:
|
1264
|
-
#line
|
1268
|
+
#line 96 "src/query_parser/q_parser.y"
|
1265
1269
|
{ (yyval.array) = add_default_cls(qp, (yyvsp[-1].array), (yyvsp[0].bcls)); }
|
1266
1270
|
break;
|
1267
1271
|
|
1268
1272
|
case 8:
|
1269
|
-
#line
|
1273
|
+
#line 98 "src/query_parser/q_parser.y"
|
1270
1274
|
{ (yyval.bcls) = get_bool_cls((yyvsp[0].query), BC_MUST); }
|
1271
1275
|
break;
|
1272
1276
|
|
1273
1277
|
case 9:
|
1274
|
-
#line
|
1278
|
+
#line 99 "src/query_parser/q_parser.y"
|
1275
1279
|
{ (yyval.bcls) = get_bool_cls((yyvsp[0].query), BC_MUST_NOT); }
|
1276
1280
|
break;
|
1277
1281
|
|
1278
1282
|
case 10:
|
1279
|
-
#line
|
1283
|
+
#line 100 "src/query_parser/q_parser.y"
|
1280
1284
|
{ (yyval.bcls) = get_bool_cls((yyvsp[0].query), BC_SHOULD); }
|
1281
1285
|
break;
|
1282
1286
|
|
1283
1287
|
case 12:
|
1284
|
-
#line
|
1288
|
+
#line 103 "src/query_parser/q_parser.y"
|
1285
1289
|
{ if ((yyvsp[-2].query)) sscanf((yyvsp[0].str),"%f",&((yyvsp[-2].query)->boost)); (yyval.query)=(yyvsp[-2].query); }
|
1286
1290
|
break;
|
1287
1291
|
|
1288
1292
|
case 14:
|
1289
|
-
#line
|
1293
|
+
#line 106 "src/query_parser/q_parser.y"
|
1290
1294
|
{ (yyval.query) = get_bool_q((yyvsp[-1].array)); }
|
1291
1295
|
break;
|
1292
1296
|
|
1293
1297
|
case 19:
|
1294
|
-
#line
|
1298
|
+
#line 112 "src/query_parser/q_parser.y"
|
1295
1299
|
{ FLDS((yyval.query), get_term_q(qp, field, (yyvsp[0].str))); }
|
1296
1300
|
break;
|
1297
1301
|
|
1298
1302
|
case 20:
|
1299
|
-
#line
|
1303
|
+
#line 113 "src/query_parser/q_parser.y"
|
1300
1304
|
{ FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[-2].str), (yyvsp[0].str))); }
|
1301
1305
|
break;
|
1302
1306
|
|
1303
1307
|
case 21:
|
1304
|
-
#line
|
1308
|
+
#line 114 "src/query_parser/q_parser.y"
|
1305
1309
|
{ FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[-1].str), NULL)); }
|
1306
1310
|
break;
|
1307
1311
|
|
1308
1312
|
case 22:
|
1309
|
-
#line
|
1313
|
+
#line 116 "src/query_parser/q_parser.y"
|
1310
1314
|
{ FLDS((yyval.query), get_wild_q(qp, field, (yyvsp[0].str))); }
|
1311
1315
|
break;
|
1312
1316
|
|
1313
1317
|
case 23:
|
1314
|
-
#line
|
1318
|
+
#line 118 "src/query_parser/q_parser.y"
|
1315
1319
|
{ qp->fields = qp->def_fields; }
|
1316
1320
|
break;
|
1317
1321
|
|
1318
1322
|
case 24:
|
1319
|
-
#line
|
1323
|
+
#line 119 "src/query_parser/q_parser.y"
|
1320
1324
|
{ (yyval.query) = (yyvsp[-1].query); }
|
1321
1325
|
break;
|
1322
1326
|
|
1323
1327
|
case 25:
|
1324
|
-
#line
|
1328
|
+
#line 120 "src/query_parser/q_parser.y"
|
1325
1329
|
{ qp->fields = qp->all_fields; }
|
1326
1330
|
break;
|
1327
1331
|
|
1328
1332
|
case 26:
|
1329
|
-
#line
|
1333
|
+
#line 120 "src/query_parser/q_parser.y"
|
1330
1334
|
{qp->fields = qp->def_fields;}
|
1331
1335
|
break;
|
1332
1336
|
|
1333
1337
|
case 27:
|
1334
|
-
#line
|
1338
|
+
#line 121 "src/query_parser/q_parser.y"
|
1335
1339
|
{ (yyval.query) = (yyvsp[-1].query); }
|
1336
1340
|
break;
|
1337
1341
|
|
1338
1342
|
case 28:
|
1339
|
-
#line
|
1343
|
+
#line 123 "src/query_parser/q_parser.y"
|
1340
1344
|
{ (yyval.hashset) = first_field(qp, (yyvsp[0].str)); }
|
1341
1345
|
break;
|
1342
1346
|
|
1343
1347
|
case 29:
|
1344
|
-
#line
|
1348
|
+
#line 124 "src/query_parser/q_parser.y"
|
1345
1349
|
{ (yyval.hashset) = add_field(qp, (yyvsp[0].str));}
|
1346
1350
|
break;
|
1347
1351
|
|
1348
1352
|
case 30:
|
1349
|
-
#line
|
1353
|
+
#line 126 "src/query_parser/q_parser.y"
|
1350
1354
|
{ (yyval.query) = get_phrase_q(qp, (yyvsp[-1].phrase), NULL); }
|
1351
1355
|
break;
|
1352
1356
|
|
1353
1357
|
case 31:
|
1354
|
-
#line
|
1358
|
+
#line 127 "src/query_parser/q_parser.y"
|
1355
1359
|
{ (yyval.query) = get_phrase_q(qp, (yyvsp[-3].phrase), (yyvsp[0].str)); }
|
1356
1360
|
break;
|
1357
1361
|
|
1358
1362
|
case 32:
|
1359
|
-
#line
|
1363
|
+
#line 128 "src/query_parser/q_parser.y"
|
1360
1364
|
{ (yyval.query) = NULL; }
|
1361
1365
|
break;
|
1362
1366
|
|
1363
1367
|
case 33:
|
1364
|
-
#line
|
1368
|
+
#line 129 "src/query_parser/q_parser.y"
|
1365
1369
|
{ (yyval.query) = NULL; }
|
1366
1370
|
break;
|
1367
1371
|
|
1368
1372
|
case 34:
|
1369
|
-
#line
|
1373
|
+
#line 131 "src/query_parser/q_parser.y"
|
1370
1374
|
{ (yyval.phrase) = ph_first_word((yyvsp[0].str)); }
|
1371
1375
|
break;
|
1372
1376
|
|
1373
1377
|
case 35:
|
1374
|
-
#line
|
1378
|
+
#line 132 "src/query_parser/q_parser.y"
|
1375
1379
|
{ (yyval.phrase) = ph_first_word(NULL); }
|
1376
1380
|
break;
|
1377
1381
|
|
1378
1382
|
case 36:
|
1379
|
-
#line
|
1383
|
+
#line 133 "src/query_parser/q_parser.y"
|
1380
1384
|
{ (yyval.phrase) = ph_add_word((yyvsp[-1].phrase), (yyvsp[0].str)); }
|
1381
1385
|
break;
|
1382
1386
|
|
1383
1387
|
case 37:
|
1384
|
-
#line
|
1388
|
+
#line 134 "src/query_parser/q_parser.y"
|
1385
1389
|
{ (yyval.phrase) = ph_add_word((yyvsp[-2].phrase), NULL); }
|
1386
1390
|
break;
|
1387
1391
|
|
1388
1392
|
case 38:
|
1389
|
-
#line
|
1393
|
+
#line 135 "src/query_parser/q_parser.y"
|
1390
1394
|
{ (yyval.phrase) = ph_add_multi_word((yyvsp[-2].phrase), (yyvsp[0].str)); }
|
1391
1395
|
break;
|
1392
1396
|
|
1393
1397
|
case 39:
|
1394
|
-
#line
|
1398
|
+
#line 137 "src/query_parser/q_parser.y"
|
1395
1399
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[-2].str), (yyvsp[-1].str), true, true)); }
|
1396
1400
|
break;
|
1397
1401
|
|
1398
1402
|
case 40:
|
1399
|
-
#line
|
1403
|
+
#line 138 "src/query_parser/q_parser.y"
|
1400
1404
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[-2].str), (yyvsp[-1].str), true, false)); }
|
1401
1405
|
break;
|
1402
1406
|
|
1403
1407
|
case 41:
|
1404
|
-
#line
|
1408
|
+
#line 139 "src/query_parser/q_parser.y"
|
1405
1409
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[-2].str), (yyvsp[-1].str), false, true)); }
|
1406
1410
|
break;
|
1407
1411
|
|
1408
1412
|
case 42:
|
1409
|
-
#line
|
1413
|
+
#line 140 "src/query_parser/q_parser.y"
|
1410
1414
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[-2].str), (yyvsp[-1].str), false, false)); }
|
1411
1415
|
break;
|
1412
1416
|
|
1413
1417
|
case 43:
|
1414
|
-
#line
|
1418
|
+
#line 141 "src/query_parser/q_parser.y"
|
1415
1419
|
{ FLDS((yyval.query), get_range_q(field, NULL,(yyvsp[-1].str), false, false)); }
|
1416
1420
|
break;
|
1417
1421
|
|
1418
1422
|
case 44:
|
1419
|
-
#line
|
1423
|
+
#line 142 "src/query_parser/q_parser.y"
|
1420
1424
|
{ FLDS((yyval.query), get_range_q(field, NULL,(yyvsp[-1].str), false, true)); }
|
1421
1425
|
break;
|
1422
1426
|
|
1423
1427
|
case 45:
|
1424
|
-
#line
|
1428
|
+
#line 143 "src/query_parser/q_parser.y"
|
1425
1429
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[-1].str), NULL,true, false)); }
|
1426
1430
|
break;
|
1427
1431
|
|
1428
1432
|
case 46:
|
1429
|
-
#line
|
1433
|
+
#line 144 "src/query_parser/q_parser.y"
|
1430
1434
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[-1].str), NULL,false, false)); }
|
1431
1435
|
break;
|
1432
1436
|
|
1433
1437
|
case 47:
|
1434
|
-
#line
|
1438
|
+
#line 145 "src/query_parser/q_parser.y"
|
1435
1439
|
{ FLDS((yyval.query), get_range_q(field, NULL,(yyvsp[0].str), false, false)); }
|
1436
1440
|
break;
|
1437
1441
|
|
1438
1442
|
case 48:
|
1439
|
-
#line
|
1443
|
+
#line 146 "src/query_parser/q_parser.y"
|
1440
1444
|
{ FLDS((yyval.query), get_range_q(field, NULL,(yyvsp[0].str), false, true)); }
|
1441
1445
|
break;
|
1442
1446
|
|
1443
1447
|
case 49:
|
1444
|
-
#line
|
1448
|
+
#line 147 "src/query_parser/q_parser.y"
|
1445
1449
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[0].str), NULL,true, false)); }
|
1446
1450
|
break;
|
1447
1451
|
|
1448
1452
|
case 50:
|
1449
|
-
#line
|
1453
|
+
#line 148 "src/query_parser/q_parser.y"
|
1450
1454
|
{ FLDS((yyval.query), get_range_q(field, (yyvsp[0].str), NULL,false, false)); }
|
1451
1455
|
break;
|
1452
1456
|
|
@@ -1455,7 +1459,7 @@ yyreduce:
|
|
1455
1459
|
}
|
1456
1460
|
|
1457
1461
|
/* Line 1126 of yacc.c. */
|
1458
|
-
#line
|
1462
|
+
#line 1463 "y.tab.c"
|
1459
1463
|
|
1460
1464
|
yyvsp -= yylen;
|
1461
1465
|
yyssp -= yylen;
|
@@ -1723,7 +1727,7 @@ yyreturn:
|
|
1723
1727
|
}
|
1724
1728
|
|
1725
1729
|
|
1726
|
-
#line
|
1730
|
+
#line 150 "src/query_parser/q_parser.y"
|
1727
1731
|
|
1728
1732
|
|
1729
1733
|
const char *special_char = "&:()[]{}!+\"~^-|<>=*?";
|
data/lib/ferret.rb
CHANGED
@@ -11,7 +11,7 @@ module Ferret
|
|
11
11
|
|
12
12
|
class QueryParser < Racc::Parser
|
13
13
|
|
14
|
-
module_eval <<'..end lib/ferret/query_parser/query_parser.y modeval..
|
14
|
+
module_eval <<'..end lib/ferret/query_parser/query_parser.y modeval..id07e7308361', 'lib/ferret/query_parser/query_parser.y', 126
|
15
15
|
attr_accessor :default_field, :fields, :handle_parse_errors
|
16
16
|
|
17
17
|
def initialize(default_field = "*", options = {})
|
@@ -323,7 +323,7 @@ module_eval <<'..end lib/ferret/query_parser/query_parser.y modeval..id155b60f3f
|
|
323
323
|
end
|
324
324
|
|
325
325
|
def add_and_clause(clauses, clause)
|
326
|
-
clauses.compact!
|
326
|
+
(clauses||=[]).compact!
|
327
327
|
if (clauses.length == 1)
|
328
328
|
last_cl = clauses[0]
|
329
329
|
last_cl.occur = BooleanClause::Occur::MUST if not last_cl.prohibited?
|
@@ -379,7 +379,7 @@ module_eval <<'..end lib/ferret/query_parser/query_parser.y modeval..id155b60f3f
|
|
379
379
|
q = yield(field)
|
380
380
|
bq << BooleanClause.new(q) if q
|
381
381
|
end
|
382
|
-
return bq
|
382
|
+
return (bq.clauses.size == 0) ? nil : bq
|
383
383
|
end
|
384
384
|
end
|
385
385
|
|
@@ -398,7 +398,7 @@ module_eval <<'..end lib/ferret/query_parser/query_parser.y modeval..id155b60f3f
|
|
398
398
|
return qp.parse(query)
|
399
399
|
end
|
400
400
|
|
401
|
-
..end lib/ferret/query_parser/query_parser.y modeval..
|
401
|
+
..end lib/ferret/query_parser/query_parser.y modeval..id07e7308361
|
402
402
|
|
403
403
|
##### racc 1.4.4 generates ###
|
404
404
|
|
data/lib/rferret.rb
CHANGED
data/test/unit/index/tc_index.rb
CHANGED
@@ -624,4 +624,30 @@ class IndexTest < Test::Unit::TestCase
|
|
624
624
|
index.flush
|
625
625
|
index.close
|
626
626
|
end
|
627
|
+
|
628
|
+
def test_stopwords
|
629
|
+
i = Ferret::Index::Index.new(
|
630
|
+
:occur_default => Ferret::Search::BooleanClause::Occur::MUST,
|
631
|
+
:default_search_field => '*')
|
632
|
+
d = Ferret::Document::Document.new
|
633
|
+
|
634
|
+
# adding this additional field to the document leads to failure below
|
635
|
+
# comment out this statement and all tests pass:
|
636
|
+
d << Ferret::Document::Field.new('id', '1',
|
637
|
+
Ferret::Document::Field::Store::YES,
|
638
|
+
Ferret::Document::Field::Index::UNTOKENIZED)
|
639
|
+
|
640
|
+
d << Ferret::Document::Field.new('content', 'Move or shake',
|
641
|
+
Ferret::Document::Field::Store::NO,
|
642
|
+
Ferret::Document::Field::Index::TOKENIZED,
|
643
|
+
Ferret::Document::Field::TermVector::NO,
|
644
|
+
false, 1.0)
|
645
|
+
i << d
|
646
|
+
hits = i.search 'move nothere shake'
|
647
|
+
assert_equal 0, hits.size
|
648
|
+
hits = i.search 'move shake'
|
649
|
+
assert_equal 1, hits.size
|
650
|
+
hits = i.search 'move or shake'
|
651
|
+
assert_equal 1, hits.size # fails when id field is present
|
652
|
+
end
|
627
653
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ferret
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
7
|
-
date: 2006-08-
|
6
|
+
version: 0.9.6
|
7
|
+
date: 2006-08-23 00:00:00 +09:00
|
8
8
|
summary: Ruby indexing library.
|
9
9
|
require_paths:
|
10
10
|
- lib
|