Changeset 2111 for libswish3/trunk/src/xapian
- Timestamp:
- 04/06/08 23:29:45 (9 months ago)
- Files:
-
- libswish3/trunk/src/xapian/swish_xapian.cpp (modified) (8 diffs)
- libswish3/trunk/src/xapian/test.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/xapian/swish_xapian.cpp
r2108 r2111 67 67 char *dbpath 68 68 ); 69 int do_search(69 int search( 70 70 char *query 71 71 ); … … 75 75 static Xapian::WritableDatabase wdb; 76 76 static Xapian::Database::Database rdb; 77 static Xapian::Stem stemmer("english"); 77 static Xapian::Stem stemmer("english"); // TODO make this configurable 78 78 static Xapian::TermGenerator indexer; 79 79 static int twords = 0; … … 216 216 (swish_MetaName *)swish_hash_fetch(config->metanames, metaname); 217 217 prefix = int_to_string(meta->id); 218 return prefix; 218 return prefix + string((const char*)":"); 219 } 220 221 static void 222 add_prefix( 223 swish_MetaName *meta, 224 Xapian::QueryParser qp, 225 xmlChar *name 226 ) 227 { 228 qp.add_prefix(string((const char*)name), 229 int_to_string(meta->id) + string((const char*)":")); 219 230 } 220 231 … … 449 460 450 461 int 451 do_search( 452 char *query 453 ) 454 { 455 462 search( 463 char *qstr 464 ) 465 { 466 int total_matches; 467 Xapian::Enquire *enquire; 468 Xapian::Query query; 469 Xapian::QueryParser qparser; 470 Xapian::MSet mset; 471 Xapian::MSetIterator iterator; 472 Xapian::Document doc; 473 474 total_matches = 0; 475 qparser.set_stemmer(stemmer); // TODO make this configurable 476 qparser.set_database(rdb); 477 478 // map all human metanames to internal prefix 479 xmlHashScan(s3->config->metanames, (xmlHashScanner)add_prefix, &qparser); 480 481 // TODO boolean_prefix? 482 483 try { 484 query = qparser.parse_query(string(qstr)); 485 } 486 catch (Xapian::QueryParserError &e) { 487 SWISH_CROAK("query parser error: %s", e.get_msg().c_str()); 488 } 489 490 enquire = new Xapian::Enquire(rdb); 491 enquire->set_query(query); 492 mset = enquire->get_mset(0, 100); 493 iterator = mset.begin(); 494 for ( ; iterator != mset.end(); ++iterator) { 495 doc = iterator.get_document(); 496 printf("ID %d %d%%\n[\n%s\n]\n", 497 iterator.operator*(), iterator.get_percent(), doc.get_data().c_str()); 498 total_matches++; 499 } 500 printf("%d total matches\n", total_matches); 456 501 } 457 502 … … 535 580 case 'q': 536 581 query = (char *)swish_xstrdup((xmlChar *)optarg); 582 break; 537 583 538 584 case '?': … … 554 600 die with no args 555 601 */ 556 if ( !i || i >= argc) {602 if ((!i || i >= argc) && !query) { 557 603 swish_free_swish3(s3); 558 604 usage(); … … 568 614 } 569 615 616 // indexing mode 570 617 if (!query) { 571 // indexing mode618 572 619 open_writeable_index(dbpath); 573 620 … … 604 651 else { 605 652 open_readable_index(dbpath); 606 do_search(query); 653 search(query); 654 swish_xfree(BAD_CAST query); 607 655 } 608 656 libswish3/trunk/src/xapian/test.pl
r2090 r2111 2 2 3 3 use Carp; 4 use Test::More tests => 3;4 use Test::More tests => 4; 5 5 6 ok( run(''), 'usage' ); 6 ok( run(''), 'usage' ); 7 8 # indexing 7 9 ok( run(' ../test_docs/*xml'), 'index xml' ); 8 10 ok( run(' ../test_docs/*html'), 'index html' ); 11 12 # searching 13 ok( ( grep {m/2 total matches/} run(' --query swishtitle:foobar') ), 14 'search swishtitle:foobar' ); 9 15 10 16 sub run {
