source: gs3-extensions/audioDB/trunk/src/src/java/org/greenstone/gsdl3/service/AbstractGS2AudioSearch.java@ 30411

Last change on this file since 30411 was 30411, checked in by davidb, 8 years ago

Changes after debugging on MacOS El Capitan

File size: 6.4 KB
Line 
1/*
2 * AbstractGS2AudioSearch.java
3 * Copyright (C) 2011 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.OID;
23import org.greenstone.gsdl3.util.DBInfo;
24import org.greenstone.gsdl3.util.GSXML;
25import org.greenstone.gsdl3.util.BasicDocumentDatabase;
26import org.greenstone.gsdl3.util.GSFile;
27
28// XML classes
29import org.w3c.dom.Document;
30import org.w3c.dom.Element;
31import org.w3c.dom.NodeList;
32
33// java
34import java.util.Vector;
35import java.util.ArrayList;
36import java.util.HashMap;
37import java.util.Map;
38import java.util.Set;
39import java.util.Iterator;
40import java.io.File;
41
42import org.apache.log4j.*;
43
44public abstract class AbstractGS2AudioSearch
45 extends AbstractAudioSearch
46{
47
48 protected static final String EQUIV_TERM_ELEM = "equivTerm";
49
50 protected static final String STEM_ATT = "stem";
51 protected static final String NUM_DOCS_MATCH_ATT = "numDocsMatch";
52 protected static final String FREQ_ATT = "freq";
53
54 // Elements used in the config file that are specific to this class
55 protected static final String DEFAULT_INDEX_ELEM = "defaultIndex";
56 protected static final String INDEX_STEM_ELEM = "indexStem";
57 protected static final String INDEX_ELEM = "index";
58 protected static final String DEFAULT_INDEX_SUBCOLLECTION_ELEM = "defaultIndexSubcollection";
59 protected static final String DEFAULT_INDEX_LANGUAGE_ELEM = "defaultIndexLanguage";
60 protected static final String INDEX_SUBCOLLECTION_ELEM = "indexSubcollection";
61 protected static final String INDEX_LANGUAGE_ELEM = "indexLanguage";
62
63
64 // Some indexing options
65 protected static final String STEMINDEX_OPTION = "stemIndexes";
66 protected static final String MAXNUMERIC_OPTION = "maxnumeric";
67
68 /** the stem used for the index files */
69 protected String index_stem = null;
70
71 // stem indexes available
72 protected boolean does_case=true;
73 protected boolean does_stem=true;
74 protected boolean does_accent=false;
75
76 // maxnumeric -
77 protected int maxnumeric = 4;
78
79 BasicDocumentDatabase gs_doc_db = null;
80
81 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2AudioSearch.class.getName());
82
83
84 /** constructor */
85 public AbstractGS2AudioSearch()
86 {
87
88 }
89 public void cleanUp() {
90 super.cleanUp();
91 this.gs_doc_db.cleanUp();
92 }
93
94 /** configure this service */
95 public boolean configure(Element info, Element extra_info)
96 {
97 if (!super.configure(info,extra_info)) {
98 return false;
99 }
100
101 // find out what kind of database we have
102 Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
103 String database_type = null;
104 if (database_type_elem != null) {
105 database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
106 }
107 if (database_type == null || database_type.equals("")) {
108 database_type = "gdbm"; // the default
109 }
110
111 // the index stem is either the collection name or is specified in the config file
112 Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM);
113 if (index_stem_elem != null) {
114 this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
115 }
116 if (this.index_stem == null || this.index_stem.equals("")) {
117 logger.warn("indexStem element not found, stem will default to collection name");
118 this.index_stem = this.cluster_name;
119 }
120
121 // replaces default AbstractSearch version with one tied to database
122 gs_doc_db = new BasicDocumentDatabase(database_type,this.site_home,
123 this.cluster_name,
124 this.index_stem);
125 if (!gs_doc_db.isValid()) {
126 logger.error("Failed to open Document Database.");
127 return false;
128 }
129 this.gs_doc = gs_doc_db;
130
131 // do we support any of the extended features?
132 does_chunking = true;
133
134 // Get the default index out of <defaultIndex> (buildConfig.xml)
135 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM);
136 if (def != null) {
137 this.default_index = def.getAttribute(GSXML.SHORTNAME_ATT);
138 } // otherwise will be "", and the first one will be the default
139
140
141 // Get index options ...
142 // ... but there are currently no index options supported for audio
143 // so nothing to do
144
145 // Similarly the following will not currently do anything, but leave
146 // in for the time we do start supporting different indexes
147 //
148 // *** Also, it is identical to that in AbstractGS2TextSearch, so
149 // consider putting into supporting routine and sharing
150 // (realted in 'info' object
151
152 // get display info from extra info
153 if (extra_info !=null) {
154 Document owner = info.getOwnerDocument();
155 // so far we have index specific display elements, and global format elements
156 NodeList indexes = info.getElementsByTagName(GSXML.INDEX_ELEM);
157 Element config_search = (Element)GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
158
159 for (int i=0; i<indexes.getLength();i++) {
160 Element ind = (Element)indexes.item(i);
161 String name = ind.getAttribute(GSXML.NAME_ATT);
162 Element node_extra = GSXML.getNamedElement(config_search,
163 GSXML.INDEX_ELEM,
164 GSXML.NAME_ATT,
165 name);
166 if (node_extra == null) {
167 logger.error("haven't found extra info for index named "+name);
168 continue;
169 }
170
171 // get the display elements if any - displayName
172 NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
173 if (display_names !=null) {
174 for (int j=0; j<display_names.getLength(); j++) {
175 Element e = (Element)display_names.item(j);
176 ind.appendChild(owner.importNode(e, true));
177 }
178 }
179 } // for each index
180 }
181
182 return true;
183 }
184
185 protected void getIndexData(ArrayList index_ids, ArrayList index_names, String lang)
186 {
187 logger.info("Trivial index support for audio for now. Adding hardwired 'audioDB' to index");
188 index_names.add("audioDB");
189 }
190}
191
192
Note: See TracBrowser for help on using the repository browser.