Changeset 2ac444617a25eb599de0faec801ffa532425f554
- Timestamp:
- 04/28/08 14:54:33 (8 months ago)
- Parents:
- 88af924cc987bc50098df966cc16b84e4213a7fe
- Children:
- 8d89448795e517f0f1afd9bb633dc677fde09712
- git-committer:
- David Balmain <dbalmain@gmail.com> / 2008-04-28T14:54:33Z+1000
- Files:
-
- 6 modified
-
c/.rake/gcov.history (modified) (previous)
-
c/src/index.c (modified) (1 diff)
-
c/src/q_phrase.c (modified) (1 diff)
-
c/src/search.c (modified) (3 diffs)
-
c/test/test_search.c (modified) (7 diffs)
-
ruby/ext/r_search.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
c/src/index.c
ra23445 r2ac444 5580 5580 while (NULL != (tk = ts->next(ts))) { 5581 5581 pos += tk->pos_inc; 5582 /* if for some reason pos gets set to some number less 5583 * than 0 the we'll start pos at 0 */ 5584 if (pos < 0) { 5585 pos = 0; 5586 } 5582 5587 dw_add_posting(mp, curr_plists, fld_plists, doc_num, 5583 5588 tk->text, tk->len, pos); -
c/src/q_phrase.c
r7b6066 r2ac444 778 778 if (tv_term) { 779 779 TVPosEnum *tvpe = tvpe_new(tv_term->positions, tv_term->freq, 0); 780 if (tvpe_next(tvpe)) { 781 pq_push(tvpe_pq, tvpe); 782 total_positions += tv_term->freq; 783 } 784 else { 785 free(tvpe); 786 } 780 /* got tv_term so tvpe_next should always return true once here */ 781 assert(tvpe_next(tvpe)); 782 pq_push(tvpe_pq, tvpe); 783 total_positions += tv_term->freq; 787 784 } 788 785 } -
c/src/search.c
r7b6066 r2ac444 540 540 } 541 541 self->matches[self->size].start = start; 542 self->matches[self->size].end = end; 543 self->matches[self->size++].score = 1.0; 542 self->matches[self->size].end = end; 543 self->matches[self->size].score = 1.0; 544 self->size++; 544 545 return self; 545 546 } … … 1523 1524 Query *rewritten_query = self->rewrite(self, query); 1524 1525 /* terms get copied directly to df_map so no need to free here */ 1525 HashSet *terms = frt_hs_new((hash_ft)&frt_term_hash,1526 (eq_ft)&frt_term_eq,1527 (free_ft)NULL);1526 HashSet *terms = hs_new((hash_ft)&term_hash, 1527 (eq_ft)&term_eq, 1528 (free_ft)NULL); 1528 1529 HashSetEntry *hse; 1529 1530 … … 1801 1802 int i = msea_get_searcher_index(self, doc_num); 1802 1803 Searcher *s = msea->searchers[i]; 1803 return s->get_term_vector(s, doc_num - msea->starts[i], 1804 field); 1804 return s->get_term_vector(s, doc_num - msea->starts[i], field); 1805 1805 } 1806 1806 -
c/test/test_search.c
r7b6066 r2ac444 202 202 IndexWriter *iw; 203 203 204 FieldInfos *fis = fis_new(STORE_YES, INDEX_YES, TERM_VECTOR_YES); 204 FieldInfos *fis = fis_new(STORE_YES, 205 INDEX_YES, 206 TERM_VECTOR_WITH_POSITIONS_OFFSETS); 205 207 index_create(store, fis); 206 208 fis_deref(fis); … … 514 516 static void test_phrase_query(TestCase *tc, void *data) 515 517 { 518 MatchVector *mv; 516 519 Searcher *searcher = (Searcher *)data; 520 Explanation *explanation; 517 521 Query *q; 518 522 Query *phq = phq_new(field); … … 597 601 phq_add_term(phq, "quick", 1); 598 602 check_hits(tc, searcher, phq, "", -1); 603 explanation = searcher->explain(searcher, phq, 0); 604 Afequal(0.0, explanation->value); 605 expl_destroy(explanation); 599 606 q_deref(phq); 600 607 601 /* test single term case, query is rewritten to TermQuery */608 /* test single-term case, query is rewritten to TermQuery */ 602 609 phq = phq_new(field); 603 610 phq_add_term(phq, "word2", 1); … … 605 612 q = searcher_rewrite(searcher, phq); 606 613 Aiequal(q->type, TERM_QUERY); 614 q_deref(q); 615 616 /* test single-position/multi-term query is rewritten as MultiTermQuery */ 617 phq_append_multi_term(phq, "word3"); 618 check_hits(tc, searcher, phq, "1,2,3,4,6,8,11,14", -1); 619 q = searcher_rewrite(searcher, phq); 620 Aiequal(q->type, MULTI_TERM_QUERY); 621 q_deref(q); 622 623 /* check boost doesn't break anything */; 624 phq_add_term(phq, "one", 1); /* make sure it won't be rewritten */ 625 phq->boost = 10.0; 626 check_hits(tc, searcher, phq, "2,3", -1); 607 627 q_deref(phq); 608 q_deref(q); 628 629 /* test get_matchv_i */ 630 phq = phq_new(field); 631 phq_add_term(phq, "quick", 0); 632 phq_add_term(phq, "brown", 1); 633 check_hits(tc, searcher, phq, "1", -1); 634 mv = searcher_get_match_vector(searcher, phq, 1, field); 635 if (Aiequal(2, mv->size)) { 636 Aiequal(3, mv->matches[0].start); 637 Aiequal(4, mv->matches[0].end); 638 Aiequal(7, mv->matches[1].start); 639 Aiequal(8, mv->matches[1].end); 640 } 641 matchv_destroy(mv); 642 phq_set_slop(phq, 4); 643 check_hits(tc, searcher, phq, "1,16,17", -1); 644 mv = searcher_get_match_vector(searcher, phq, 1, field); 645 if (Aiequal(2, mv->size)) { 646 Aiequal(3, mv->matches[0].start); 647 Aiequal(4, mv->matches[0].end); 648 Aiequal(7, mv->matches[1].start); 649 Aiequal(8, mv->matches[1].end); 650 } 651 matchv_destroy(mv); 652 mv = searcher_get_match_vector(searcher, phq, 16, field); 653 if (Aiequal(1, mv->size)) { 654 Aiequal(2, mv->matches[0].start); 655 Aiequal(5, mv->matches[0].end); 656 } 657 matchv_destroy(mv); 658 phq_add_term(phq, "chicken", 1); 659 check_hits(tc, searcher, phq, "", -1); 660 mv = searcher_get_match_vector(searcher, phq, 16, field); 661 Aiequal(0, mv->size); 662 matchv_destroy(mv); 663 q_deref(phq); 609 664 } 610 665 … … 666 721 Searcher *searcher = (Searcher *)data; 667 722 Query *phq, *q; 723 MatchVector *mv; 668 724 669 725 phq = phq_new(field); 670 phq_add_term(phq, "quick", 0); 726 /* ok to use append_multi_term to start */ 727 phq_append_multi_term(phq, "quick"); 671 728 phq_append_multi_term(phq, "fast"); 672 729 check_hits(tc, searcher, phq, "1, 8, 11, 14, 16, 17", -1); … … 731 788 q_deref(q); 732 789 790 /* test get_matchv_i */ 791 phq = phq_new(field); 792 phq_add_term(phq, "quick", 0); 793 phq_add_term(phq, "brown", 1); 794 phq_append_multi_term(phq, "dirty"); 795 phq_append_multi_term(phq, "red"); 796 check_hits(tc, searcher, phq, "1,11", -1); 797 mv = searcher_get_match_vector(searcher, phq, 1, field); 798 if (Aiequal(2, mv->size)) { 799 Aiequal(3, mv->matches[0].start); 800 Aiequal(4, mv->matches[0].end); 801 Aiequal(7, mv->matches[1].start); 802 Aiequal(8, mv->matches[1].end); 803 } 804 matchv_destroy(mv); 805 phq_set_slop(phq, 1); 806 check_hits(tc, searcher, phq, "1,11,17", -1); 807 mv = searcher_get_match_vector(searcher, phq, 1, field); 808 if (Aiequal(2, mv->size)) { 809 Aiequal(3, mv->matches[0].start); 810 Aiequal(4, mv->matches[0].end); 811 Aiequal(7, mv->matches[1].start); 812 Aiequal(8, mv->matches[1].end); 813 } 814 matchv_destroy(mv); 815 mv = searcher_get_match_vector(searcher, phq, 17, field); 816 if (Aiequal(1, mv->size)) { 817 Aiequal(5, mv->matches[0].start); 818 Aiequal(7, mv->matches[0].end); 819 } 820 matchv_destroy(mv); 821 phq_add_term(phq, "chicken", 1); 822 phq_append_multi_term(phq, "turtle"); 823 check_hits(tc, searcher, phq, "", -1); 824 mv = searcher_get_match_vector(searcher, phq, 17, field); 825 Aiequal(0, mv->size); 826 matchv_destroy(mv); 827 q_deref(phq); 733 828 } 734 829 … … 1406 1501 int i; 1407 1502 IndexWriter *iw; 1408 FieldInfos *fis = fis_new(STORE_YES, INDEX_YES, TERM_VECTOR_YES); 1503 FieldInfos *fis = fis_new(STORE_YES, 1504 INDEX_YES, 1505 TERM_VECTOR_WITH_POSITIONS_OFFSETS); 1409 1506 index_create(store, fis); 1410 1507 fis_deref(fis); -
ruby/ext/r_search.c
r0c11a5 r2ac444 494 494 { 495 495 VALUE rterms = rb_ary_new(); 496 HashSet *terms = term_set_new(); 496 HashSet *terms = hs_new((hash_ft)&term_hash, 497 (eq_ft)&term_eq, 498 (free_ft)term_destroy); 497 499 HashSetEntry *hse; 498 500 GET_Q();
