Changeset 8d89448795e517f0f1afd9bb633dc677fde09712

Show
Ignore:
Timestamp:
04/29/08 20:45:14 (8 months ago)
Author:
David Balmain <dbalmain@…>
Parents:
2ac444617a25eb599de0faec801ffa532425f554
Children:
76d73d55aa0ba896da711c5ed3d0e2b3e236ef3e
git-committer:
David Balmain <dbalmain@gmail.com> / 2008-04-29T20:45:14Z+1000
Message:

Full gcov test coverage for TermQuery?

Location:
c
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • c/src/q_term.c

    r0c11a5 r8d8944  
    147147    TermQuery *tq = TQ(self->query); 
    148148    TermDocEnum *tde = ir_term_docs_for(ir, tq->field, tq->term); 
    149     if (!tde) { 
    150         return NULL; 
    151     } 
     149    /* ir_term_docs_for should always return a TermDocEnum */ 
     150    assert(NULL != tde); 
    152151 
    153152    return tsc_new(self, tde, ir_get_norms(ir, tq->field)); 
  • c/test/test_search.c

    r2ac444 r8d8944  
    168168    {"20051003", "word1 word3 one two", 
    169169        "cat1/sub2",            "3999"}, 
    170     {"20051004", "word1 word2", 
     170    /* we have 33 * "word2" below to cause cache miss in TermQuery */ 
     171    {"20051004", "word1 word2 word2 word2 word2 word2 word2 word2 word2 " 
     172                 "word2 word2 word2 word2 word2 word2 word2 word2 word2 " 
     173                 "word2 word2 word2 word2 word2 word2 word2 word2 word2 " 
     174                 "word2 word2 word2 word2 word2 word2 word2", 
    171175        "cat1/sub2/subsub2",    "+.3413"}, 
    172176    {"20051005", "word1 one two x x x x x one two", 
     
    331335static void test_term_query(TestCase *tc, void *data) 
    332336{ 
     337    MatchVector *mv; 
     338    HashSet *hs; 
    333339    Searcher *searcher = (Searcher *)data; 
    334340    TopDocs *top_docs; 
     341    Weight *w; 
     342    char *t, e[100]; 
    335343    Query *tq = tq_new(field, "word2"); 
    336344    check_to_s(tc, tq, field, "word2"); 
     
    340348    check_to_s(tc, tq, field, "word2^100.0"); 
    341349    check_to_s(tc, tq, NULL, "field:word2^100.0"); 
     350 
     351    /* test PhraseWeight.to_s */ 
     352    w = searcher->create_weight(searcher, tq); 
     353    sprintf(e, "TermWeight(%f)", w->value); 
     354    t = w->to_s(w); Asnequal(e, t, 17); free(t); 
     355    tq->boost = 10.5f; 
     356    sprintf(e, "TermWeight(%f)", w->value); 
     357    t = w->to_s(w); Asnequal(e, t, 17); free(t); 
     358    w->destroy(w); 
     359 
    342360    q_deref(tq); 
    343361 
     
    369387    Aiequal(SEARCH_DOCS_SIZE - 10, top_docs->size); 
    370388    td_destroy(top_docs); 
     389    q_deref(tq); 
     390 
     391    tq = tq_new(field, "quick"); 
     392    /* test get_matchv_i */ 
     393    check_hits(tc, searcher, tq, "1,11,14,16,17", -1); 
     394    mv = searcher_get_match_vector(searcher, tq, 1, field); 
     395    if (Aiequal(2, mv->size)) { 
     396        Aiequal(3, mv->matches[0].start); 
     397        Aiequal(3, mv->matches[0].end); 
     398        Aiequal(7, mv->matches[1].start); 
     399        Aiequal(7, mv->matches[1].end); 
     400    } 
     401    matchv_destroy(mv); 
     402 
     403    /* test extract_terms */ 
     404    hs = hs_new((hash_ft)&term_hash, (eq_ft)&term_eq, (free_ft)&term_destroy); 
     405    tq->extract_terms(tq, hs); 
     406    Aiequal(1, hs->size); 
     407    Asequal("quick", ((Term *)hs->first->elem)->text); 
     408    Apequal(field, ((Term *)hs->first->elem)->field); 
     409    hs_destroy(hs); 
    371410    q_deref(tq); 
    372411}