static TestQueryParser* syntax_test_minus_minus() { /* Not a perfect result, but then it's not a good query string. */ Query *tree = make_leaf_query(NULL, "a"); return TestQP_new("--a", tree, NULL, 4); }
static TestQueryParser* leaf_test_unescape_colons() { Query *tree = make_leaf_query("plain", "a\\:b"); Query *expanded = make_term_query("plain", "a:b"); return TestQP_new("plain:a\\:b", tree, expanded, 0); }
static TestQueryParser* syntax_test_minus_plus() { Query *leaf = make_leaf_query(NULL, "a"); Query *tree = make_not_query(leaf); return TestQP_new("-+a", tree, NULL, 0); }
static TestQueryParser* logical_test_one_nested_term(u32_t boolop) { Query *leaf = make_leaf_query(NULL, "a"); Query *tree = make_poly_query(boolop, leaf, NULL); return TestQP_new("(a)", tree, NULL, 4); }
static TestQueryParser* logical_test_one_term_phrase(u32_t boolop) { Query *tree = make_leaf_query(NULL, "\"a\""); UNUSED_VAR(boolop); return TestQP_new("\"a\"", tree, NULL, 4); }
static TestQueryParser* logical_test_simple_term(u32_t boolop) { Query *tree = make_leaf_query(NULL, "b"); UNUSED_VAR(boolop); return TestQP_new("b", tree, NULL, 3); }
static TestQueryParser* logical_test_nested_empty_phrase(u32_t boolop) { Query *leaf = make_leaf_query(NULL, "\"\""); Query *tree = make_poly_query(boolop, leaf, NULL); return TestQP_new("(\"\")", tree, NULL, 0); }
static TestQueryParser* logical_test_field_phrase(u32_t boolop) { Query *tree = make_leaf_query("content", "\"b c\""); UNUSED_VAR(boolop); return TestQP_new("content:\"b c\"", tree, NULL, 2); }
static TestQueryParser* logical_test_pure_negation(uint32_t boolop) { Query *leaf = make_leaf_query(NULL, "x"); Query *tree = make_not_query(leaf); UNUSED_VAR(boolop); return TestQP_new("-x", tree, NULL, 0); }
static TestQueryParser* logical_test_triple_negative(uint32_t boolop) { Query *leaf = make_leaf_query(NULL, "a"); Query *tree = make_not_query(leaf); UNUSED_VAR(boolop); return TestQP_new("---a", tree, NULL, 0); }
static TestQueryParser* logical_test_double_negative(u32_t boolop) { Query *tree = make_leaf_query(NULL, "a"); UNUSED_VAR(boolop); return TestQP_new("--a", tree, NULL, 4); }
static TestQueryParser* leaf_test_field() { Query *tree = make_leaf_query("plain", "b"); Query *expanded = make_term_query("plain", "b"); return TestQP_new("plain:b", tree, expanded, 3); }
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); }
static TestQueryParser* leaf_test_unrecognized_field() { Query *tree = make_leaf_query("bogusfield", "b"); Query *expanded = make_term_query("bogusfield", "b"); return TestQP_new("bogusfield:b", tree, expanded, 0); }
static TestQueryParser* syntax_test_not_plus() { // Not a perfect result, but then it's not a good query string. Query *leaf = make_leaf_query(NULL, "a"); Query *tree = make_not_query(leaf); return TestQP_new("NOT +a", tree, NULL, 0); }
static TestQueryParser* logical_test_two_terms_one_required(u32_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); }
static TestQueryParser* leaf_test_simple_term() { Query *tree = make_leaf_query(NULL, "a"); Query *plain_q = make_term_query("plain", "a"); Query *fancy_q = make_term_query("fancy", "a"); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new("a", tree, expanded, 4); }
static TestQueryParser* leaf_test_phrase_with_stopwords() { Query *tree = make_leaf_query(NULL, "\"x a\""); Query *plain_q = make_phrase_query("plain", "x", "a", NULL); Query *fancy_q = make_phrase_query("fancy", "a", NULL); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new("\"x a\"", tree, expanded, 4); }
static TestQueryParser* leaf_test_empty_phrase() { Query *tree = make_leaf_query(NULL, "\"\""); Query *plain_q = make_phrase_query("plain", NULL); Query *fancy_q = make_phrase_query("fancy", NULL); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new("\"\"", tree, expanded, 0); }
static TestQueryParser* leaf_test_escaped_quotes_outside() { Query *tree = make_leaf_query(NULL, "\\\"a"); Query *plain_q = make_term_query("plain", "\"a"); Query *fancy_q = make_term_query("fancy", "a"); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new("\\\"a", tree, expanded, 4); }
static TestQueryParser* leaf_test_unclosed_quote() { Query *tree = make_leaf_query(NULL, "\"a b"); Query *plain_q = make_phrase_query("plain", "a", "b", NULL); Query *fancy_q = make_phrase_query("fancy", "a", "b", NULL); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new("\"a b", tree, expanded, 3); }
static TestQueryParser* leaf_test_different_tokenization() { Query *tree = make_leaf_query(NULL, "a.b"); Query *plain_q = make_term_query("plain", "a.b"); Query *fancy_q = make_phrase_query("fancy", "a", "b", NULL); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new("a.b", tree, expanded, 3); }
// Technically, this should produce an acceptably small result set, but it's // too difficult to prune -- so QParser_Prune just lops it because it's a // top-level NOTQuery. static TestQueryParser* logical_test_nested_negations(uint32_t boolop) { Query *query = make_leaf_query(NULL, "a"); query = make_poly_query(boolop, query, NULL); query = make_not_query(query); query = make_poly_query(BOOLOP_AND, query, NULL); query = make_not_query(query); return TestQP_new("-(-(a))", query, NULL, 0); }
static TestQueryParser* leaf_test_http() { char address[] = "http://www.foo.com/bar.html"; Query *tree = make_leaf_query(NULL, address); Query *plain_q = make_term_query("plain", address); Query *fancy_q = make_phrase_query("fancy", "http", "www", "foo", "com", "bar", "html", NULL); Query *expanded = make_poly_query(BOOLOP_OR, fancy_q, plain_q, NULL); return TestQP_new(address, tree, expanded, 0); }
static TestQueryParser* syntax_test_escaped_quotes_inside() { Query *tree = make_leaf_query(NULL, "\"\\\"a\\\"\""); return TestQP_new("\"\\\"a\\\"\"", tree, NULL, 4); }
static TestQueryParser* syntax_test_not_minus() { Query *tree = make_leaf_query(NULL, "a"); return TestQP_new("NOT -a", tree, NULL, 4); }
static TestQueryParser* syntax_test_unmatched_parens() { Query *tree = make_leaf_query(NULL, "a"); return TestQP_new(")a)", tree, NULL, 4); }
static TestQueryParser* syntax_test_identifier_field_name() { // Field names must be identifiers, i.e. they cannot start with a number. Query *tree = make_leaf_query(NULL, "10:30"); return TestQP_new("10:30", tree, NULL, 0); }
static TestQueryParser* logical_test_empty_phrase(uint32_t boolop) { Query *tree = make_leaf_query(NULL, "\"\""); UNUSED_VAR(boolop); return TestQP_new("\"\"", tree, NULL, 0); }
static TestQueryParser* syntax_test_double_colon() { Query *tree = make_leaf_query(NULL, "PHP::Interpreter"); return TestQP_new("PHP::Interpreter", tree, NULL, 0); }