Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: kinosearch: commits

r3824 - in trunk: c_src/KinoSearch/Test perl/lib/KinoSearch/Test perl/t

 

 

kinosearch commits RSS feed   Index | Next | Previous | View Threaded


marvin at rectangular

Sep 6, 2008, 9:34 AM

Post #1 of 1 (978 views)
Permalink
r3824 - in trunk: c_src/KinoSearch/Test perl/lib/KinoSearch/Test perl/t

Author: creamyg
Date: 2008-09-06 09:34:10 -0700 (Sat, 06 Sep 2008)
New Revision: 3824

Modified:
trunk/c_src/KinoSearch/Test/TestQueryParserLogic.bp
trunk/c_src/KinoSearch/Test/TestQueryParserLogic.c
trunk/perl/lib/KinoSearch/Test/TestQueryParserLogic.pm
trunk/perl/t/610-queryparser_logic.t
Log:
Run QueryParserLogic tests from C.


Modified: trunk/c_src/KinoSearch/Test/TestQueryParserLogic.bp
===================================================================
--- trunk/c_src/KinoSearch/Test/TestQueryParserLogic.bp 2008-09-06 12:34:02 UTC (rev 3823)
+++ trunk/c_src/KinoSearch/Test/TestQueryParserLogic.bp 2008-09-06 16:34:10 UTC (rev 3824)
@@ -4,11 +4,8 @@
*/

static class KinoSearch::Test::TestQueryParserLogic cnick TestQPLogic {
- static incremented VArray*
- logical_tests(const CharBuf *boolop);
-
- static incremented VArray*
- prune_tests();
+ static void
+ run_tests(InvIndex *invindex);
}

/* Copyright 2005-2008 Marvin Humphrey

Modified: trunk/c_src/KinoSearch/Test/TestQueryParserLogic.c
===================================================================
--- trunk/c_src/KinoSearch/Test/TestQueryParserLogic.c 2008-09-06 12:34:02 UTC (rev 3823)
+++ trunk/c_src/KinoSearch/Test/TestQueryParserLogic.c 2008-09-06 16:34:10 UTC (rev 3824)
@@ -2,8 +2,15 @@
#include <stdarg.h>
#include <string.h>

+#define CHAZ_USE_SHORT_NAMES
+#include "Charmonizer/Test.h"
+
#include "KinoSearch/Test/TestQueryParserLogic.h"
#include "KinoSearch/Test/TestQueryParser.h"
+#include "KinoSearch/InvIndex.h"
+#include "KinoSearch/QueryParser.h"
+#include "KinoSearch/Searcher.h"
+#include "KinoSearch/Search/Hits.h"
#include "KinoSearch/Search/TermQuery.h"
#include "KinoSearch/Search/PhraseQuery.h"
#include "KinoSearch/Search/LeafQuery.h"
@@ -524,83 +531,155 @@

/***************************************************************************/

-VArray*
-TestQPLogic_logical_tests(const CharBuf *boolop)
+typedef TestQueryParser*
+(*kino_TestQPLogic_logical_test_t)(u32_t boolop_sym);
+
+static kino_TestQPLogic_logical_test_t logical_test_funcs[] = {
+ logical_test_empty_phrase,
+ logical_test_empty_parens,
+ logical_test_nested_empty_parens,
+ logical_test_nested_empty_phrase,
+ logical_test_simple_term,
+ logical_test_one_nested_term,
+ logical_test_one_term_phrase,
+ logical_test_two_terms,
+ logical_test_two_terms_nested,
+ logical_test_one_term_one_single_term_phrase,
+ logical_test_two_terms_one_nested,
+ logical_test_one_term_one_nested_phrase,
+ logical_test_phrase,
+ logical_test_nested_phrase,
+ logical_test_three_terms,
+ logical_test_three_terms_two_nested,
+ logical_test_one_term_one_phrase,
+ logical_test_one_term_one_nested_single_term_phrase,
+ logical_test_long_phrase,
+ logical_test_pure_negation,
+ logical_test_double_negative,
+ logical_test_triple_negative,
+ logical_test_nested_negations,
+ logical_test_two_terms_one_required,
+ logical_test_intersection,
+ logical_test_three_way_intersection,
+ logical_test_union,
+ logical_test_three_way_union,
+ logical_test_a_or_plus_b,
+ logical_test_and_not,
+ logical_test_nested_or,
+ logical_test_and_nested_or,
+ logical_test_or_nested_or,
+ logical_test_and_not_nested_or,
+ logical_test_required_phrase_negated_term,
+ logical_test_required_term_optional_phrase,
+ logical_test_nested_nest,
+ logical_test_field_phrase,
+ logical_test_field_bool_group,
+ logical_test_field_multi_OR,
+ logical_test_field_multi_AND,
+ NULL
+};
+
+typedef TestQueryParser*
+(*kino_TestQPLogic_prune_test_t)();
+
+static kino_TestQPLogic_prune_test_t prune_test_funcs[] = {
+ prune_test_null_querystring,
+ prune_test_matchall,
+ prune_test_nomatch,
+ prune_test_optional_not,
+ prune_test_reqopt_optional_not,
+ prune_test_reqopt_required_not,
+ prune_test_not_and_not,
+ NULL
+};
+
+
+static ZombieCharBuf AND = ZCB_LITERAL("AND");
+
+void
+TestQPLogic_run_tests(InvIndex *invindex)
{
- VArray *tests = VA_new(20);
- u32_t boolop_sym = CB_Equals_Str(boolop, "OR", 2)
- ? BOOLOP_OR
- : BOOLOP_AND;
u32_t i;
+ TestBatch *batch = Test_new_batch("TestQueryParserLogic", 178, NULL);
+ Searcher *searcher = Searcher_new(invindex, NULL);
+ QueryParser *or_parser = QParser_new(InvIndex_Get_Schema(invindex),
+ NULL, NULL, NULL);
+ QueryParser *and_parser = QParser_new(InvIndex_Get_Schema(invindex),
+ NULL, (CharBuf*)&AND, NULL);
+ QParser_Set_Heed_Colons(or_parser, true);
+ QParser_Set_Heed_Colons(and_parser, true);

- VA_Push(tests, (Obj*)logical_test_empty_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_empty_parens(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_nested_empty_parens(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_nested_empty_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_simple_term(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_one_nested_term(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_one_term_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_two_terms(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_two_terms_nested(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_one_term_one_single_term_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_two_terms_one_nested(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_one_term_one_nested_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_nested_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_three_terms(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_three_terms_two_nested(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_one_term_one_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_one_term_one_nested_single_term_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_long_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_pure_negation(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_double_negative(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_triple_negative(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_nested_negations(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_two_terms_one_required(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_intersection(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_three_way_intersection(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_union(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_three_way_union(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_a_or_plus_b(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_and_not(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_nested_or(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_and_nested_or(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_or_nested_or(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_and_not_nested_or(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_required_phrase_negated_term(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_required_term_optional_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_nested_nest(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_field_phrase(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_field_bool_group(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_field_multi_OR(boolop_sym));
- VA_Push(tests, (Obj*)logical_test_field_multi_AND(boolop_sym));
+ /* FIXME!! This is cheap substitute for plan(). */
+ printf("1..%u\n", batch->num_tests);

- for (i = 0; i < tests->size; i++) {
- Obj_Dec_RefCount(VA_Fetch(tests, i));
+ 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_Search(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);
+ REFCOUNT_DEC(tree);
+ REFCOUNT_DEC(parsed);
+ REFCOUNT_DEC(hits);
+ REFCOUNT_DEC(test_case);
}
- return tests;
-}

-VArray*
-TestQPLogic_prune_tests()
-{
- VArray *tests = VA_new(20);
- u32_t i;
+ 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_Search(searcher, (Obj*)parsed, 0, 10, NULL);

- VA_Push(tests, (Obj*)prune_test_null_querystring());
- VA_Push(tests, (Obj*)prune_test_matchall());
- VA_Push(tests, (Obj*)prune_test_nomatch());
- VA_Push(tests, (Obj*)prune_test_optional_not());
- VA_Push(tests, (Obj*)prune_test_reqopt_optional_not());
- VA_Push(tests, (Obj*)prune_test_reqopt_required_not());
- VA_Push(tests, (Obj*)prune_test_not_and_not());
+ 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);
+ REFCOUNT_DEC(tree);
+ REFCOUNT_DEC(parsed);
+ REFCOUNT_DEC(hits);
+ REFCOUNT_DEC(test_case);
+ }

- for (i = 0; i < tests->size; i++) {
- Obj_Dec_RefCount(VA_Fetch(tests, i));
+
+ 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_Search(searcher, (Obj*)expanded, 0, 10, NULL);
+ ASSERT_INT_EQ(batch, Hits_Total_Hits(hits), test_case->num_hits,
+ "hits: %s", qstring->ptr);
+
+ REFCOUNT_DEC(pruned);
+ REFCOUNT_DEC(expanded);
+ REFCOUNT_DEC(qstring);
+ REFCOUNT_DEC(hits);
+ REFCOUNT_DEC(test_case);
}
- return tests;
+
+ batch->destroy(batch);
+ REFCOUNT_DEC(searcher);
+ REFCOUNT_DEC(or_parser);
+ REFCOUNT_DEC(and_parser);
}
-
/* Copyright 2005-2008 Marvin Humphrey
*
* This program is free software; you can redistribute it and/or modify

Modified: trunk/perl/lib/KinoSearch/Test/TestQueryParserLogic.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Test/TestQueryParserLogic.pm 2008-09-06 12:34:02 UTC (rev 3823)
+++ trunk/perl/lib/KinoSearch/Test/TestQueryParserLogic.pm 2008-09-06 16:34:10 UTC (rev 3824)
@@ -1,16 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Test::TestQueryParserLogic;
-use KinoSearch::Util::ToolSet qw( to_perl );
-BEGIN {
- push our @ISA, 'Exporter';
- our @EXPORT_OK = qw( logical_tests prune_tests );
-}
-
-sub logical_tests { to_perl( _logical_tests(shift) ) }
-sub prune_tests { to_perl( _prune_tests() ) }
-
1;

__END__
@@ -19,19 +8,12 @@

MODULE = KinoSearch PACKAGE = KinoSearch::Test::TestQueryParserLogic

-SV*
-_logical_tests(boolop)
- kino_CharBuf boolop;
-CODE:
- KOBJ_TO_SV_NOINC( kino_TestQPLogic_logical_tests(&boolop), RETVAL );
-OUTPUT: RETVAL
+void
+run_tests(invindex)
+ kino_InvIndex *invindex;
+PPCODE:
+ kino_TestQPLogic_run_tests(invindex);

-SV*
-_prune_tests()
-CODE:
- KOBJ_TO_SV_NOINC( kino_TestQPLogic_prune_tests(), RETVAL );
-OUTPUT: RETVAL
-
__COPYRIGHT__

Copyright 2005-2008 Marvin Humphrey

Modified: trunk/perl/t/610-queryparser_logic.t
===================================================================
--- trunk/perl/t/610-queryparser_logic.t 2008-09-06 12:34:02 UTC (rev 3823)
+++ trunk/perl/t/610-queryparser_logic.t 2008-09-06 16:34:10 UTC (rev 3824)
@@ -3,57 +3,12 @@
use lib 'buildlib';

package main;
-use Test::More tests => 178;

-use KinoSearch::QueryParser;
-use KinoSearch::InvIndex;
-use KinoSearch::InvIndexer;
-use KinoSearch::Searcher;
-use KinoSearch::Store::RAMFolder;
use KinoSearch::Test::TestQueryParser qw( doc_set );
-use KinoSearch::Test::TestQueryParserLogic qw( logical_tests prune_tests );
+use KinoSearch::Test::TestQueryParserLogic;
use KinoTestUtils qw( create_invindex );
-use TestSchema;

my $invindex = create_invindex( @{ doc_set() } );
-my $schema = $invindex->get_schema;

-my $OR_parser = KinoSearch::QueryParser->new( schema => $schema, );
-my $AND_parser = KinoSearch::QueryParser->new(
- schema => $schema,
- default_boolop => 'AND',
-);
-$OR_parser->set_heed_colons(1);
-$AND_parser->set_heed_colons(1);
-my $searcher = KinoSearch::Searcher->new( invindex => $invindex );
+KinoSearch::Test::TestQueryParserLogic::run_tests($invindex);

-for my $boolop (qw( OR AND )) {
- my $qparser = $boolop eq 'OR' ? $OR_parser : $AND_parser;
- my $cases = logical_tests($boolop);
- for my $case (@$cases) {
- my $qstring = $case->get_query_string;
- my $tree = $qparser->tree($qstring);
- ok( $tree->equals( $case->get_tree ), "tree() $boolop: $qstring" );
-
- my $parsed = $qparser->parse($qstring);
- my $hits = $searcher->search( query => $parsed );
- is( $hits->total_hits, $case->get_num_hits,
- "hits $boolop: $qstring" );
- }
-}
-
-{
- my $qparser = $OR_parser;
- my $cases = prune_tests();
- for my $case (@$cases) {
- my $tree = $case->get_tree;
- my $string = defined($tree) ? $tree->to_string : '(undef)';
- my $wanted = $case->get_expanded;
- my $pruned = $qparser->prune($tree);
- ok( $pruned->equals($wanted), "prune(): $string" );
-
- my $expanded = $qparser->expand($pruned);
- my $hits = $searcher->search( query => $expanded );
- is( $hits->total_hits, $case->get_num_hits, "hits: $string" );
- }
-}


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits [at] rectangular
http://www.rectangular.com/mailman/listinfo/kinosearch-commits

kinosearch commits RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.