Changeset 3851 for trunk/gsdl3/src
- Timestamp:
- 2003-03-11T16:58:35+13:00 (21 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/service
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Browse.java
r3678 r3851 28 28 import org.w3c.dom.NodeList; 29 29 /** 30 * A Service sImplclass for GSDL2-style Classifiers30 * A ServiceRack class for GSDL2-style Classifiers 31 31 * 32 32 * @author <a href="mailto:[email protected]">Katherine Don</a> … … 51 51 Element display = doc_.createElement(GSXML.DISPLAY_ELEM); 52 52 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, getTextString(service+".name", lang))); 53 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang))); 54 55 Element param; 56 53 //display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang))); 54 55 // need to add in the classifier name info 56 // add <classifier name="CL1">text name</classifier> to the 57 // display node 58 NodeList classifiers = config_info_.getElementsByTagName(GSXML.CLASSIFIER_ELEM); 59 for (int i=0; i<classifiers.getLength(); i++) { 60 Element cl = (Element)classifiers.item(i); 61 Element disp = (Element)GSXML.getChildByTagName(cl, GSXML.DISPLAY_ELEM); 62 String text = null; 63 if (disp !=null) { 64 text = GSXML.getDisplayText(disp, 65 GSXML.DISPLAY_NAME_ELEM, 66 lang, "en"); 67 } 68 if (text == null || text.equals("")) { 69 // no display element was specified, use the metadata name 70 // for now this looks in the class properties file 71 // this needs to use a general metadata thing instead 72 text = getTextString(cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT), lang); 73 } 74 75 Element cl_elem = doc_.createElement(GSXML.CLASSIFIER_ELEM); 76 cl_elem.setAttribute(GSXML.NAME_ATT, cl.getAttribute(GSXML.NAME_ATT)); 77 Element cl_name = GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, text); 78 cl_elem.appendChild(cl_name); 79 80 display.appendChild(cl_elem); 81 82 } 83 57 84 return display; 58 85 … … 90 117 classifier.setAttribute(GSXML.NAME_ATT, classifier_name); 91 118 result_content.appendChild(classifier); 119 120 // see if there is a stylesheet associated with this classifier 121 Element cl_list = (Element)GSXML.getChildByTagName(config_info_, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER); 122 Element cl_info = GSXML.getNamedElement(cl_list, 123 GSXML.CLASSIFIER_ELEM, 124 GSXML.NAME_ATT, 125 classifier_name); 126 if (cl_info !=null) { 127 128 // find the format child 129 Element cl_format = (Element)GSXML.getChildByTagName(cl_info, GSXML.FORMAT_ELEM); 130 // add it to the result if the result isnt null 131 if (cl_format!=null) { 132 System.out.println("adding format info to browse result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 133 result.appendChild(doc_.importNode(cl_format, true)); 134 } 135 } 136 92 137 DBInfo top_info; 93 138 … … 98 143 } 99 144 100 // a substitute template - should be read from config file101 //String extra = "<stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='document' priority='3'><xsl:param name='collName'>coll-name</xsl:param><xsl:variable name='library' select='ancestor::page/config/library_name'/><td><a href='{$library}?a=r&c={$collName}&r={@name}'><img src='interfaces/default/images/book.gif' width='18' height='11' border='0'/></a></td><td>***</td><td><xsl:value-of select='metadataList/metadata[@name=\"Title\"]'/></td></xsl:template></stylesheet>";102 //Element extra_doc = converter_.getDOM(extra).getDocumentElement();103 //result.appendChild(doc_.importNode(extra_doc, true));104 105 145 // get the classifier attributes 106 146 String type = top_info.getInfo("childtype"); … … 189 229 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 190 230 GSXML.addMetadata(doc_, meta_list, "Title", title); 231 String keyword = child_info.getInfo("Keyword"); 232 String source = child_info.getInfo("Source"); 233 GSXML.addMetadata(doc_, meta_list, "Keyword", keyword); 234 GSXML.addMetadata(doc_, meta_list, "Source", source); 191 235 node.appendChild(meta_list); 192 236 this_node.appendChild(node); … … 194 238 } 195 239 240 System.out.println("result="); 241 System.out.println(converter_.getString(result)); 196 242 return result; 197 243 … … 203 249 204 250 System.out.println("configuring GS2Browse"); 205 251 System.out.println("config info="); 252 System.out.println(converter_.getString(info)); 206 253 Element e = null; 207 254 // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built. … … 212 259 short_service_info_.appendChild(e); 213 260 261 // set up config info - just a cache of whats in the config file 262 config_info_ = info; 263 214 264 // set up service_info_map_ - for now, just has the same elements as above 215 265 // should have full details about each service incl params lists etc. … … 217 267 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE); 218 268 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE); 219 220 // get the classifier list out of the service info 221 Node classList = GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER); 222 e.appendChild(doc_.importNode(classList, true)); 223 269 Element cl_list = doc_.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER); 270 e.appendChild(cl_list); 271 272 // add in to the description a simplified list of classifiers 273 NodeList classifiers = config_info_.getElementsByTagName(GSXML.CLASSIFIER_ELEM); 274 275 for(int i=0; i<classifiers.getLength(); i++) { 276 Element cl = (Element)classifiers.item(i); 277 Element new_cl = (Element)doc_.importNode(cl, false); // just import this node, not the children 278 cl_list.appendChild(new_cl); 279 280 } 281 224 282 service_info_map_.put(CLASSIFIER_SERVICE, e); 225 283 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Construct.java
r3681 r3851 62 62 private static final String NEW_FILE_PARAM = "newfile"; 63 63 private static final String HANDLE_PARAM = "id"; 64 64 private static final String BUILDTYPE_PARAM = "buildType"; 65 private static final String BUILDTYPE_MG = "mg"; 66 private static final String BUILDTYPE_MGPP = "mgpp"; 67 65 68 // the list of the collections - store between some method calls 66 69 private String[] collection_list_ = null; … … 107 110 Element param; 108 111 if (service.equals(NEW_SERVICE)) { 109 // have the coll title, about and creator params112 // have the coll title, about, buildtype and creator params 110 113 param = GSXML.createParameterDisplay(doc_, NEW_COL_TITLE_PARAM, getTextString("param."+NEW_COL_TITLE_PARAM, lang), null, null); 111 114 display.appendChild(param); … … 113 116 display.appendChild(param); 114 117 param = GSXML.createParameterDisplay(doc_, NEW_COL_ABOUT_PARAM, getTextString("param."+NEW_COL_ABOUT_PARAM, lang), null, null); 118 display.appendChild(param); 119 120 String[] types = {BUILDTYPE_MGPP, BUILDTYPE_MG}; 121 String[] type_texts = {getTextString("param."+BUILDTYPE_PARAM+"."+BUILDTYPE_MGPP, lang), getTextString("param."+BUILDTYPE_PARAM+"."+BUILDTYPE_MG, lang)}; 122 param = GSXML.createParameterDisplay(doc_, BUILDTYPE_PARAM, getTextString("param."+BUILDTYPE_PARAM, lang), types, type_texts); 115 123 display.appendChild(param); 116 124 } else { … … 396 404 param = GSXML.createParameter(doc_, NEW_COL_ABOUT_PARAM, GSXML.PARAM_TYPE_TEXT, "", null); 397 405 param_list.appendChild(param); 406 String[] types = {BUILDTYPE_MGPP, BUILDTYPE_MG}; 407 param = GSXML.createParameter(doc_, BUILDTYPE_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, BUILDTYPE_MGPP, types); 408 param_list.appendChild(param); 409 398 410 e.appendChild(param_list); 399 411 service_info_map_.put(NEW_SERVICE, e); … … 627 639 param.setAttribute(GSXML.VALUE_ATT, (String)params.get(NEW_COL_TITLE_PARAM)); 628 640 param_list.appendChild(param); 641 param = doc_.createElement(GSXML.PARAM_ELEM); 642 param.setAttribute(GSXML.NAME_ATT, "buildtype"); 643 param.setAttribute(GSXML.VALUE_ATT, (String)params.get(BUILDTYPE_PARAM)); 644 param_list.appendChild(param); 629 645 return param_list; 630 646 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java
r3820 r3851 78 78 79 79 80 /** Retrieve the structure of a document */80 /** Retrieve the structure of a document - this function needed as its called specifically on the class name*/ 81 81 protected Element processDocumentStructureRetrieve(Element request) 82 82 { … … 85 85 86 86 87 /** Retrieve metadata associated with a document */87 /** Retrieve metadata associated with a document - this function needed as its called specifically on the class name*/ 88 88 protected Element processDocumentMetadataRetrieve(Element request) 89 89 { … … 106 106 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 107 107 if (param_list == null) { 108 System.err.println("GS2 Retrieve, DocumentContentRetrieve Error: missing paramList.\n");108 System.err.println("GS2MGPPRetrieve, DocumentContentRetrieve Error: missing paramList.\n"); 109 109 return result; // Return the empty result 110 110 } … … 113 113 114 114 // Process the request parameters 115 // are there any??? 115 116 Element param = (Element) param_list.getFirstChild(); 116 117 while (param != null) { … … 119 120 } 120 121 else { 121 // 122 // this looks for a level param but I think we dont use it 122 123 if (param.getAttribute(GSXML.NAME_ATT) == LEVEL_PARAM) { 123 124 level = GSXML.getValue(param); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java
r3826 r3851 47 47 extends GS2Search { 48 48 49 // these strings must match what is found in the properties file 50 // the services on offer 49 // extra services offered by mgpp collections 51 50 private static final String FIELD_QUERY_SERVICE = "FieldQuery"; 52 51 private static final String ADVANCED_FIELD_QUERY_SERVICE = "AdvancedFieldQuery"; 53 52 54 // Parameters used 55 private static final String INDEX_PARAM = "index"; 53 // extra parameters used 56 54 private static final String LEVEL_PARAM = "level"; 57 55 private static final String RANK_PARAM = "sortBy"; … … 70 68 private static final String FIELD_COMBINE_PARAM_NOT = "2"; 71 69 72 // Elements used in the config file that are specific to this class 73 private static final String DEFAULT_INDEX_ELEM = "defaultIndex"; 74 private static final String DEFAULT_LEVEL_ELEM = "defaultLevel"; 75 private static final String INDEX_ELEM = "index"; 76 private static final String LEVEL_ELEM = "level"; 77 70 private static final int TEXT_QUERY = 0; 71 private static final int SIMPLE_QUERY = 1; 72 private static final int ADVANCED_QUERY = 2; 73 74 protected static final String FIELD_ATT = "field"; 78 75 private MGPPWrapper mgpp_src_=null; 79 76 80 private String default_index_=null;81 77 private String default_level_=null; 82 83 78 84 79 /** constructor */ … … 99 94 System.out.println("Configuring GS2MGPPSearch..."); 100 95 101 // Get the default index out of <defaultIndex> (buildConfig.xml)102 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);103 if (def != null) {104 default_index_ = def.getAttribute(GSXML.NAME_ATT);105 }106 if (default_index_ == null || default_index_.equals("")) {107 System.err.println("Error: default index not specified!");108 return false;109 }110 // System.out.println("Default index: " + default_index_);111 112 96 // Get the default level out of <defaultLevel> (buildConfig.xml) 113 def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);97 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM); 114 98 if (def != null) { 115 99 default_level_ = def.getAttribute(GSXML.NAME_ATT); … … 119 103 return false; 120 104 } 121 // System.out.println("Default level: " + default_level_);122 105 123 106 // the default level is also the level which gdbm is expecting 124 107 mgpp_src_.setReturnLevel(default_level_); 108 mgpp_src_.setReturnTerms(true); 109 mgpp_src_.setQueryLevel(default_level_); 125 110 126 111 // set up which services are available for this collection … … 140 125 // set up service_info_map_ - for now, just has the same elements as above 141 126 // should have full details about each service incl params lists etc. 142 // do the text query one - for now a static list. later use buildcfg.xml values to dynamically change this143 127 Element fq_service_full = (Element) fq_service.cloneNode(true); 144 128 Element fq_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); … … 168 152 if (len > 1) { // add index param to list only if more than one index specified 169 153 String [] inds = new String[len]; 154 String [] ind_names = new String[len]; 170 155 for (int i=0; i<len; i++) { 171 156 inds[i] = ((Element)indexes.item(i)).getAttribute(GSXML.NAME_ATT); 157 if (display) { 158 Element disp = (Element)GSXML.getChildByTagName(indexes.item(i), GSXML.DISPLAY_ELEM); 159 ind_names[i] = GSXML.getDisplayText(disp, GSXML.DISPLAY_NAME_ELEM, lang, "en"); 160 } 161 //Element display_name = (Element)GSXML.getChildByTagName(indexes.item(i), GSXML.DISPLAYNAME_ELEM) 162 //ind_names[i] = GSXML.getNodeText((Element)GSXML.getChildByTagName(indexes.item(i), GSXML.DISPLAYNAME_ELEM)); 163 // } 172 164 } 173 165 if (display) { 174 166 // use the same index names for now - should get these out of the config info 175 param = GSXML.createParameterDisplay(doc_, INDEX_PARAM, getTextString("param."+INDEX_PARAM, lang), inds, ind s);167 param = GSXML.createParameterDisplay(doc_, INDEX_PARAM, getTextString("param."+INDEX_PARAM, lang), inds, ind_names); 176 168 } else { 177 169 param = GSXML.createParameter(doc_, INDEX_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_index_, inds); … … 185 177 if (len > 1) { // add level param to list only if more than one index specified 186 178 String [] levs = new String[len]; 179 String [] lev_names = new String[len]; 187 180 for (int i=0; i<len; i++) { 188 181 levs[i] = ((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT); 182 if (display) { 183 String lname = "level."+levs[i]; 184 System.out.println("lname="+lname); 185 //lev_names[i] = levs[i]; 186 lev_names[i] = getTextString(lname, lang); 187 } 189 188 } 190 189 if (display) { 191 param = GSXML.createParameterDisplay(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), levs, lev s);190 param = GSXML.createParameterDisplay(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), levs, lev_names); 192 191 } else { 193 192 param = GSXML.createParameter(doc_, LEVEL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_level_, levs); … … 231 230 232 231 } 232 233 233 } else if (name.equals(FIELD_FIELD_PARAM)) { 234 234 235 // the field list - should be read from config file 236 String [] vals2 = {"TX", "SU", "TI", "OR"}; 237 String [] vals2_texts = {"TextOnly", "Subject", "Title", "Organization"}; 235 // the field list - read from config file 236 Element field_list = (Element)GSXML.getChildByTagName(config_info_, GSXML.FIELD_ELEM+GSXML.LIST_MODIFIER); 237 NodeList fields = field_list.getElementsByTagName(GSXML.FIELD_ELEM); 238 int len = fields.getLength(); 239 String [] f_names = new String [len]; 240 String [] f_texts = new String [len]; 241 242 for (int i=0; i< len;i++) { 243 f_names[i] = ((Element)fields.item(i)).getAttribute(GSXML.SHORTNAME_ATT); 244 if (display) { 245 // these should be changed to a text element based on lang 246 f_texts[i] = ((Element)fields.item(i)).getAttribute(GSXML.NAME_ATT); 247 } 248 249 } 250 // String [] vals2 = {"TX", "SU", "TI", "OR"}; 251 //String [] vals2_texts = {"TextOnly", "Subject", "Title", "Organization"}; 238 252 239 253 if (display) { 240 param = GSXML.createParameterDisplay(doc_, FIELD_FIELD_PARAM, getTextString("param."+FIELD_FIELD_PARAM, lang), vals2, vals2_texts);254 param = GSXML.createParameterDisplay(doc_, FIELD_FIELD_PARAM, getTextString("param."+FIELD_FIELD_PARAM, lang), f_names, f_texts); 241 255 242 256 } else { 243 param = GSXML.createParameter(doc_, FIELD_FIELD_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", vals2);257 param = GSXML.createParameter(doc_, FIELD_FIELD_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", f_names ); 244 258 245 259 } … … 273 287 * otherwise it creates the description version 274 288 */ 275 protected boolean createTextQueryParamList(Element param_list, boolean display, 289 protected boolean createTextQueryParamList(Element param_list, 290 boolean display, 276 291 String lang) 277 292 { … … 280 295 createParameter(INDEX_PARAM, param_list, display, lang); 281 296 createParameter(LEVEL_PARAM, param_list, display, lang); 297 createParameter(CASE_PARAM, param_list, display, lang); 298 createParameter(STEM_PARAM, param_list, display, lang); 299 createParameter(MATCH_PARAM, param_list, display, lang); 282 300 createParameter(RANK_PARAM, param_list, display, lang); 283 return super.createTextQueryParamList(param_list, display, lang); 284 } 301 createParameter(MAXDOCS_PARAM, param_list, display, lang); 302 createParameter(QUERY_PARAM, param_list, display, lang); 303 304 return true; 305 } 306 307 308 // for now, the field queries just use the default index. 309 // however, it is entirely possible to create two indexes with different 310 // metadata. then you run into problems with displaying the form - you 311 // need to use javascript to change teh field and maybe level lists 312 // depending on which index is selected, or have the index preselected 313 // before going to the query form 285 314 286 315 … … 292 321 String lang) 293 322 { 323 createParameter(LEVEL_PARAM, param_list, display, lang); 294 324 createParameter(MATCH_PARAM, param_list, display, lang); 295 createParameter(LEVEL_PARAM, param_list, display, lang);296 325 createParameter(CASE_PARAM, param_list, display, lang); 297 326 createParameter(STEM_PARAM, param_list, display, lang); … … 386 415 return display; 387 416 } 388 389 417 418 // the following three functions are needed so the base class can 419 // call the process+SERVICE_NAME methods 390 420 /** process a text query */ 391 protected Element processTextQuery(Element request) 421 protected Element processTextQuery(Element request) { 422 return processAnyQuery(request, TEXT_QUERY); 423 } 424 425 /** process a field query */ 426 protected Element processFieldQuery(Element request) { 427 return processAnyQuery(request, SIMPLE_QUERY); 428 } 429 430 /** process an advanced field query */ 431 protected Element processAdvancedFieldQuery(Element request) { 432 return processAnyQuery(request, ADVANCED_QUERY); 433 } 434 435 /** process a query */ 436 protected Element processAnyQuery(Element request, int query_type) 392 437 { 438 439 String service_name=null; 440 String empty_query_test_param=null; 441 // set up the type specific bits 442 switch (query_type) { 443 case TEXT_QUERY: 444 service_name = TEXT_QUERY_SERVICE; 445 empty_query_test_param = QUERY_PARAM; 446 break; 447 case SIMPLE_QUERY: 448 service_name = FIELD_QUERY_SERVICE; 449 empty_query_test_param = FIELD_QUERY_PARAM; 450 break; 451 case ADVANCED_QUERY: 452 service_name = ADVANCED_FIELD_QUERY_SERVICE; 453 empty_query_test_param = FIELD_QUERY_PARAM; 454 break; 455 default: 456 // should never get here 457 System.out.println("wrong query type!!"); 458 return null; 459 } 460 393 461 // Create a new (empty) result message 394 462 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 395 String from = GSPath.appendLink(cluster_name_, TEXT_QUERY_SERVICE); 463 // set the from att 464 String from = GSPath.appendLink(cluster_name_, service_name); 396 465 result.setAttribute(GSXML.FROM_ATT, from); 397 466 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS); 398 467 Element result_content = doc_.createElement(GSXML.CONTENT_ELEM); 399 468 result.appendChild(result_content); 400 469 401 470 // Get the parameters of the request 402 471 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); … … 410 479 411 480 // Make sure a query has been specified 412 String query = (String) params.get( QUERY_PARAM);481 String query = (String) params.get(empty_query_test_param); 413 482 if (query == null || query == "") { 414 483 return result; // Return the empty result … … 421 490 } 422 491 423 // The location of the MGPP text files492 // set up mgpp_src 424 493 String basedir = GSFile.collectionBaseDir(site_home_, cluster_name_); 425 494 String indexdir = GSFile.collectionIndexPath(cluster_name_, index); … … 428 497 429 498 mgpp_src_.loadIndexData(basedir, indexdir); 430 431 499 setStandardQueryParams(params); 500 501 // if field search, create the query string 502 switch (query_type) { 503 case SIMPLE_QUERY: 504 query = parseFieldQueryParams(params); 505 break; 506 case ADVANCED_QUERY: 507 query = parseAdvancedFieldQueryParams(params); 508 break; 509 } 510 // run the query 432 511 mgpp_src_.runQuery(query); 433 512 MGPPQueryResult mqr= mgpp_src_.getQueryResult(); 434 long totalDocs = mqr.getTotalDocs(); 435 System.out.println("Total documents: " + totalDocs); 436 437 // Get the docnums out, and convert to HASH ids 438 Vector docs = mqr.getDocs(); 439 if (docs.size()==0) { 440 System.out.println("Warning: No results found...\n"); 441 // return result; 442 } 443 513 514 // build up the response 515 444 516 // Create a metadata list to store information about the query results 445 517 Element metadata_list = GSXML.addMetaList(doc_, result); 446 518 447 519 // Add a metadata element specifying the number of matching documents 520 long totalDocs = mqr.getTotalDocs(); 448 521 Element num_matches_elem = doc_.createElement(GSXML.METADATA_ELEM); 449 522 num_matches_elem.setAttribute(GSXML.NAME_ATT, "numDocsMatched"); … … 452 525 453 526 // Create a document list to store the matching documents, and add them 527 Vector docs = mqr.getDocs(); 454 528 Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER); 455 529 result_content.appendChild(document_list); … … 462 536 463 537 // Create a term list to store the term information, and add it 538 String query_level = (String)params.get(LEVEL_PARAM); // the current query level 464 539 Element term_list = doc_.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER); 465 540 result_content.appendChild(term_list); … … 467 542 for (int t = 0; t < terms.size(); t++) { 468 543 MGPPTermInfo term_info = (MGPPTermInfo) terms.get(t); 469 470 String term = term_info.term_; 471 int stem_method = term_info.stem_method_; 544 545 Element term_elem = doc_.createElement(GSXML.TERM_ELEM); 546 term_elem.setAttribute(GSXML.NAME_ATT, term_info.term_); 547 term_elem.setAttribute(STEM_ATT, "" + term_info.stem_method_); 548 term_elem.setAttribute(FREQ_ATT, "" + term_info.term_freq_); 549 term_elem.setAttribute(NUM_DOCS_MATCH_ATT, "" + term_info.match_docs_); 550 String field = term_info.tag_; 551 if (field.equals(query_level)) { 552 // ignore 553 field = ""; 554 } 555 term_elem.setAttribute(FIELD_ATT, field); 556 472 557 Vector equiv_terms = term_info.equiv_terms_; 473 474 Element term_elem = doc_.createElement(GSXML.TERM_ELEM);475 term_elem.setAttribute(GSXML.NAME_ATT, term);476 term_elem.setAttribute(STEM_ATT, "" + stem_method);477 478 558 Element equiv_term_list = doc_.createElement(EQUIV_TERM_ELEM+GSXML.LIST_MODIFIER); 479 559 term_elem.appendChild(equiv_term_list); 480 560 481 561 for (int et = 0; et < equiv_terms.size(); et++) { 482 562 String equiv_term = (String) equiv_terms.get(et); … … 489 569 } 490 570 491 term_elem.setAttribute(FREQ_ATT, "" + term_info.term_freq_);492 571 term_list.appendChild(term_elem); 493 572 } … … 495 574 return result; 496 575 } 497 498 499 protected Element processFieldQuery(Element request) {500 return processAnyFieldQuery(request, "simple");501 }502 503 504 protected Element processAdvancedFieldQuery(Element request) {505 return processAnyFieldQuery(request, "advanced");506 }507 508 509 /** process a fielded query */510 protected Element processAnyFieldQuery(Element request, String type) {511 512 System.out.println("processing any Field Query...");513 Element result = doc_.createElement(GSXML.RESPONSE_ELEM);514 String from = null;515 if (type.equals("simple")) {516 from = GSPath.appendLink(cluster_name_, FIELD_QUERY_SERVICE);517 } else {518 from = GSPath.appendLink(cluster_name_, ADVANCED_FIELD_QUERY_SERVICE);519 }520 result.setAttribute(GSXML.FROM_ATT, from);521 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);522 523 // get param list524 Element param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);525 if (param_list==null) {526 System.err.println("GS2MGPPSearch, FieldQuery Error: no param list in request!");527 return result; // empty result528 }529 530 HashMap params = GSXML.extractAllParams(param_list);531 printHash(params);532 533 //check one of the params to see if it is present534 String test_param = (String)params.get(FIELD_QUERY_PARAM);535 if (test_param == null) { // no query536 return result;537 }538 539 // for now we are using the default index540 String index = default_index_;541 542 // now set up the mgpp stuff543 String basedir = GSFile.collectionBaseDir(site_home_,544 cluster_name_);545 String indexdir = GSFile.collectionIndexPath(cluster_name_, index);546 547 mgpp_src_.loadIndexData(basedir, indexdir);548 setStandardQueryParams(params);549 550 String query="";551 if (type.equals("simple")) {552 query = parseFieldQueryParams(params);553 } else if (type.equals("advanced")) {554 query = parseAdvancedFieldQueryParams(params);555 }556 System.out.println("query="+query);557 mgpp_src_.runQuery(query);558 MGPPQueryResult mqr= mgpp_src_.getQueryResult();559 560 // get the docnums out, and convert to HASH ids561 Vector docs = mqr.getDocs();562 if (docs.size()==0) {563 // no docs found564 return result;565 }566 // create a documentList element567 Element c = doc_.createElement(GSXML.CONTENT_ELEM);568 result.appendChild(c);569 Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);570 c.appendChild(document_list);571 // add each document572 for (int d=0; d<docs.size(); d++) {573 long docnum = ((MGPPDocInfo)docs.elementAt(d)).num_;574 String id = gdbm_src_.docnum2Oid(docnum);575 Element doc_node = createDocumentNodeElement(id);576 document_list.appendChild(doc_node);577 }578 return result;579 }580 581 582 576 583 577 // should probably use a list rather than map 584 578 protected boolean setStandardQueryParams(HashMap params) { 585 579 586 // set the default ones587 mgpp_src_.setReturnTerms(true);588 580 Set entries = params.entrySet(); 589 581 Iterator i = entries.iterator(); … … 620 612 } 621 613 614 /** combines all the field params into a single query 615 * - for simple field query */ 622 616 protected String parseFieldQueryParams(HashMap params) { 623 617 … … 644 638 return final_query.toString(); 645 639 } 646 640 641 /** combines all the field params into a single query 642 * - for advanced field query */ 647 643 protected String parseAdvancedFieldQueryParams(HashMap params) { 648 644 … … 697 693 } 698 694 } 695 699 696 protected String addStemAndCase(String q, String s, String c) { 700 697 String mods = "#"; … … 721 718 } 722 719 723 protected void printHash(HashMap map) {724 System.out.println("Map entries are :");725 Set entries = map.entrySet();726 Iterator i = entries.iterator();727 while (i.hasNext()) {728 Map.Entry m = (Map.Entry)i.next();729 String name = (String)m.getKey();730 String value = (String)m.getValue();731 System.out.println(name+"="+value);732 }733 }734 720 735 721 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java
r3823 r3851 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 6 * the Free Software Foundation; either version 2 of the License, or 8 7 * (at your option) any later version. 9 8 * … … 41 40 * 42 41 * @author <a href="mailto:[email protected]">Katherine Don</a> 42 * @author <a href="mailto:[email protected]">Michael Dewsnip</a> 43 43 * @version $Revision$ 44 44 */ … … 47 47 extends GS2Search { 48 48 49 // Parameters used50 private static final String INDEX_PARAM = "index";51 52 // Elements used in the config file that are specific to this class53 private static final String DEFAULT_INDEX_ELEM = "defaultIndex";54 private static final String INDEX_ELEM = "index";55 49 56 50 private MGWrapper mg_src_ = null; 57 58 private String default_index_ = null;59 51 60 52 … … 67 59 68 60 /** configure this service */ 69 public boolean configure(Element info)61 /* public boolean configure(Element info) 70 62 { 71 63 // Do generic configuration … … 76 68 System.out.println("Configuring GS2MGSearch..."); 77 69 78 // Get the default index out of <defaultIndex> (buildConfig.xml)79 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);80 if (def != null) {81 default_index_ = def.getAttribute(GSXML.NAME_ATT);82 }83 if (default_index_ == null || default_index_.equals("")) {84 System.err.println("Error: default index not specified!");85 return false;86 }87 // System.out.println("Default index: " + default_index_);88 89 70 return true; 90 } 71 }*/ 91 72 92 73 … … 136 117 // the query form 137 118 createParameter(INDEX_PARAM, param_list, display, lang); 138 return super.createTextQueryParamList(param_list, display, lang); 119 createParameter(CASE_PARAM, param_list, display, lang); 120 createParameter(STEM_PARAM, param_list, display, lang); 121 createParameter(MATCH_PARAM, param_list, display, lang); 122 createParameter(MAXDOCS_PARAM, param_list, display, lang); 123 createParameter(QUERY_PARAM, param_list, display, lang); 124 125 return true; 139 126 } 140 127 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Search.java
r3822 r3851 30 30 /** 31 31 * 32 * @author <a href="mailto: [email protected]">Katherine Don</a>32 * @author <a href="mailto:[email protected]">Michael Dewsnip</a> 33 33 * @version $Revision$ 34 34 */ … … 42 42 43 43 // Parameters used 44 protected static final String INDEX_PARAM = "index"; 44 45 protected static final String CASE_PARAM = "case"; 45 46 protected static final String STEM_PARAM = "stem"; … … 58 59 protected static final String FREQ_ATT = "freq"; 59 60 61 // Elements used in the config file that are specific to this class 62 protected static final String DEFAULT_INDEX_ELEM = "defaultIndex"; 63 protected static final String DEFAULT_LEVEL_ELEM = "defaultLevel"; 64 protected static final String INDEX_ELEM = "index"; 65 protected static final String LEVEL_ELEM = "level"; 66 60 67 protected GDBMWrapper gdbm_src_ = null; 61 68 62 69 protected Element config_info_ = null; 70 71 /** the default index */ 72 protected String default_index_ = null; 63 73 64 74 … … 75 85 System.out.println("Configuring GS2Search..."); 76 86 config_info_ = info; 87 88 // Get the default index out of <defaultIndex> (buildConfig.xml) 89 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM); 90 if (def != null) { 91 default_index_ = def.getAttribute(GSXML.NAME_ATT); 92 } 93 if (default_index_ == null || default_index_.equals("")) { 94 System.err.println("Error: default index not specified!"); 95 return false; 96 } 77 97 78 98 // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built. … … 103 123 104 124 /** creates a new param element and adds it to the param list */ 105 protected void createParameter(String name, Element param_list, boolean display,106 String lang)125 protected void createParameter(String name, Element param_list, 126 boolean display, String lang) 107 127 { 108 128 Element param=null; … … 162 182 * otherwise it creates the description version 163 183 */ 164 protected boolean createTextQueryParamList(Element param_list, boolean display, 165 String lang) 166 { 167 // the order they are specified here is the order they appear on 168 // the query form 169 createParameter(CASE_PARAM, param_list, display, lang); 170 createParameter(STEM_PARAM, param_list, display, lang); 171 createParameter(MATCH_PARAM, param_list, display, lang); 172 createParameter(MAXDOCS_PARAM, param_list, display, lang); 173 createParameter(QUERY_PARAM, param_list, display, lang); 174 return true; 175 } 176 184 protected abstract boolean createTextQueryParamList(Element param_list, 185 boolean display, 186 String lang); 177 187 178 188 /** creates a display element containing all the text strings needed to display … … 182 192 // Create a service display for the basic text query service 183 193 Element display = doc_.createElement(GSXML.DISPLAY_ELEM); 184 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, 185 getTextString(service+".name", lang))); 186 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, 187 getTextString(service+".submit", lang))); 194 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, getTextString(service+".name", lang))); 195 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang))); 188 196 189 197 // now need to add in the params -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceRack.java
r3677 r3851 69 69 /** a converter class to create Documents etc */ 70 70 protected XMLConverter converter_ = null; 71 72 /** the original config info - if need to store it */ 73 protected Element config_info_ = null; 71 74 72 75 /** XML element for describe requests - the container doc */ -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/XSLTServices.java
r3648 r3851 100 100 } 101 101 102 /** configure this service */103 public boolean configure(Element info) {104 105 System.out.println("configuring XSLTServices");106 config_info_ = info;102 /** configure this service */ 103 public boolean configure(Element info) { 104 105 System.out.println("configuring XSLTServices"); 106 config_info_ = info; 107 107 try { 108 108 System.out.println("XSLTService::configure() called with:");
Note:
See TracChangeset
for help on using the changeset viewer.