source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractTextSearch.java@ 24394

Last change on this file since 24394 was 24394, checked in by davidb, 13 years ago

Through the audioDB extension we now support a form of content-based audio/music searching. These commited changes reflect this generalization in our Service inheritance hierarchy for searching. Basically, what used to be thought of as a search service implied a *text* search service.

File size: 5.9 KB
Line 
1/*
2 * AbstractTextSearch.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 * 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
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.service;
20
21// Greenstone classes
22import org.greenstone.gsdl3.util.GSXML;
23import org.greenstone.gsdl3.util.GSPath;
24
25// XML classes
26import org.w3c.dom.Document;
27import org.w3c.dom.Element;
28import org.w3c.dom.NodeList;
29
30// java classes
31import java.util.ArrayList;
32import java.util.HashMap;
33
34import org.apache.log4j.*;
35
36/** Partially implements a generic search service
37 *
38 * @author <a href="mailto:[email protected]">Katherine Don</a>
39 */
40
41public abstract class AbstractTextSearch
42 extends AbstractSearch
43{
44
45 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractTextSearch.class.getName());
46
47
48 // optional standard params - some of these have to be implemented
49 protected static final String INDEX_SUBCOLLECTION_PARAM = "indexSubcollection";
50 protected static final String INDEX_LANGUAGE_PARAM = "indexLanguage";
51
52 protected static final String INDEX_SUBCOLLECTION_ELEM = "indexSubcollection";
53 protected static final String INDEX_LANGUAGE_ELEM = "indexLanguage";
54
55
56 // some other common params that may be used
57 protected static final String CASE_PARAM = "case";
58 protected static final String STEM_PARAM = "stem";
59 protected static final String ACCENT_PARAM="accent";
60
61 protected static final String BOOLEAN_PARAM_ON = "1";
62 protected static final String BOOLEAN_PARAM_OFF = "0";
63 protected static final String MATCH_PARAM = "matchMode";
64 protected static final String MATCH_PARAM_ALL = "all";
65 protected static final String MATCH_PARAM_SOME = "some";
66
67 protected String default_index_subcollection = "";
68
69 protected String default_index_language = "";
70
71 public AbstractTextSearch()
72 {
73 // the search service
74 QUERY_SERVICE = "TextQuery";
75 }
76
77
78 /** adds the standard query params into the service description */
79 protected void addStandardQueryParams(Element param_list, String lang)
80 {
81 if (!default_index_subcollection.equals("")){
82 createParameter(INDEX_SUBCOLLECTION_PARAM,param_list, lang);
83 }
84 if (!default_index_language.equals("")){
85 createParameter(INDEX_LANGUAGE_PARAM,param_list, lang);
86 }
87
88 super.addStandardQueryParams(param_list,lang);
89 }
90
91 /** Top up createParameterChain with TextQuery specific params:
92 * case, stem ...
93 */
94 protected boolean createParameterChain(String name, Element param_list, String lang, String default_value)
95 {
96 Element param = null;
97 String param_default = default_value;
98
99 if (super.createParameterChain(name,param_list,lang,default_value)) {
100 // found a match, so can stop here
101 return true;
102 }
103 // otherwise look to see if it is a text specific parameter
104 else if (name.equals(INDEX_SUBCOLLECTION_PARAM)){
105 Element index_sub_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_SUBCOLLECTION_ELEM+GSXML.LIST_MODIFIER);
106 if (index_sub_list == null) return true; // processed, just not a very interesting result
107 ArrayList index_sub_ids = new ArrayList();
108 ArrayList index_sub_names = new ArrayList();
109 getIndexSubcollectionData(index_sub_ids, index_sub_names, lang);
110 String param_type = GSXML.PARAM_TYPE_ENUM_SINGLE;
111 if (does_multi_index_search) {
112 param_type = GSXML.PARAM_TYPE_ENUM_MULTI;
113 }
114 if (param_default == null) {
115 param_default = this.default_index_subcollection;
116 }
117 param = GSXML.createParameterDescription2(this.doc, INDEX_SUBCOLLECTION_PARAM, getTextString("param."+INDEX_SUBCOLLECTION_PARAM, lang), param_type, param_default, index_sub_ids, index_sub_names);
118 param_list.appendChild(param);
119 return true;
120 }
121 else if(name.equals(INDEX_LANGUAGE_PARAM)){
122 Element index_lang_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_LANGUAGE_ELEM+GSXML.LIST_MODIFIER);
123 if (index_lang_list == null) return true; // processed, just not a very interesting result
124 ArrayList index_lang_ids = new ArrayList();
125 ArrayList index_lang_names = new ArrayList();
126 getIndexLanguageData(index_lang_ids, index_lang_names, lang);
127 String param_type = GSXML.PARAM_TYPE_ENUM_SINGLE;
128 if (does_multi_index_search) {
129 param_type = GSXML.PARAM_TYPE_ENUM_MULTI;
130 }
131 if (param_default == null) {
132 param_default = this.default_index_language;
133 }
134 param = GSXML.createParameterDescription2(this.doc, INDEX_LANGUAGE_PARAM, getTextString("param."+INDEX_LANGUAGE_PARAM, lang), param_type, param_default, index_lang_ids, index_lang_names);
135 param_list.appendChild(param);
136 return true;
137 }
138
139 // Get to there then none of the above params matched
140 // => return false so the chain can continue
141 return false;
142
143 }
144
145 /** do the actual query
146 * must be implemented by subclass */
147 abstract protected Element processTextQuery(Element request);
148
149 /** get the details about the indexexSubcollections available
150 * might be implemented by subclass
151 */
152 protected void getIndexSubcollectionData(ArrayList index_ids, ArrayList index_names, String lang){}
153
154 /** get the details about the indexes available
155 * might be implemented by subclass
156 */
157 protected void getIndexLanguageData(ArrayList index_ids, ArrayList index_names, String lang){}
158
159
160}
161
Note: See TracBrowser for help on using the repository browser.