source: trunk/gsdl/src/colservr/z3950explain.cpp@ 12276

Last change on this file since 12276 was 10437, checked in by kjdon, 19 years ago

declared int i outside the for loop to get it to compile under windows

  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/**********************************************************************
2 *
3 * z3950explain.cpp --
4 * Copyright (C) 2000 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "z3950explain.h"
27
28void getExplainInfo(bend_search_rr *rr, FilterResponse_t &response, comerror_t &err)
29{
30 text_t GSQuery = ZQueryToGSQuery(rr);
31 char *GSQuery_char = GSQuery.getcstr();
32
33 int i;
34 if (strstr(GSQuery_char, "TargetInfo") != NULL) {
35 // should be one only
36 // real-life example:
37 /*
38 62
39 explain-category targetInfo
40 date-of-info Sep 22, 1999
41 language eng
42 */
43 ResultDocInfo_t docinfo;
44 docinfo.metadata["explain-category"].values.push_back("TargetInfo");
45 docinfo.metadata["name"].values.push_back("Greenstone");
46 docinfo.metadata["namedResultSets"].values.push_back("false");
47 docinfo.metadata["multipleDBsearch"].values.push_back("true");
48 docinfo.metadata["language"].values.push_back("eng");
49 response.docInfo.push_back(docinfo);
50 response.numDocs++;
51 }
52 if (strstr(GSQuery_char, "DatabaseInfo") != NULL) {
53 // should be one per collection
54 // real-life example:
55 /*
56 3
57 dbnum 0
58 explain-category DatabaseInfo
59 database-name.1 0
60 title Z39.50 EXPLAIN DB
61 database-name.2 ir-explain-1
62 date-of-info Sep 22, 1999
63 language eng
64 dbpath /usr/wald/z39.50root/explain
65 dbname explain
66 */
67 ResultDocInfo_t docinfo;
68 docinfo.metadata["explain-category"].values.push_back("DatabaseInfo");
69 docinfo.metadata["database-name"].values.push_back("IR-Explain-1");
70 docinfo.metadata["title"].values.push_back("Z39.50 EXPLAIN DB");
71 docinfo.metadata["language"].values.push_back("eng");
72 docinfo.metadata["dbname"].values.push_back("explain");
73 response.docInfo.push_back(docinfo);
74 response.numDocs++;
75 // now get the info for each collection
76 text_tarray collectlist;
77 Protocol->get_collection_list(collectlist, err, cerr);
78 text_tarray::iterator COLHERE = collectlist.begin();
79 text_tarray::iterator COLEND = collectlist.end();
80 while (COLHERE != COLEND) {
81 // don't include information for non-active collections
82 bool collection_active;
83 Protocol->ping(*COLHERE, collection_active, err, cerr);
84 if (collection_active != true) {
85 COLHERE++;
86 continue;
87 }
88 ColInfoResponse_t collectinfo;
89 Protocol->get_collectinfo(*COLHERE, collectinfo, err, cerr);
90 docinfo.clear();
91 docinfo.metadata["name"].values.push_back(collectinfo.shortInfo.name);
92 docinfo.metadata["host"].values.push_back(collectinfo.shortInfo.host);
93 if (collectinfo.isPublic) {
94 docinfo.metadata["isPublic"].values.push_back("true");
95 } else {
96 docinfo.metadata["isPublic"].values.push_back("false");
97 }
98 if (collectinfo.isBeta) {
99 docinfo.metadata["isBeta"].values.push_back("true");
100 } else {
101 docinfo.metadata["isBeta"].values.push_back("false");
102 }
103 docinfo.metadata["buildDate"].values.push_back(collectinfo.buildDate);
104 text_tarray::iterator TEXTT_HERE = collectinfo.ccsCols.begin();
105 text_tarray::iterator TEXTT_END = collectinfo.ccsCols.end();
106 for (i = 1; TEXTT_HERE != TEXTT_END; i++, TEXTT_HERE++) {
107 text_t tmp = "ccsCols.";
108 tmp.appendint(i);
109 docinfo.metadata[tmp].values.push_back(*TEXTT_HERE);
110 }
111 TEXTT_HERE = collectinfo.languages.begin();
112 TEXTT_END = collectinfo.languages.end();
113 for (i = 1; TEXTT_HERE != TEXTT_END; i++, TEXTT_HERE++) {
114 text_t tmp = "languages.";
115 tmp.appendint(i);
116 docinfo.metadata[tmp].values.push_back(*TEXTT_HERE);
117 }
118 docinfo.metadata["numDocs"].values.push_back(collectinfo.numDocs);
119 docinfo.metadata["numSections"].values.push_back(collectinfo.numSections);
120 docinfo.metadata["numWords"].values.push_back(collectinfo.numWords);
121 docinfo.metadata["numBytes"].values.push_back(collectinfo.numBytes);
122
123 collectionmeta_map::iterator COLLMETA_MAP_HERE = collectinfo.collectionmeta.begin();
124 collectionmeta_map::iterator COLLMETA_MAP_END = collectinfo.collectionmeta.end();
125 for (i = 1; COLLMETA_MAP_HERE != COLLMETA_MAP_END; i++, COLLMETA_MAP_HERE++) {
126 text_t tmp = "collectionmeta.";
127 tmp.appendint(i);
128 text_t tmp2 = COLLMETA_MAP_HERE->first;
129 tmp2.appendcstr(" -> ");
130 tmp2.append(COLLMETA_MAP_HERE->second[g_EmptyText]);
131 docinfo.metadata[tmp].values.push_back(tmp2);
132 }
133 text_tmap::iterator TEXTT_MAP_HERE;
134 text_tmap::iterator TEXTT_MAP_END;
135 // uncomment if you want to include this in the explain record,
136 // it's a bit messy to include by default
137 /*
138 TEXTT_MAP_HERE = collectinfo.format.begin();
139 TEXTT_MAP_END = collectinfo.format.end();
140 for (i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
141 text_t tmp = "format.";
142 tmp.appendint(i);
143 text_t tmp2 = TEXTT_MAP_HERE->first;
144 tmp2.appendcstr(" -> ");
145 tmp2.append(TEXTT_MAP_HERE->second);
146 docinfo.metadata[tmp].values.push_back(tmp2);
147 }
148 */
149 TEXTT_MAP_HERE = collectinfo.building.begin();
150 TEXTT_MAP_END = collectinfo.building.end();
151 for (i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
152 text_t tmp = "building.";
153 tmp.appendint(i);
154 text_t tmp2 = TEXTT_MAP_HERE->first;
155 tmp2.appendcstr(" -> ");
156 tmp2.append(TEXTT_MAP_HERE->second);
157 docinfo.metadata[tmp].values.push_back(tmp2);
158 }
159 docinfo.metadata["receptionist"].values.push_back(collectinfo.receptionist);
160 docinfo.metadata["buildType"].values.push_back(collectinfo.buildType);
161 response.docInfo.push_back(docinfo);
162 response.numDocs++;
163 COLHERE++;
164 }
165 }
166 if (strstr(GSQuery_char, "SchemaInfo") != NULL) {
167 // should be one per collection
168 // real-life example:
169 /*
170 10
171 dbnum 1
172 explain-category schemaInfo
173 database-name.1 1
174 database-name.2 books
175 database-name.3 default
176 database-name.4 cat
177 date-of-info Sep 22, 1999
178 language eng
179 schema.1 1.2.840.10003.13.1000.3.1
180 dbpath /usr/wald/z39.50root/books
181 dbname books
182 */
183 }
184 if (strstr(GSQuery_char, "AttributeSetInfo") != NULL) {
185 // should be one per collection
186 // real-life example:
187 /*
188 9
189 dbnum 1
190 explain-category AttributeSetInfo
191 database-name.1 1
192 database-name.2 books
193 database-name.3 default
194 database-name.4 cat
195 date-of-info Sep 22, 1999
196 language eng
197 attribute-set.1 1.2.840.10003.13.1000.3.1
198 dbpath /usr/wald/z39.50root/books
199 dbname books
200 */
201 }
202}
203
204
Note: See TracBrowser for help on using the repository browser.