97b3c67db21670bcf6897ec990672a1aac166f5c
[idzebra-moved-to-github.git] / test / api / t10.c
1 /* $Id: t10.c,v 1.9 2005-09-13 11:51:07 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 #define qry(zh,query,hits,string,score) \
29     ranking_query(__LINE__,(zh),(query),(hits),(string),(score))
30
31 struct tst {
32     char *schema;
33     char *hit1;
34     int score1;
35     char *hit2;
36     int score2;
37     char *hit3;
38     int score3;
39 };
40
41
42
43 struct tst tests[] = {
44     {"ntc-atn", "first title", 0, "first title", 1000, "first title",1000 },
45     {"ntc-ntn", "first title", 0, "first title", 1000, "first title",1000 },
46     {"ntc-btn", "first title", 0, "first title", 1000, "first title",1000 },
47     {"ntc-apn", "first title", 0,    "first title", 1000, "first title",1000 },
48     {"ntc-npn", "first title", 0,    "first title", 1000, "first title",1000 },
49     {"ntc-bpn", "first title", 0,    "first title", 1000, "first title",1000 },
50     {"atc-atn", "first title", 0,    "first title", 1000, "first title", 1000 },
51     {"atc-ntn", "first title", 0,    "first title", 1000, "first title", 1000 },
52     {"atc-btn", "first title", 0,    "first title", 1000, "first title", 1000 },
53     {"atc-apn", "first title", 0,    "first title", 1000, "first title", 1000 },
54     {"atc-npn", "first title", 0,    "first title", 1000, "first title", 1000 },
55     {"atc-bpn", "first title", 0,    "first title", 1000, "first title", 1000 },
56
57     {"npc-atn", "first title", 0,    "first title", 1000, "first title", 1000 },
58     {"npc-ntn", "first title", 0,    "first title", 1000, "first title", 1000 },
59     {"npc-btn", "first title", 0,    "first title", 1000, "first title", 1000 },
60     {"npc-apn", "first title", 0,    "first title", 1000, "first title", 1000 },
61     {"npc-npn", "first title", 0,    "first title", 1000, "first title", 1000 },
62     {"npc-bpn", "first title", 0,    "first title", 1000, "first title", 1000 },
63
64     {"apc-atn", "first title", 0,    "first title", 1000, "first title", 1000 },
65     {"apc-ntn", "first title", 0,    "first title", 1000, "first title", 1000 },
66     {"apc-btn", "first title", 0,    "first title", 1000, "first title", 1000 },
67     {"apc-apn", "first title", 0,    "first title", 1000, "first title", 1000 },
68     {"apc-npn", "first title", 0,    "first title", 1000, "first title", 1000 },
69     {"apc-bpn", "first title", 0,    "first title", 1000, "first title", 1000 },
70     {0,0,0,0,0,0,0},
71 };
72
73 int main(int argc, char **argv)
74 {
75     int i;
76     ZebraService zs = start_up("zebrazv.cfg", argc, argv);
77     ZebraHandle zh = zebra_open(zs, 0);
78   
79     init_data(zh, recs);
80     zebra_close(zh);
81     for (i = 0; tests[i].schema; i++)
82     {
83         zh = zebra_open(zs, 0);
84         zebra_select_database(zh, "Default");
85         zebra_set_resource(zh, "zvrank.weighting-scheme", tests[i].schema);
86         yaz_log(YLOG_LOG,"============%d: %s ===========", i, tests[i].schema);
87
88         ranking_query( __LINE__, zh, "@attr 1=1016 @attr 2=102 the",
89                 3, tests[i].hit1, tests[i].score1);
90         ranking_query( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or foo bar",
91                 3, tests[i].hit2, tests[i].score2);
92         ranking_query( __LINE__, zh, 
93                 "@attr 1=1016 @attr 2=102 @or @or the foo bar",
94                 3, tests[i].hit3, tests[i].score3);
95
96         zebra_close(zh);
97     }
98     
99     return close_down(0,zs,0);
100 }