1 /* $Id: tst_index_types.c,v 1.3 2007-10-25 19:25:00 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <index_types.h>
30 " <indextype id=\"*:w:el\" position=\"1\" alwaysmatches=\"1\" firstinfield=\"1\"\n"
34 " <indextype id=\"*:w\" position=\"1\" alwaysmatches=\"1\" firstinfield=\"1\"\n"
38 " <indextype id=\"*:p\" position=\"0\" alwaysmatches=\"0\" firstinfield=\"0\"\n"
42 " <indextype id=\"*:s\" sort=\"1\" \n"
49 int compare_lookup(zebra_index_types_t r, const char *id,
50 const char *expected_id)
52 const char *got_id = zebra_index_type_lookup_str(r, id);
53 if (!got_id && !expected_id)
54 return 1; /* none expected */
56 if (got_id && expected_id && !strcmp(got_id, expected_id))
64 xmlDocPtr doc = xmlParseMemory(xml_str, strlen(xml_str));
69 zebra_index_types_t rules = zebra_index_types_create_doc(doc);
70 zebra_index_type_t type;
76 YAZ_CHECK(compare_lookup(rules, "title:s", "*:s"));
77 YAZ_CHECK(compare_lookup(rules, "title:sx", 0));
78 YAZ_CHECK(compare_lookup(rules, "title:Sx", 0));
79 YAZ_CHECK(compare_lookup(rules, "any:w", "*:w"));
80 YAZ_CHECK(compare_lookup(rules, "any:w:en", 0));
81 YAZ_CHECK(compare_lookup(rules, "any:w:el", "*:w:el"));
85 for (i = 0; i < iter; i++)
87 compare_lookup(rules, "title:s", "*:s");
88 compare_lookup(rules, "title:sx", 0);
89 compare_lookup(rules, "title:Sx", 0);
93 type = zebra_index_type_get(rules, "any:w");
97 const char *buf = " How are you?";
98 size_t len = strlen(buf);
103 const char *result_buf = 0;
104 size_t result_len = 0;
105 r = zebra_index_type_tokenize(type, buf, len,
106 &result_buf, &result_len);
108 YAZ_CHECK(result_len == 3 &&
109 !memcmp(result_buf, "how", result_len));
114 const char *result_buf = 0;
115 size_t result_len = 0;
116 r = zebra_index_type_tokenize(type, 0, 0,
117 &result_buf, &result_len);
119 YAZ_CHECK(result_len == 3 &&
120 !memcmp(result_buf, "are", result_len));
125 const char *result_buf = 0;
126 size_t result_len = 0;
127 r = zebra_index_type_tokenize(type, 0, 0,
128 &result_buf, &result_len);
130 YAZ_CHECK(result_len == 3 &&
131 !memcmp(result_buf, "you", result_len));
136 const char *result_buf = 0;
137 size_t result_len = 0;
138 r = zebra_index_type_tokenize(type, 0, 0,
139 &result_buf, &result_len);
143 zebra_index_types_destroy(rules);
146 zebra_index_types_t rules = zebra_index_types_create_doc(doc);
151 int main(int argc, char **argv)
153 YAZ_CHECK_INIT(argc, argv);
164 * indent-tabs-mode: nil
166 * vim: shiftwidth=4 tabstop=8 expandtab