Changeset 257 for trunk/gsdl/src/recpt/OIDtools.cpp
- Timestamp:
- 1999-05-10T15:40:44+12:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/OIDtools.cpp
r248 r257 12 12 /* 13 13 $Log$ 14 Revision 1.6 1999/05/10 03:40:25 sjboddie 15 lots of changes - slowly getting document action sorted out 16 14 17 Revision 1.5 1999/04/30 01:59:37 sjboddie 15 18 lots of stuff - getting documentaction working (documentaction replaces … … 38 41 39 42 40 // get first four characters of whatever string is passed in41 // OID. This returns the CLSU, HASH etc.42 void get_head (const text_t &OID, text_t &head) {43 44 head.clear();45 if (OID.size() < 4) return;46 head.appendrange (OID.begin(), (OID.begin() + 4));47 }48 49 50 43 // returns (in top) the top level of OID (i.e. everything 51 44 // up until the first dot) … … 76 69 77 70 78 // is_classification checks OID to see if it's a classification79 // or a document. I'm not sure how to do this - for now I'll just assume80 // all documents start with HASH and classifications start with something81 // else.82 bool is_classification (const text_t &OID) {83 text_t head;84 get_head (OID, head);85 if (head == "HASH") return false;86 return true;87 }88 89 71 // get_parents_array loads the parents array with all the parents of the 90 // document or classification specified by OID 91 // note that this function doesn't clear the parents array 72 // document or classification specified by OID 92 73 void get_parents_array (const text_t &OID, text_tarray &parents) { 74 75 parents.erase (parents.begin(), parents.end()); 93 76 94 77 text_t::const_iterator here = OID.begin (); … … 134 117 } 135 118 119 // has_children returns true if OID has children 120 bool has_children (const text_t &OID, const text_t &collection, 121 recptproto *collectproto, ostream &logout) { 122 123 FilterResponse_t response; 124 text_tarray metadata; 125 metadata.push_back ("haschildren"); 126 127 if (get_info (OID, collection, metadata, collectproto, 128 response, logout)) { 129 if (response.docInfo[0].metadata[0].values[0] == "1") 130 return true; 131 } 132 return false; 133 } 134 135 136 136 // get_children does a protocol call and returns (in response) the OIDs and 137 137 // metadata of all the children of OID. The metadata array should be loaded … … 168 168 } 169 169 170 // get_first_child does a protocol call and returns (in child) the OID171 // of the first child of OID if it exists172 bool get_first_child (const text_t &OID, text_t &child, const text_t &collection,173 recptproto *collectproto, ostream logout) {174 175 comerror_t err;176 FilterResponse_t response;177 FilterRequest_t request;178 OptionValue_t option;179 180 request.filterName = "BrowseFilter";181 option.name = "EndResults";182 option.value = "1";183 request.filterOptions.push_back (option);184 option.name = "ParentNode";185 option.value = OID;186 request.filterOptions.push_back (option);187 request.filterResultOptions = FROID;188 189 collectproto->filter (collection, request, response, err, logout);190 191 if (err != noError) {192 outconvertclass text_t2ascii;193 logout << text_t2ascii194 << "Error: call to filter failed for " << OID195 << " in OIDtools::get_first_child ("196 << get_comerror_string (err) << ")\n";197 return false;198 }199 200 if (response.docInfo[0].OID.empty())201 return false;202 else203 child = response.docInfo[0].OID;204 return true;205 }206 207 170 // get_parent returns the parent of the document or classification 208 171 // specified by OID … … 222 185 } 223 186 224 // takes an OID like ".2 .3and replaces the " with parent187 // takes an OID like ".2 and replaces the " with parent 225 188 void translate_parent (text_t &OID, const text_t &parent) { 226 189 … … 240 203 void shrink_parent (text_t &OID) { 241 204 242 text_t::iterator parit = findchar (OID.begin(), OID.end(), '.'); 243 if (parit == OID.end()) return; 244 245 OID.erase (OID.begin(), parit); 246 OID = "\"" + OID; 205 text_tarray tmp; 206 splitchar (OID.begin(), OID.end(), '.', tmp); 207 OID = "\"." + tmp.back(); 247 208 } 248 209 … … 260 221 return false; 261 222 } 223 224 225 void recurse_contents (const ResultDocInfo_t section, const bool &classify, 226 int &totalcols, const text_t &collection, 227 const text_tarray &metadata, recptproto *collectproto, 228 FilterResponse_t &response, ostream &logout) { 229 230 int haschildren = section.metadata[1].values[0].getint(); 231 const text_t &doctype = section.metadata[2].values[0]; 232 int cols; 233 234 if ((haschildren == 1) && ((!classify) || (doctype == "classify"))) { 235 text_t parent = response.docInfo.back().OID; 236 int parentcols = countchar (parent.begin(), parent.end(), '.'); 237 FilterResponse_t tmp; 238 get_children (section.OID, collection, metadata, collectproto, tmp, logout); 239 ResultDocInfo_tarray::const_iterator thisdoc = tmp.docInfo.begin(); 240 ResultDocInfo_tarray::const_iterator lastdoc = tmp.docInfo.end(); 241 while (thisdoc != lastdoc) { 242 if (((*thisdoc).metadata[2].values[0] != "classify") && (classify)) 243 cols = parentcols + 1; 244 else 245 cols = countchar ((*thisdoc).OID.begin(), (*thisdoc).OID.end(), '.'); 246 if (cols > totalcols) totalcols = cols; 247 response.docInfo.push_back (*thisdoc); 248 recurse_contents (*thisdoc, classify, totalcols, collection, 249 metadata, collectproto, response, logout); 250 thisdoc ++; 251 } 252 } 253 } 254 255 // get_contents returns OIDs and metadata of all contents 256 // below (and including) OID. 257 // metadata being returned for each is Title, haschildren, 258 // doctype, and hastxt 259 void get_contents (const text_t &topOID, const text_t &classifytype, int &totalcols, 260 const text_t &collection, recptproto *collectproto, 261 FilterResponse_t &response, ostream &logout) { 262 263 bool classify = false; 264 response.clear(); 265 text_tarray metadata; 266 metadata.push_back ("Title"); 267 metadata.push_back ("haschildren"); 268 metadata.push_back ("doctype"); 269 metadata.push_back ("hastxt"); 270 271 // we don't want to recurse all the way down through each document 272 // if we're expanding top level contents 273 if (classifytype == "classify") classify = true; 274 275 // update totalcols 276 totalcols = countchar (topOID.begin(), topOID.end(), '.'); 277 278 // get topOIDs info 279 if (get_info (topOID, collection, metadata, collectproto, response, logout)) 280 recurse_contents (response.docInfo[0], classify, totalcols, collection, 281 metadata, collectproto, response, logout); 282 }
Note:
See TracChangeset
for help on using the changeset viewer.