source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPSearch.java@ 9002

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

reworked the search classes, now have a base AbstractSearch class, hopefully all searches can inherit from this. base classes are mg/mgpp split rather than gs2/gs3

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/*
2 * GS3MGPPSearch.java
3 * Copyright (C) 2005 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// Greenstone classes
21import org.greenstone.mg.*;
22import org.greenstone.gsdl3.util.GSXML;
23import org.greenstone.gsdl3.util.GS3OID;
24import org.greenstone.gsdl3.util.SQLQuery;
25
26// XML classes
27import org.w3c.dom.Document;
28import org.w3c.dom.Element;
29import org.w3c.dom.NodeList;
30
31// java classes
32import java.io.File;
33
34
35/**
36 *
37 * @author <a href="mailto:[email protected]">Katherine Don</a>
38 */
39
40public class GS3MGPPSearch
41 extends AbstractMGPPSearch
42{
43 protected SQLQuery database = null;
44 /** the base index prefix */
45 protected String base_index_prefix = null;
46
47
48 /** constructor */
49 public GS3MGPPSearch()
50 {
51 this.database = new SQLQuery();
52 }
53
54 /** configure this service */
55 public boolean configure(Element info, Element extra_info)
56 {
57
58 // get the base prefix
59 Element def = (Element) GSXML.getChildByTagName(info, "baseIndexPrefix");
60 if (def != null) {
61 this.base_index_prefix = def.getAttribute(GSXML.NAME_ATT);
62 }
63 if (this.base_index_prefix == null || this.base_index_prefix.equals("")) {
64 System.err.println("Error: base index prefix not specified!");
65 return false;
66 }
67 String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1);
68 if (site_name.equals("")) {
69 System.err.println("GS3Search Error: Cannot extract the site name from site home: "+this.site_home);
70 return false;
71 }
72 if (!database.setDatabase(site_name+"_"+this.cluster_name)) {
73 System.err.println("GS3Search Error: Could not open SQL database!");
74 return false;
75 }
76
77 return super.configure(info, extra_info);
78 }
79 /** returns the document type of the doc that the specified node
80 belongs to. should be one of
81 GSXML.DOC_TYPE_SIMPLE,
82 GSXML.DOC_TYPE_PAGED,
83 GSXML.DOC_TYPE_HIERARCHY
84 */
85 protected String getDocType(String node_id){
86 boolean hierarchical = false;
87 if (!GS3OID.isDocTop(node_id) || database.isHierarchicalDocument(node_id) ) {
88 hierarchical = true;
89 }
90 // what about paged???
91 if (!hierarchical) {
92 // a simple document
93 return GSXML.DOC_TYPE_SIMPLE;
94 } else {
95 // a hierarchical doc
96 return GSXML.DOC_TYPE_HIERARCHY;
97 }
98 // don't have paged yet.
99
100 }
101
102 /** returns true if the node has child nodes */
103 protected boolean hasChildren(String node_id){
104 return database.documentHasChildren(node_id);
105 }
106
107 /** returns true if the node has a parent */
108 protected boolean hasParent(String node_id){
109 String parent = GS3OID.getParent(node_id);
110 if (parent.equals(node_id)) {
111 return false;
112 }
113 return true;
114 }
115
116 /** convert MGPP internal id to Greenstone oid */
117 protected String MGPPNum2OID(long docnum)
118 {
119 String mg_id = this.base_index_prefix+"."+docnum;
120 String doc_id = database.MGNum2OID(mg_id);
121 // hack !!!
122 if (doc_id.endsWith("-All")) {
123 // get rid of the All bit
124 doc_id = doc_id.substring(0,doc_id.length()-4);
125 //doc_id=doc_id.replaceAll("All","1");
126 }
127 return doc_id;
128
129 }
130
131}
132
133
Note: See TracBrowser for help on using the repository browser.