source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java@ 10651

Last change on this file since 10651 was 10651, checked in by kjdon, 19 years ago

made all index/gdbm db paths use indexstem instead of cluster_name

  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/*
2 * GS2MGSearch.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18package org.greenstone.gsdl3.service;
19
20
21// Greenstone classes
22import org.greenstone.gsdl3.util.*;
23
24// XML classes
25import org.w3c.dom.Document;
26import org.w3c.dom.Element;
27import org.w3c.dom.NodeList;
28
29/**
30 *
31 * @author <a href="mailto:[email protected]">Katherine Don</a>
32 * @author <a href="mailto:[email protected]">Michael Dewsnip</a>
33 */
34
35public class GS2MGSearch
36 extends AbstractMGSearch
37{
38 protected GDBMWrapper gdbm_src = null;
39
40 /** constructor */
41 public GS2MGSearch()
42 {
43 this.gdbm_src = new GDBMWrapper();
44 }
45 public void cleanUp() {
46 super.cleanUp();
47 this.gdbm_src.closeDatabase();
48 }
49
50 /** configure this service */
51 public boolean configure(Element info, Element extra_info)
52 {
53 if (!super.configure(info, extra_info)){
54 return false;
55 }
56
57 // Open GDBM database for querying
58 String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
59 if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
60 System.err.println("Error: Could not open GDBM database!");
61 return false;
62 }
63 return true;
64 }
65 /** returns the document type of the doc that the specified node
66 belongs to. should be one of
67 GSXML.DOC_TYPE_SIMPLE,
68 GSXML.DOC_TYPE_PAGED,
69 GSXML.DOC_TYPE_HIERARCHY
70 */
71 protected String getDocType(String node_id){
72 DBInfo info = this.gdbm_src.getInfo(node_id);
73 if (info == null) {
74 return GSXML.DOC_TYPE_SIMPLE;
75 }
76 String doc_type = info.getInfo("doctype");
77 if (!doc_type.equals("")&&!doc_type.equals("doc")) {
78 return doc_type;
79 }
80
81 String top_id = OID.getTop(node_id);
82 boolean is_top = (top_id.equals(node_id) ? true : false);
83
84 String children = info.getInfo("contains");
85 boolean is_leaf = (children.equals("") ? true : false);
86
87 if (is_top && is_leaf) { // a single section document
88 return GSXML.DOC_TYPE_SIMPLE;
89 }
90
91 // now we just check the top node
92 if (!is_top) { // we need to look at the top info
93 info = this.gdbm_src.getInfo(top_id);
94 }
95 if (info == null) {
96 return GSXML.DOC_TYPE_HIERARCHY;
97 }
98
99 String childtype = info.getInfo("childtype");
100 if (childtype.equals("Paged")) {
101 return GSXML.DOC_TYPE_PAGED;
102 }
103 return GSXML.DOC_TYPE_HIERARCHY;
104
105 }
106
107 /** returns true if the node has child nodes */
108 protected boolean hasChildren(String node_id){
109 DBInfo info = this.gdbm_src.getInfo(node_id);
110 if (info == null) {
111 return false;
112 }
113 String contains = info.getInfo("contains");
114 if (contains.equals("")) {
115 return false;
116 }
117 return true;
118 }
119
120 /** returns true if the node has a parent */
121 protected boolean hasParent(String node_id){
122 String parent = OID.getParent(node_id);
123 if (parent.equals(node_id)) {
124 return false;
125 }
126 return true;
127 }
128
129 /** convert MG internal id to Greenstone oid */
130 protected String MGNum2OID(long docnum)
131 {
132 return this.gdbm_src.docnum2OID(docnum);
133
134 }
135
136}
137
138
Note: See TracBrowser for help on using the repository browser.