6e5323767444c8ad9aeeb10e6f8874812a199d05
[idzebra-moved-to-github.git] / test / api / t10.c
1 /* $Id: t10.c,v 1.10 2006-03-31 15:58:05 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /** t10.c - test zv-rank */
24
25 #include "testlib.h"
26 #include "rankingrecords.h"
27
28 struct tst {
29     char *schema;
30     char *hit1;
31     int score1;
32     char *hit2;
33     int score2;
34     char *hit3;
35     int score3;
36 };
37
38 struct tst tests[] = {
39     {"ntc-atn", "first title", 0, "first title", 1000, "first title",1000 },
40     {"ntc-ntn", "first title", 0, "first title", 1000, "first title",1000 },
41     {"ntc-btn", "first title", 0, "first title", 1000, "first title",1000 },
42     {"ntc-apn", "first title", 0,    "first title", 1000, "first title",1000 },
43     {"ntc-npn", "first title", 0,    "first title", 1000, "first title",1000 },
44     {"ntc-bpn", "first title", 0,    "first title", 1000, "first title",1000 },
45     {"atc-atn", "first title", 0,    "first title", 1000, "first title", 1000 },
46     {"atc-ntn", "first title", 0,    "first title", 1000, "first title", 1000 },
47     {"atc-btn", "first title", 0,    "first title", 1000, "first title", 1000 },
48     {"atc-apn", "first title", 0,    "first title", 1000, "first title", 1000 },
49     {"atc-npn", "first title", 0,    "first title", 1000, "first title", 1000 },
50     {"atc-bpn", "first title", 0,    "first title", 1000, "first title", 1000 },
51
52     {"npc-atn", "first title", 0,    "first title", 1000, "first title", 1000 },
53     {"npc-ntn", "first title", 0,    "first title", 1000, "first title", 1000 },
54     {"npc-btn", "first title", 0,    "first title", 1000, "first title", 1000 },
55     {"npc-apn", "first title", 0,    "first title", 1000, "first title", 1000 },
56     {"npc-npn", "first title", 0,    "first title", 1000, "first title", 1000 },
57     {"npc-bpn", "first title", 0,    "first title", 1000, "first title", 1000 },
58
59     {"apc-atn", "first title", 0,    "first title", 1000, "first title", 1000 },
60     {"apc-ntn", "first title", 0,    "first title", 1000, "first title", 1000 },
61     {"apc-btn", "first title", 0,    "first title", 1000, "first title", 1000 },
62     {"apc-apn", "first title", 0,    "first title", 1000, "first title", 1000 },
63     {"apc-npn", "first title", 0,    "first title", 1000, "first title", 1000 },
64     {"apc-bpn", "first title", 0,    "first title", 1000, "first title", 1000 },
65     {0,0,0,0,0,0,0},
66 };
67
68 static void tst(int argc, char **argv)
69 {
70     int i;
71     ZebraService zs = tl_start_up("zebrazv.cfg", argc, argv);
72     ZebraHandle zh = zebra_open(zs, 0);
73   
74     YAZ_CHECK(tl_init_data(zh, recs));
75     zebra_close(zh);
76     for (i = 0; tests[i].schema; i++)
77     {
78         zh = zebra_open(zs, 0);
79         YAZ_CHECK(zh);
80         YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
81
82         zebra_set_resource(zh, "zvrank.weighting-scheme", tests[i].schema);
83         yaz_log(YLOG_LOG,"============%d: %s ===========", i, tests[i].schema);
84
85         YAZ_CHECK(tl_ranking_query(zh, "@attr 1=1016 @attr 2=102 the",
86                                    3, tests[i].hit1, tests[i].score1));
87         YAZ_CHECK(tl_ranking_query(zh, "@attr 1=1016 @attr 2=102 @or foo bar",
88                                    3, tests[i].hit2, tests[i].score2));
89         YAZ_CHECK(tl_ranking_query(zh, 
90                                    "@attr 1=1016 @attr 2=102 @or @or the foo bar",
91                                    3, tests[i].hit3, tests[i].score3));
92         zebra_close(zh);
93     }
94     YAZ_CHECK(tl_close_down(0, zs));
95 }
96
97 TL_MAIN