Changeset 1342 for branches/z3950-branch/gsdl/src/recpt/z3950server.cpp
- Timestamp:
- 2000-08-03T14:49:41+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/z3950-branch/gsdl/src/recpt/z3950server.cpp
r1191 r1342 18 18 // for now, assume that all records will have text associated with them. 19 19 meta["hastxt"]="1"; 20 // for now, assume we don't want ANY DocumentButtons. 21 format["DocumentButtons"]=""; 20 22 } 21 23 … … 74 76 } 75 77 76 text_tarray *z3950_server::getbriefrecords(const text_t &query, 78 void z3950_server::parseQuery(const text_t &query, 79 const text_t &fields, 80 text_t &parsed_query) { 81 /****** FIXME *****/ 82 // We need to format the query string into RPN - 83 // by just passing it like this, it will only work for simple queries. 84 // This will require us to actually come up with a query syntax and 85 // a parser. For now, we'll just do an "AND" query for all terms 86 87 // we need to count number of terms separated by a space 88 char *ptr=query.getcstr(); 89 int strlength=strlen(ptr); 90 bool inword=false; 91 int num_terms=0; 92 for (int i=0;i<strlength;i++) { 93 if (*(ptr+i)!=' ') { 94 if (inword==false) { 95 inword=true; 96 num_terms++; 97 } 98 } 99 else { // ptr+i is a space 100 inword=false; 101 } 102 } 103 104 // set the field(s) to search on - main ones (that I've found) include: 105 // 1016 => Any 106 // 1 => (Personal) Name 107 // 4 => Title 108 // 21 => Subject Heading 109 // 45 => Subject precis 110 // Note I have no idea how these actually work - I think some servers 111 // only have limited fields, and map all subject-type requests into that 112 // subject field, etc. 113 114 parsed_query="@attr 1="; 115 if (fields==".author") 116 parsed_query+="1 "; 117 else if (fields==".title") 118 parsed_query+="4 "; 119 else // fields==".any" 120 parsed_query+="1016 "; 121 122 // append "@and" for each term after the first 123 for (int i=1;i<num_terms;i++) 124 parsed_query+="@and "; 125 // append the actual query 126 parsed_query+=query; 127 128 } 129 130 text_tarray *z3950_server::getrecordTitles(const text_t &query, 131 const text_t &fields, 77 132 int first, int count, 78 133 int *nummatches, comerror_t &err) { … … 83 138 titles=new text_tarray; 84 139 140 /* check if connected */ 85 141 if (connected==false) 86 142 if (connect()==false) { … … 91 147 92 148 93 // We need to format the query string into RPN - 94 // by just passing it like this, it will only work for simple queries. 95 /* check if connected */ 96 /* titles->push_back("first dummy title"); 97 titles->push_back("Second dummy title"); 98 return titles; 99 */ 149 text_t expanded_query=""; 150 parseQuery(query,fields,expanded_query); 151 100 152 // following functions defined in yaz_zclient.c 101 *nummatches=z_cmd_dosearch(query.getcstr()); // returns # found, -1 on err. 102 // could just check if (*nummatches)==0. 103 153 *nummatches=z_cmd_dosearch(expanded_query.getcstr()); // returns # found, -1 on err. 154 if (*nummatches<=0) { 155 if (*nummatches==0) { 156 // no matches 157 return (NULL); 158 } else if (*nummatches==-1) { 159 // prefix query error 160 err=protocolError; 161 return (NULL); 162 } else if (*nummatches==-2) { 163 // sendsearchRequest not answered by searchResponse 164 err=protocolError; 165 return (NULL); 166 } 167 } 104 168 // could do a sort eventually, eg on date, title, etc. 105 169 // (non-existent function) z_sort(field, asc|desc); 106 170 /* min of (count, first + (*nummatches) ) */ 107 c_str_titles=z_getbriefrecords(first,count); 171 // z_getrecordTitles ( first, howmany ) 172 c_str_titles=z_getrecordTitles(first,min(count,*nummatches-first+1)); 108 173 if (c_str_titles==NULL) { 109 174 // an error occurred. we need a logout/err as an arg … … 124 189 } 125 190 126 bool z3950_server::getfullrecord(const int ID, text_t &rettitle, 127 text_t &rettext, comerror_t &err) { 191 bool z3950_server::getfullrecord(const text_t &query, const text_t &fields, 192 const int ID, 193 text_t &rettitle, 194 text_t &rettext, comerror_t &err) { 128 195 if (connected==false) { 129 196 if (connect()==false) { … … 134 201 // since we have just re-connected, we need to do the 135 202 // query again. 203 204 text_t expanded_query=""; 205 parseQuery(query,fields,expanded_query); 206 207 int returned=z_cmd_dosearch(expanded_query.getcstr()); 208 if (returned<=0) { 209 // 0 => none. 210 // <0 => error 211 err=protocolError; 212 return (false); 213 } 136 214 } 137 215 138 216 if (rettitle!="unneeded") { 139 /*char **c_str_titles;140 141 c_str_titles=z_getbriefrecords("the",ID,1,&dummy); // check this return value.142 217 char **c_str_titles; 218 //int dummy; 219 c_str_titles=z_getrecordTitles(ID,1); // check this return value. 220 if (c_str_titles!=NULL && (int)c_str_titles[0]==1) { 143 221 rettitle.setcstr(c_str_titles[1]); // and check this 144 222 free (c_str_titles); 145 */ 146 // rettitle=(*titles)[ID]; // this isn't quite right, as ID isn't the offset 147 rettitle="Dummy Title"; 148 } 149 223 // rettitle="Dummy Title"; 224 } else { 225 // we didn't get something.... 226 rettitle="Nothing Returned..."; 227 } 228 } 229 150 230 if (rettext!="unneeded") { 151 231 // get the text 152 rettext="Dummy Text. This is here as a placeholder until I work out"; 153 rettext+=" a way to get the query again when running in simple cgi\n"; 154 rettext+="as after each page is completed, the connection is lost to the"; 155 rettext+=" server, and we forget what the query was\n"; 232 rettext.setcstr(z_getfullRecord(ID)); 156 233 } 157 234 return (true); 158 }235 } 159 236 160 237 text_t &z3950_server::getzAbout() {
Note:
See TracChangeset
for help on using the changeset viewer.