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

Last change on this file since 9934 was 9926, checked in by davidb, 19 years ago

Introduction of Z39.50 Server code for Greenstone. Based on the work of
Chris Martin (2001 approx). Updated to work with newer version of YAZ
library.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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 if (strstr(GSQuery_char, "TargetInfo") != NULL) {
34 // should be one only
35 // real-life example:
36 /*
37 62
38 explain-category targetInfo
39 date-of-info Sep 22, 1999
40 language eng
41 */
42 ResultDocInfo_t docinfo;
43 docinfo.metadata["explain-category"].values.push_back("TargetInfo");
44 docinfo.metadata["name"].values.push_back("Greenstone");
45 docinfo.metadata["namedResultSets"].values.push_back("false");
46 docinfo.metadata["multipleDBsearch"].values.push_back("true");
47 docinfo.metadata["language"].values.push_back("eng");
48 response.docInfo.push_back(docinfo);
49 response.numDocs++;
50 }
51 if (strstr(GSQuery_char, "DatabaseInfo") != NULL) {
52 // should be one per collection
53 // real-life example:
54 /*
55 3
56 dbnum 0
57 explain-category DatabaseInfo
58 database-name.1 0
59 title Z39.50 EXPLAIN DB
60 database-name.2 ir-explain-1
61 date-of-info Sep 22, 1999
62 language eng
63 dbpath /usr/wald/z39.50root/explain
64 dbname explain
65 */
66 ResultDocInfo_t docinfo;
67 docinfo.metadata["explain-category"].values.push_back("DatabaseInfo");
68 docinfo.metadata["database-name"].values.push_back("IR-Explain-1");
69 docinfo.metadata["title"].values.push_back("Z39.50 EXPLAIN DB");
70 docinfo.metadata["language"].values.push_back("eng");
71 docinfo.metadata["dbname"].values.push_back("explain");
72 response.docInfo.push_back(docinfo);
73 response.numDocs++;
74 // now get the info for each collection
75 text_tarray collectlist;
76 Protocol->get_collection_list(collectlist, err, cerr);
77 text_tarray::iterator COLHERE = collectlist.begin();
78 text_tarray::iterator COLEND = collectlist.end();
79 while (COLHERE != COLEND) {
80 // don't include information for non-active collections
81 bool collection_active;
82 Protocol->ping(*COLHERE, collection_active, err, cerr);
83 if (collection_active != true) {
84 COLHERE++;
85 continue;
86 }
87 ColInfoResponse_t collectinfo;
88 Protocol->get_collectinfo(*COLHERE, collectinfo, err, cerr);
89 docinfo.clear();
90 docinfo.metadata["name"].values.push_back(collectinfo.shortInfo.name);
91 docinfo.metadata["host"].values.push_back(collectinfo.shortInfo.host);
92 if (collectinfo.isPublic) {
93 docinfo.metadata["isPublic"].values.push_back("true");
94 } else {
95 docinfo.metadata["isPublic"].values.push_back("false");
96 }
97 if (collectinfo.isBeta) {
98 docinfo.metadata["isBeta"].values.push_back("true");
99 } else {
100 docinfo.metadata["isBeta"].values.push_back("false");
101 }
102 docinfo.metadata["buildDate"].values.push_back(collectinfo.buildDate);
103 text_tarray::iterator TEXTT_HERE = collectinfo.ccsCols.begin();
104 text_tarray::iterator TEXTT_END = collectinfo.ccsCols.end();
105 for (int i = 1; TEXTT_HERE != TEXTT_END; i++, TEXTT_HERE++) {
106 text_t tmp = "ccsCols.";
107 tmp.appendint(i);
108 docinfo.metadata[tmp].values.push_back(*TEXTT_HERE);
109 }
110 TEXTT_HERE = collectinfo.languages.begin();
111 TEXTT_END = collectinfo.languages.end();
112 for (int i = 1; TEXTT_HERE != TEXTT_END; i++, TEXTT_HERE++) {
113 text_t tmp = "languages.";
114 tmp.appendint(i);
115 docinfo.metadata[tmp].values.push_back(*TEXTT_HERE);
116 }
117 docinfo.metadata["numDocs"].values.push_back(collectinfo.numDocs);
118 docinfo.metadata["numSections"].values.push_back(collectinfo.numSections);
119 docinfo.metadata["numWords"].values.push_back(collectinfo.numWords);
120 docinfo.metadata["numBytes"].values.push_back(collectinfo.numBytes);
121 text_tmap::iterator TEXTT_MAP_HERE = collectinfo.collectionmeta.begin();
122 text_tmap::iterator TEXTT_MAP_END = collectinfo.collectionmeta.end();
123 for (int i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
124 text_t tmp = "collectionmeta.";
125 tmp.appendint(i);
126 text_t tmp2 = TEXTT_MAP_HERE->first;
127 tmp2.appendcstr(" -> ");
128 tmp2.append(TEXTT_MAP_HERE->second);
129 docinfo.metadata[tmp].values.push_back(tmp2);
130 }
131 // uncomment if you want to include this in the explain record,
132 // it's a bit messy to include by default
133 /*
134 TEXTT_MAP_HERE = collectinfo.format.begin();
135 TEXTT_MAP_END = collectinfo.format.end();
136 for (int i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
137 text_t tmp = "format.";
138 tmp.appendint(i);
139 text_t tmp2 = TEXTT_MAP_HERE->first;
140 tmp2.appendcstr(" -> ");
141 tmp2.append(TEXTT_MAP_HERE->second);
142 docinfo.metadata[tmp].values.push_back(tmp2);
143 }
144 */
145 TEXTT_MAP_HERE = collectinfo.building.begin();
146 TEXTT_MAP_END = collectinfo.building.end();
147 for (int i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
148 text_t tmp = "building.";
149 tmp.appendint(i);
150 text_t tmp2 = TEXTT_MAP_HERE->first;
151 tmp2.appendcstr(" -> ");
152 tmp2.append(TEXTT_MAP_HERE->second);
153 docinfo.metadata[tmp].values.push_back(tmp2);
154 }
155 docinfo.metadata["receptionist"].values.push_back(collectinfo.receptionist);
156 docinfo.metadata["buildType"].values.push_back(collectinfo.buildType);
157 response.docInfo.push_back(docinfo);
158 response.numDocs++;
159 COLHERE++;
160 }
161 }
162 if (strstr(GSQuery_char, "SchemaInfo") != NULL) {
163 // should be one per collection
164 // real-life example:
165 /*
166 10
167 dbnum 1
168 explain-category schemaInfo
169 database-name.1 1
170 database-name.2 books
171 database-name.3 default
172 database-name.4 cat
173 date-of-info Sep 22, 1999
174 language eng
175 schema.1 1.2.840.10003.13.1000.3.1
176 dbpath /usr/wald/z39.50root/books
177 dbname books
178 */
179 }
180 if (strstr(GSQuery_char, "AttributeSetInfo") != NULL) {
181 // should be one per collection
182 // real-life example:
183 /*
184 9
185 dbnum 1
186 explain-category AttributeSetInfo
187 database-name.1 1
188 database-name.2 books
189 database-name.3 default
190 database-name.4 cat
191 date-of-info Sep 22, 1999
192 language eng
193 attribute-set.1 1.2.840.10003.13.1000.3.1
194 dbpath /usr/wald/z39.50root/books
195 dbname books
196 */
197 }
198}
199
200
Note: See TracBrowser for help on using the repository browser.