Removed livcode ranking
[idzebra-moved-to-github.git] / test / api / t10.c
1 /* $Id: t10.c,v 1.1 2004-10-28 10:37:15 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 <yaz/log.h>
26 #include <yaz/pquery.h>
27 #include <idzebra/api.h>
28 #include "testlib.h"
29 #include "rankingrecords.h"
30
31 #define qry(zh,query,hits,string,score) \
32     RankingQuery(__LINE__,(zh),(query),(hits),(string),(score))
33
34 struct tst {
35     char *schema;
36     char *hit1;
37     int score1;
38     char *hit2;
39     int score2;
40     char *hit3;
41     int score3;
42 };
43
44
45
46 struct tst tests[] = {
47     {"ntc-atn", "first title", 1000, "first title", 1000, "third title", 826 },
48     {"ntc-ntn", "first title", 1000, "first title", 1000, "third title", 826 },
49     {"ntc-btn", "first title", 1000, "first title", 1000, "third title", 826 },
50     {"ntc-apn", "first title", 1000, "first title", 1000, "third title", 826 },
51     {"ntc-npn", "first title", 1000, "first title", 1000, "third title", 826 },
52     {"ntc-bpn", "first title", 1000, "first title", 1000, "third title", 826 },
53
54     {"atc-atn", "first title", 1000, "first title", 1000, "first title", 972 },
55     {"atc-ntn", "first title", 1000, "first title", 1000, "first title", 972 },
56     {"atc-btn", "first title", 1000, "first title", 1000, "first title", 972 },
57     {"atc-apn", "first title", 1000, "first title", 1000, "first title", 972 },
58     {"atc-npn", "first title", 1000, "first title", 1000, "first title", 972 },
59     {"atc-bpn", "first title", 1000, "first title", 1000, "first title", 972 },
60
61     {"npc-atn", "first title", 1000, "first title", 1000, "third title", 826 },
62     {"npc-ntn", "first title", 1000, "first title", 1000, "third title", 826 },
63     {"npc-btn", "first title", 1000, "first title", 1000, "third title", 826 },
64     {"npc-apn", "first title", 1000, "first title", 1000, "third title", 826 },
65     {"npc-npn", "first title", 1000, "first title", 1000, "third title", 826 },
66     {"npc-bpn", "first title", 1000, "first title", 1000, "third title", 826 },
67
68     {"apc-atn", "first title", 1000, "first title", 1000, "first title", 972 },
69     {"apc-ntn", "first title", 1000, "first title", 1000, "first title", 972 },
70     {"apc-btn", "first title", 1000, "first title", 1000, "first title", 972 },
71     {"apc-apn", "first title", 1000, "first title", 1000, "first title", 972 },
72     {"apc-npn", "first title", 1000, "first title", 1000, "first title", 972 },
73     {"apc-bpn", "first title", 1000, "first title", 1000, "first title", 972 },
74
75     {0,0,0,0,0,0,0},
76 };
77
78 int main(int argc, char **argv)
79 {
80     int i;
81     char *addinfo;
82     ZebraService zs;
83     ZebraHandle zh;
84
85     yaz_log_init_file("t10.log");
86     /* yaz_log_init_level(LOG_ALL);  */
87
88     nmem_init ();
89     
90     zs = start_service("zebrazv.cfg"); 
91     zh = zebra_open (zs);
92     zebra_select_database(zh, "Default");
93     logf(LOG_LOG,"going to call init");
94     i=zebra_init(zh);
95     logf(LOG_LOG,"init returned %d",i);
96     if (i) {
97         printf("init failed with %d\n",i);
98         zebra_result(zh, &i, &addinfo);
99         printf("  Error %d   %s\n",i,addinfo);
100         exit(1);
101     }
102
103     zebra_begin_trans (zh, 1);
104     for (i = 0; recs[i]; i++)
105         zebra_add_record (zh, recs[i], strlen(recs[i]));
106     zebra_end_trans (zh);
107     zebra_commit (zh);
108   
109     // yaz_log_init_level(LOG_ALL); 
110
111     zebra_close(zh);
112
113
114     for (i=0; tests[i].schema; i++)
115     {
116         zh = zebra_open (zs);
117         zebra_select_database(zh, "Default");
118         zebra_set_resource(zh, "zvrank.weighting-scheme", tests[i].schema);
119         logf(LOG_LOG,"============%d: %s ============", i,tests[i].schema);
120
121         RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 the",
122                 3, tests[i].hit1, tests[i].score1);
123         RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or foo bar",
124                 3, tests[i].hit2, tests[i].score2);
125         RankingQuery( __LINE__, zh, 
126                 "@attr 1=1016 @attr 2=102 @or @or the foo bar",
127                 3, tests[i].hit3, tests[i].score3);
128
129         zebra_close(zh);
130     }
131     
132     zebra_stop (zs);
133
134     nmem_exit ();
135     xmalloc_trav ("x");
136     logf(LOG_LOG,"============ ALL TESTS PASSED OK ============");
137     exit (0);
138 }