Exemple #1
0
static void
test_Dump_Load_and_Equals(TestBatch *batch)
{
    Query *a_leaf  = (Query*)TestUtils_make_leaf_query(NULL, "a");
    Query *b_leaf  = (Query*)TestUtils_make_leaf_query(NULL, "b");
    Query *c_leaf  = (Query*)TestUtils_make_leaf_query(NULL, "c");
    RequiredOptionalQuery *query = ReqOptQuery_new(a_leaf, b_leaf);
    RequiredOptionalQuery *kids_differ = ReqOptQuery_new(a_leaf, c_leaf);
    RequiredOptionalQuery *boost_differs = ReqOptQuery_new(a_leaf, b_leaf);
    Obj *dump = (Obj*)ReqOptQuery_Dump(query);
    RequiredOptionalQuery *clone 
        = (RequiredOptionalQuery*)Obj_Load(dump, dump);

    TEST_FALSE(batch, ReqOptQuery_Equals(query, (Obj*)kids_differ), 
        "Different kids spoil Equals");
    TEST_TRUE(batch, ReqOptQuery_Equals(query, (Obj*)boost_differs), 
        "Equals with identical boosts");
    ReqOptQuery_Set_Boost(boost_differs, 1.5);
    TEST_FALSE(batch, ReqOptQuery_Equals(query, (Obj*)boost_differs), 
        "Different boost spoils Equals");
    TEST_TRUE(batch, ReqOptQuery_Equals(query, (Obj*)clone), 
        "Dump => Load round trip");

    DECREF(a_leaf);
    DECREF(b_leaf);
    DECREF(c_leaf);
    DECREF(query);
    DECREF(kids_differ);
    DECREF(boost_differs);
    DECREF(dump);
    DECREF(clone);
}
Exemple #2
0
static TestQueryParser*
prune_test_reqopt_required_not() {
    Query   *a_leaf  = make_leaf_query(NULL, "a");
    Query   *b_leaf  = make_leaf_query(NULL, "b");
    Query   *not_a   = make_not_query(a_leaf);
    Query   *tree    = (Query*)ReqOptQuery_new(not_a, b_leaf);
    Query   *nomatch = (Query*)NoMatchQuery_new();
    Query   *pruned  = (Query*)ReqOptQuery_new(nomatch, b_leaf);
    DECREF(nomatch);
    DECREF(not_a);
    DECREF(b_leaf);
    return TestQP_new(NULL, tree, pruned, 0);
}
Exemple #3
0
static TestQueryParser*
prune_test_reqopt_optional_not() {
    Query   *a_leaf  = make_leaf_query(NULL, "a");
    Query   *b_leaf  = make_leaf_query(NULL, "b");
    Query   *not_b   = make_not_query(b_leaf);
    Query   *tree    = (Query*)ReqOptQuery_new(a_leaf, not_b);
    Query   *nomatch = (Query*)NoMatchQuery_new();
    Query   *pruned  = (Query*)ReqOptQuery_new(a_leaf, nomatch);
    DECREF(nomatch);
    DECREF(not_b);
    DECREF(a_leaf);
    return TestQP_new(NULL, tree, pruned, 4);
}
Exemple #4
0
static TestQueryParser*
logical_test_two_terms_one_required(uint32_t boolop) {
    Query   *a_query = make_leaf_query(NULL, "a");
    Query   *b_query = make_leaf_query(NULL, "b");
    Query   *tree;
    if (boolop == BOOLOP_AND) {
        tree = make_poly_query(boolop, a_query, b_query, NULL);
    }
    else {
        tree = (Query*)ReqOptQuery_new(b_query, a_query);
        DECREF(b_query);
        DECREF(a_query);
    }
    return TestQP_new("a +b", tree, NULL, 3);
}
Exemple #5
0
static TestQueryParser*
logical_test_required_term_optional_phrase(uint32_t boolop) {
    Query *ab_query   = make_leaf_query(NULL, "\"a b\"");
    Query *d_query    = make_leaf_query(NULL, "d");
    Query *tree;
    if (boolop == BOOLOP_AND) {
        tree = make_poly_query(BOOLOP_AND, ab_query, d_query, NULL);
    }
    else {
        tree = (Query*)ReqOptQuery_new(d_query, ab_query);
        DECREF(d_query);
        DECREF(ab_query);
    }
    UNUSED_VAR(boolop);
    return TestQP_new("\"a b\" +d", tree, NULL, 1);
}
Exemple #6
0
Query*
QParser_Make_Req_Opt_Query_IMP(QueryParser *self, Query *required_query,
                               Query *optional_query) {
    UNUSED_VAR(self);
    return (Query*)ReqOptQuery_new(required_query, optional_query);
}