- Timestamp:
- 2008-05-01T13:59:09+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2Search.java
r13999 r15326 20 20 21 21 // Greenstone classes 22 import org.greenstone.mg.*; 23 import org.greenstone.gsdl3.util.*; 22 import org.greenstone.gsdl3.util.OID; 23 import org.greenstone.gsdl3.util.DBInfo; 24 import org.greenstone.gsdl3.util.GSXML; 25 import org.greenstone.gsdl3.util.SimpleCollectionDatabase; 26 import org.greenstone.gsdl3.util.GSFile; 24 27 25 28 // XML classes … … 74 77 protected int maxnumeric = 4; 75 78 76 protected GDBMWrapper gdbm_src = null; 77 78 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGSearch.class.getName()); 79 // collection database 80 protected SimpleCollectionDatabase coll_db = null; 81 82 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2Search.class.getName()); 79 83 80 84 … … 82 86 public AbstractGS2Search() 83 87 { 84 this.gdbm_src = new GDBMWrapper();88 85 89 } 86 90 public void cleanUp() { 87 91 super.cleanUp(); 88 this. gdbm_src.closeDatabase();92 this.coll_db.closeDatabase(); 89 93 } 90 94 … … 93 97 { 94 98 if (!super.configure(info, extra_info)){ 99 return false; 100 } 101 102 // find out what kind of database we have 103 Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM); 104 String database_type = null; 105 if (database_type_elem != null) { 106 database_type = database_type_elem.getAttribute(GSXML.NAME_ATT); 107 } 108 if (database_type == null || database_type.equals("")) { 109 database_type = "gdbm"; // the default 110 } 111 coll_db = new SimpleCollectionDatabase(database_type); 112 if (coll_db == null) { 113 logger.error("Couldn't create the collection database of type "+database_type); 114 return false; 115 } 116 117 // the index stem is either the collection name or is specified in the config file 118 Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM); 119 if (index_stem_elem != null) { 120 this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT); 121 } 122 if (this.index_stem == null || this.index_stem.equals("")) { 123 logger.warn("indexStem element not found, stem will default to collection name"); 124 this.index_stem = this.cluster_name; 125 } 126 127 // Open database for querying 128 String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type); 129 if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) { 130 logger.error("Could not open collection database!"); 95 131 return false; 96 132 } … … 116 152 this.default_index_language = defLang.getAttribute(GSXML.SHORTNAME_ATT); 117 153 } //concate defaultIndex + defaultIndexSubcollection + defaultIndexLanguage 118 119 120 // the index stem is either the collection name or is specified in the config file 121 Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM); 122 if (index_stem_elem != null) { 123 this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT); 124 } 125 if (this.index_stem == null || this.index_stem.equals("")) { 126 logger.warn("indexStem element not found, stem will default to collection name"); 127 this.index_stem = this.cluster_name; 128 } 129 154 130 155 // get index options 131 156 Element index_option_list = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_OPTION_ELEM + GSXML.LIST_MODIFIER); … … 187 212 } // for each index 188 213 } 189 // Open GDBM database for querying190 String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);191 if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {192 logger.error(" Could not open GDBM database!");193 return false;194 }195 214 return true; 196 215 } … … 294 313 */ 295 314 protected String getDocType(String node_id){ 296 DBInfo info = this. gdbm_src.getInfo(node_id);315 DBInfo info = this.coll_db.getInfo(node_id); 297 316 if (info == null) { 298 317 return GSXML.DOC_TYPE_SIMPLE; … … 315 334 // now we just check the top node 316 335 if (!is_top) { // we need to look at the top info 317 info = this. gdbm_src.getInfo(top_id);336 info = this.coll_db.getInfo(top_id); 318 337 } 319 338 if (info == null) { … … 331 350 /** returns true if the node has child nodes */ 332 351 protected boolean hasChildren(String node_id){ 333 DBInfo info = this. gdbm_src.getInfo(node_id);352 DBInfo info = this.coll_db.getInfo(node_id); 334 353 if (info == null) { 335 354 return false; … … 351 370 } 352 371 353 /** convert MGinternal id to Greenstone oid */372 /** convert indexer internal id to Greenstone oid */ 354 373 protected String internalNum2OID(long docnum) 355 374 { 356 return this. gdbm_src.docnum2OID(docnum);375 return this.coll_db.docnum2OID(docnum); 357 376 358 377 } 359 378 protected String internalNum2OID(String docnum) 360 379 { 361 return this. gdbm_src.docnum2OID(docnum);380 return this.coll_db.docnum2OID(docnum); 362 381 363 382 }
Note:
See TracChangeset
for help on using the changeset viewer.