Query* QParser_Parse_IMP(QueryParser *self, String *query_string) { String *qstring = query_string ? Str_Clone(query_string) : Str_new_from_trusted_utf8("", 0); Query *tree = QParser_Tree(self, qstring); Query *expanded = QParser_Expand(self, tree); Query *pruned = QParser_Prune(self, expanded); DECREF(expanded); DECREF(tree); DECREF(qstring); return pruned; }
void TestQPLogic_run_tests() { u32_t i; TestBatch *batch = Test_new_batch("TestQueryParserLogic", 178, NULL); Folder *folder = S_create_index(); Searcher *searcher = Searcher_new((Obj*)folder); QueryParser *or_parser = QParser_new(Searcher_Get_Schema(searcher), NULL, NULL, NULL); static ZombieCharBuf AND = ZCB_LITERAL("AND"); QueryParser *and_parser = QParser_new(Searcher_Get_Schema(searcher), NULL, (CharBuf*)&AND, NULL); QParser_Set_Heed_Colons(or_parser, true); QParser_Set_Heed_Colons(and_parser, true); PLAN(batch); /* Run logical tests with default boolop of OR. */ for (i = 0; logical_test_funcs[i] != NULL; i++) { kino_TestQPLogic_logical_test_t test_func = logical_test_funcs[i]; TestQueryParser *test_case = test_func(BOOLOP_OR); Query *tree = QParser_Tree(or_parser, test_case->query_string); Query *parsed = QParser_Parse(or_parser, test_case->query_string); Hits *hits = Searcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL); ASSERT_TRUE(batch, Query_Equals(tree, (Obj*)test_case->tree), "tree() OR %s", test_case->query_string->ptr); ASSERT_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits, "hits: OR %s", test_case->query_string->ptr); DECREF(hits); DECREF(parsed); DECREF(tree); DECREF(test_case); } /* Run logical tests with default boolop of AND. */ for (i = 0; logical_test_funcs[i] != NULL; i++) { kino_TestQPLogic_logical_test_t test_func = logical_test_funcs[i]; TestQueryParser *test_case = test_func(BOOLOP_AND); Query *tree = QParser_Tree(and_parser, test_case->query_string); Query *parsed = QParser_Parse(and_parser, test_case->query_string); Hits *hits = Searcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL); ASSERT_TRUE(batch, Query_Equals(tree, (Obj*)test_case->tree), "tree() AND %s", test_case->query_string->ptr); ASSERT_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits, "hits: AND %s", test_case->query_string->ptr); DECREF(hits); DECREF(parsed); DECREF(tree); DECREF(test_case); } /* Run tests for QParser_Prune(). */ for (i = 0; prune_test_funcs[i] != NULL; i++) { kino_TestQPLogic_prune_test_t test_func = prune_test_funcs[i]; TestQueryParser *test_case = test_func(); CharBuf *qstring = test_case->tree ? Obj_To_String(test_case->tree) : CB_new_from_trusted_utf8("(NULL)", 6); Query *tree = test_case->tree; Query *wanted = test_case->expanded; Query *pruned = QParser_Prune(or_parser, tree); Query *expanded; Hits *hits; ASSERT_TRUE(batch, Query_Equals(pruned, (Obj*)wanted), "prune() %s", qstring->ptr); expanded = QParser_Expand(or_parser, pruned); hits = Searcher_Hits(searcher, (Obj*)expanded, 0, 10, NULL); ASSERT_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits, "hits: %s", qstring->ptr); DECREF(hits); DECREF(expanded); DECREF(pruned); DECREF(qstring); DECREF(test_case); } DECREF(and_parser); DECREF(or_parser); DECREF(searcher); DECREF(folder); batch->destroy(batch); }
void TestQPLogic_Run_IMP(TestQueryParserLogic *self, TestBatchRunner *runner) { TestBatchRunner_Plan(runner, (TestBatch*)self, 258); uint32_t i; Folder *folder = S_create_index(); IndexSearcher *searcher = IxSearcher_new((Obj*)folder); QueryParser *or_parser = QParser_new(IxSearcher_Get_Schema(searcher), NULL, NULL, NULL); String *AND = SSTR_WRAP_C("AND"); QueryParser *and_parser = QParser_new(IxSearcher_Get_Schema(searcher), NULL, AND, NULL); QParser_Set_Heed_Colons(or_parser, true); QParser_Set_Heed_Colons(and_parser, true); // Run logical tests with default boolop of OR. for (i = 0; logical_test_funcs[i] != NULL; i++) { LUCY_TestQPLogic_Logical_Test_t test_func = logical_test_funcs[i]; TestQueryParser *test_case_obj = test_func(BOOLOP_OR); TestQueryParserIVARS *test_case = TestQP_IVARS(test_case_obj); Query *tree = QParser_Tree(or_parser, test_case->query_string); Query *parsed = QParser_Parse(or_parser, test_case->query_string); Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL); char *qstr = Str_To_Utf8(test_case->query_string); TEST_TRUE(runner, Query_Equals(tree, (Obj*)test_case->tree), "tree() OR %s", qstr); TEST_INT_EQ(runner, Hits_Total_Hits(hits), test_case->num_hits, "hits: OR %s", qstr); free(qstr); DECREF(hits); DECREF(parsed); DECREF(tree); DECREF(test_case_obj); } // Run logical tests with default boolop of AND. for (i = 0; logical_test_funcs[i] != NULL; i++) { LUCY_TestQPLogic_Logical_Test_t test_func = logical_test_funcs[i]; TestQueryParser *test_case_obj = test_func(BOOLOP_AND); TestQueryParserIVARS *test_case = TestQP_IVARS(test_case_obj); Query *tree = QParser_Tree(and_parser, test_case->query_string); Query *parsed = QParser_Parse(and_parser, test_case->query_string); Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL); char *qstr = Str_To_Utf8(test_case->query_string); TEST_TRUE(runner, Query_Equals(tree, (Obj*)test_case->tree), "tree() AND %s", qstr); TEST_INT_EQ(runner, Hits_Total_Hits(hits), test_case->num_hits, "hits: AND %s", qstr); free(qstr); DECREF(hits); DECREF(parsed); DECREF(tree); DECREF(test_case_obj); } // Run tests for QParser_Prune(). for (i = 0; prune_test_funcs[i] != NULL; i++) { LUCY_TestQPLogic_Prune_Test_t test_func = prune_test_funcs[i]; TestQueryParser *test_case_obj = test_func(); TestQueryParserIVARS *test_case = TestQP_IVARS(test_case_obj); String *qstring = test_case->tree ? Query_To_String(test_case->tree) : Str_new_from_trusted_utf8("(NULL)", 6); char *qstr = Str_To_Utf8(qstring); Query *tree = test_case->tree; Query *wanted = test_case->expanded; Query *pruned = QParser_Prune(or_parser, tree); Query *expanded; Hits *hits; TEST_TRUE(runner, Query_Equals(pruned, (Obj*)wanted), "prune() %s", qstr); expanded = QParser_Expand(or_parser, pruned); hits = IxSearcher_Hits(searcher, (Obj*)expanded, 0, 10, NULL); TEST_INT_EQ(runner, Hits_Total_Hits(hits), test_case->num_hits, "hits: %s", qstr); free(qstr); DECREF(hits); DECREF(expanded); DECREF(pruned); DECREF(qstring); DECREF(test_case_obj); } DECREF(and_parser); DECREF(or_parser); DECREF(searcher); DECREF(folder); }
void TestQPLogic_run_tests() { uint32_t i; TestBatch *batch = TestBatch_new(258); Folder *folder = S_create_index(); IndexSearcher *searcher = IxSearcher_new((Obj*)folder); QueryParser *or_parser = QParser_new(IxSearcher_Get_Schema(searcher), NULL, NULL, NULL); ZombieCharBuf *AND = ZCB_WRAP_STR("AND", 3); QueryParser *and_parser = QParser_new(IxSearcher_Get_Schema(searcher), NULL, (CharBuf*)AND, NULL); QParser_Set_Heed_Colons(or_parser, true); QParser_Set_Heed_Colons(and_parser, true); TestBatch_Plan(batch); // Run logical tests with default boolop of OR. for (i = 0; logical_test_funcs[i] != NULL; i++) { Lucy_TestQPLogic_Logical_Test_t test_func = logical_test_funcs[i]; TestQueryParser *test_case = test_func(BOOLOP_OR); Query *tree = QParser_Tree(or_parser, test_case->query_string); Query *parsed = QParser_Parse(or_parser, test_case->query_string); Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL); TEST_TRUE(batch, Query_Equals(tree, (Obj*)test_case->tree), "tree() OR %s", (char*)CB_Get_Ptr8(test_case->query_string)); TEST_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits, "hits: OR %s", (char*)CB_Get_Ptr8(test_case->query_string)); DECREF(hits); DECREF(parsed); DECREF(tree); DECREF(test_case); } // Run logical tests with default boolop of AND. for (i = 0; logical_test_funcs[i] != NULL; i++) { Lucy_TestQPLogic_Logical_Test_t test_func = logical_test_funcs[i]; TestQueryParser *test_case = test_func(BOOLOP_AND); Query *tree = QParser_Tree(and_parser, test_case->query_string); Query *parsed = QParser_Parse(and_parser, test_case->query_string); Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL); TEST_TRUE(batch, Query_Equals(tree, (Obj*)test_case->tree), "tree() AND %s", (char*)CB_Get_Ptr8(test_case->query_string)); TEST_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits, "hits: AND %s", (char*)CB_Get_Ptr8(test_case->query_string)); DECREF(hits); DECREF(parsed); DECREF(tree); DECREF(test_case); } // Run tests for QParser_Prune(). for (i = 0; prune_test_funcs[i] != NULL; i++) { Lucy_TestQPLogic_Prune_Test_t test_func = prune_test_funcs[i]; TestQueryParser *test_case = test_func(); CharBuf *qstring = test_case->tree ? Query_To_String(test_case->tree) : CB_new_from_trusted_utf8("(NULL)", 6); Query *tree = test_case->tree; Query *wanted = test_case->expanded; Query *pruned = QParser_Prune(or_parser, tree); Query *expanded; Hits *hits; TEST_TRUE(batch, Query_Equals(pruned, (Obj*)wanted), "prune() %s", (char*)CB_Get_Ptr8(qstring)); expanded = QParser_Expand(or_parser, pruned); hits = IxSearcher_Hits(searcher, (Obj*)expanded, 0, 10, NULL); TEST_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits, "hits: %s", (char*)CB_Get_Ptr8(qstring)); DECREF(hits); DECREF(expanded); DECREF(pruned); DECREF(qstring); DECREF(test_case); } DECREF(and_parser); DECREF(or_parser); DECREF(searcher); DECREF(folder); DECREF(batch); }