1 | /*
|
---|
2 | * AbstractGS2FieldSearch.java
|
---|
3 | * Copyright (C) 2006 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 | */
|
---|
18 | package org.greenstone.gsdl3.service;
|
---|
19 |
|
---|
20 | // Greenstone classes
|
---|
21 | import java.io.Serializable;
|
---|
22 | import java.util.ArrayList;
|
---|
23 | import java.util.HashMap;
|
---|
24 | import java.util.List;
|
---|
25 | import java.util.Map;
|
---|
26 |
|
---|
27 | import org.apache.log4j.Logger;
|
---|
28 | import org.greenstone.gsdl3.util.FacetWrapper;
|
---|
29 | import org.greenstone.gsdl3.util.GSXML;
|
---|
30 | import org.greenstone.gsdl3.util.XMLConverter;
|
---|
31 | import org.w3c.dom.Document;
|
---|
32 | import org.w3c.dom.Element;
|
---|
33 | import org.w3c.dom.NodeList;
|
---|
34 |
|
---|
35 | abstract public class AbstractGS2FieldSearch extends AbstractGS2TextSearch
|
---|
36 | {
|
---|
37 | // extra services offered by mgpp collections
|
---|
38 | protected static final String FIELD_QUERY_SERVICE = "FieldQuery";
|
---|
39 | protected static final String ADVANCED_FIELD_QUERY_SERVICE = "AdvancedFieldQuery";
|
---|
40 | protected static final String RAW_QUERY_SERVICE = "RawQuery";
|
---|
41 |
|
---|
42 | // extra parameters used
|
---|
43 | protected static final String LEVEL_PARAM = "level";
|
---|
44 | protected static final String RANK_PARAM = "sortBy";
|
---|
45 | protected static final String RANK_PARAM_RANK = "1";
|
---|
46 | protected static final String RANK_PARAM_NONE = "0";
|
---|
47 | protected static final String SIMPLE_FIELD_PARAM = "simpleField";
|
---|
48 | protected static final String ADVANCED_FIELD_PARAM = "complexField";
|
---|
49 |
|
---|
50 | protected static final String RAW_PARAM = "rawquery";
|
---|
51 |
|
---|
52 | // more params for field query
|
---|
53 | protected static final String FIELD_QUERY_PARAM = "fqv";
|
---|
54 | protected static final String FIELD_STEM_PARAM = "fqs";
|
---|
55 | protected static final String FIELD_CASE_PARAM = "fqc";
|
---|
56 | protected static final String FIELD_ACCENT_PARAM = "fqa";
|
---|
57 | protected static final String FIELD_FIELD_PARAM = "fqf";
|
---|
58 | protected static final String FIELD_COMBINE_PARAM = "fqk";
|
---|
59 | protected static final String FIELD_COMBINE_PARAM_AND = "0";
|
---|
60 | protected static final String FIELD_COMBINE_PARAM_OR = "1";
|
---|
61 | protected static final String FIELD_COMBINE_PARAM_NOT = "2";
|
---|
62 |
|
---|
63 | // some stuff for config files
|
---|
64 | protected static final String SEARCH_TYPE_ELEM = "searchType";
|
---|
65 | protected static final String SEARCH_TYPE_PLAIN = "plain";
|
---|
66 | protected static final String SEARCH_TYPE_SIMPLE_FORM = "simpleform";
|
---|
67 | protected static final String SEARCH_TYPE_ADVANCED_FORM = "advancedform";
|
---|
68 | protected static final String SEARCH_TYPE_RAW = "raw";
|
---|
69 |
|
---|
70 | protected static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
|
---|
71 | protected static final String DEFAULT_DB_LEVEL_ELEM = "defaultDBLevel";
|
---|
72 | protected static final String LEVEL_ELEM = "level";
|
---|
73 | protected static final String FIELD_ATT = "field";
|
---|
74 |
|
---|
75 | protected static final int TEXT_QUERY = 0;
|
---|
76 | protected static final int SIMPLE_QUERY = 1;
|
---|
77 | protected static final int ADVANCED_QUERY = 2;
|
---|
78 | protected static final int RAW_QUERY = 3;
|
---|
79 |
|
---|
80 | protected String AND_OPERATOR = "&";
|
---|
81 | protected String OR_OPERATOR = "|";
|
---|
82 | protected String NOT_OPERATOR = "!";
|
---|
83 |
|
---|
84 | // the default level for searching
|
---|
85 | protected String default_level = null;
|
---|
86 | // default level for collection db
|
---|
87 | protected String default_db_level = null;
|
---|
88 | // metadata for service, such as does_paging = true
|
---|
89 | protected Element service_metadata_list = null;
|
---|
90 | // which search services will we offer??
|
---|
91 | protected boolean plain_search = false;
|
---|
92 | protected boolean simple_form_search = false;
|
---|
93 | protected boolean advanced_form_search = false;
|
---|
94 | protected boolean raw_search = false;
|
---|
95 | //Parameters to get full field with highlighted terms
|
---|
96 | protected String hldocOID = null;
|
---|
97 | //index Field for highlighting
|
---|
98 | protected String indexField = null;
|
---|
99 |
|
---|
100 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2FieldSearch.class.getName());
|
---|
101 |
|
---|
102 | /** constructor */
|
---|
103 | public AbstractGS2FieldSearch()
|
---|
104 | {
|
---|
105 | super();
|
---|
106 | paramDefaults.put(RANK_PARAM, RANK_PARAM_RANK);
|
---|
107 | paramDefaults.put(FIELD_COMBINE_PARAM, FIELD_COMBINE_PARAM_AND);
|
---|
108 | // paramDefaults.put(FIELD_CASE_PARAM, BOOLEAN_PARAM_ON);
|
---|
109 | // paramDefaults.put(FIELD_STEM_PARAM, BOOLEAN_PARAM_OFF);
|
---|
110 | // paramDefaults.put(FIELD_ACCENT_PARAM, BOOLEAN_PARAM_ON);
|
---|
111 | }
|
---|
112 |
|
---|
113 | public void cleanUp()
|
---|
114 | {
|
---|
115 | super.cleanUp();
|
---|
116 | }
|
---|
117 |
|
---|
118 | /** configure this service */
|
---|
119 | public boolean configure(Element info, Element extra_info)
|
---|
120 | {
|
---|
121 | if (!super.configure(info, extra_info))
|
---|
122 | {
|
---|
123 | return false;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // Get the default level out of <defaultLevel> (buildConfig.xml)
|
---|
127 | Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
|
---|
128 | if (def != null)
|
---|
129 | {
|
---|
130 | this.default_level = def.getAttribute(GSXML.SHORTNAME_ATT);
|
---|
131 | }
|
---|
132 | if (this.default_level == null || this.default_level.equals(""))
|
---|
133 | {
|
---|
134 | logger.error("default level not specified!, assuming Doc");
|
---|
135 | this.default_level = "Doc";
|
---|
136 | }
|
---|
137 |
|
---|
138 | // Get the default DB level
|
---|
139 | def = (Element) GSXML.getChildByTagName(info, DEFAULT_DB_LEVEL_ELEM);
|
---|
140 | if (def != null)
|
---|
141 | {
|
---|
142 | this.default_db_level = def.getAttribute(GSXML.SHORTNAME_ATT);
|
---|
143 | }
|
---|
144 | if (this.default_db_level == null || this.default_db_level.equals(""))
|
---|
145 | {
|
---|
146 | logger.error("default database level (defaultDBLevel) not specified!, assuming Sec");
|
---|
147 | this.default_db_level = "Sec";
|
---|
148 | }
|
---|
149 |
|
---|
150 | // get stuff from from extra info (which is collectionConfig.xml)
|
---|
151 | if (extra_info != null)
|
---|
152 | {
|
---|
153 |
|
---|
154 | // the search element
|
---|
155 | Element config_search = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
|
---|
156 |
|
---|
157 | NodeList search_types = config_search.getElementsByTagName(SEARCH_TYPE_ELEM);
|
---|
158 | if (search_types == null)
|
---|
159 | {
|
---|
160 | // none specified, assume plain only
|
---|
161 | this.plain_search = true;
|
---|
162 | }
|
---|
163 | else
|
---|
164 | {
|
---|
165 | for (int i = 0; i < search_types.getLength(); i++)
|
---|
166 | {
|
---|
167 | Element t = (Element) search_types.item(i);
|
---|
168 |
|
---|
169 | String type_name = t.getAttribute(GSXML.NAME_ATT);
|
---|
170 | if (type_name.equals(SEARCH_TYPE_PLAIN))
|
---|
171 | {
|
---|
172 | this.plain_search = true;
|
---|
173 | }
|
---|
174 | else if (type_name.equals(SEARCH_TYPE_SIMPLE_FORM))
|
---|
175 | {
|
---|
176 | this.simple_form_search = true;
|
---|
177 | }
|
---|
178 | else if (type_name.equals(SEARCH_TYPE_ADVANCED_FORM))
|
---|
179 | {
|
---|
180 | this.advanced_form_search = true;
|
---|
181 | }
|
---|
182 | else if (type_name.equals(SEARCH_TYPE_RAW))
|
---|
183 | {
|
---|
184 | this.raw_search = true;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | // AbstractGS2TextSearch has set up the TextQuery service, but we may not want it
|
---|
190 | if (!this.plain_search)
|
---|
191 | {
|
---|
192 | // need to remove the TextQuery service
|
---|
193 | Element tq_service = GSXML.getNamedElement(short_service_info, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, QUERY_SERVICE);
|
---|
194 | short_service_info.removeChild(tq_service);
|
---|
195 | }
|
---|
196 |
|
---|
197 | Document owner = info.getOwnerDocument();
|
---|
198 |
|
---|
199 | NodeList levels = info.getElementsByTagName(GSXML.LEVEL_ELEM);
|
---|
200 |
|
---|
201 | for (int i = 0; i < levels.getLength(); i++)
|
---|
202 | {
|
---|
203 | Element lev = (Element) levels.item(i);
|
---|
204 | String name = lev.getAttribute(GSXML.NAME_ATT);
|
---|
205 | Element node_extra = GSXML.getNamedElement(config_search, GSXML.LEVEL_ELEM, GSXML.NAME_ATT, name);
|
---|
206 | if (node_extra == null)
|
---|
207 | {
|
---|
208 | logger.error("haven't found extra info for level named " + name);
|
---|
209 | continue;
|
---|
210 | }
|
---|
211 |
|
---|
212 | // get the display elements if any - displayName
|
---|
213 | NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
|
---|
214 | if (display_names != null)
|
---|
215 | {
|
---|
216 | for (int j = 0; j < display_names.getLength(); j++)
|
---|
217 | {
|
---|
218 | Element e = (Element) display_names.item(j);
|
---|
219 | lev.appendChild(owner.importNode(e, true));
|
---|
220 | }
|
---|
221 | }
|
---|
222 | } // for each level
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | // for soem reason we don't have the collectionConfig file. assume plain only
|
---|
227 | this.plain_search = true;
|
---|
228 | }
|
---|
229 |
|
---|
230 | // the format info is the same for all services
|
---|
231 | Element format_info = (Element) format_info_map.get(QUERY_SERVICE);
|
---|
232 |
|
---|
233 | // set up the extra services which are available for this collection
|
---|
234 | if (this.simple_form_search)
|
---|
235 | {
|
---|
236 | // set up short_service_info_ - for now just has id and type - name will be added in on the fly
|
---|
237 | Element fq_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
|
---|
238 | fq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
|
---|
239 | fq_service.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE);
|
---|
240 | this.short_service_info.appendChild(fq_service);
|
---|
241 |
|
---|
242 | if (format_info != null)
|
---|
243 | {
|
---|
244 | this.format_info_map.put(FIELD_QUERY_SERVICE, format_info);
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | if (this.advanced_form_search)
|
---|
249 | {
|
---|
250 | Element afq_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
|
---|
251 | afq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
|
---|
252 | afq_service.setAttribute(GSXML.NAME_ATT, ADVANCED_FIELD_QUERY_SERVICE);
|
---|
253 | this.short_service_info.appendChild(afq_service);
|
---|
254 |
|
---|
255 | if (format_info != null)
|
---|
256 | {
|
---|
257 | this.format_info_map.put(ADVANCED_FIELD_QUERY_SERVICE, format_info);
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (this.raw_search)
|
---|
262 | {
|
---|
263 | Element rq_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
|
---|
264 | rq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
|
---|
265 | rq_service.setAttribute(GSXML.NAME_ATT, RAW_QUERY_SERVICE);
|
---|
266 | this.short_service_info.appendChild(rq_service);
|
---|
267 |
|
---|
268 | if (format_info != null)
|
---|
269 | {
|
---|
270 | this.format_info_map.put(RAW_QUERY_SERVICE, format_info);
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | return true;
|
---|
275 | }
|
---|
276 |
|
---|
277 | // if field case/stem/accent defaults are not specified explicitly, we should use case/stem/accent defaults
|
---|
278 | protected void getSearchParamDefaults(Element search_elem) {
|
---|
279 |
|
---|
280 | boolean found_f_stem = false;
|
---|
281 | boolean found_f_case = false;
|
---|
282 | boolean found_f_accent = false;
|
---|
283 | NodeList param_defaults_list = GSXML.getChildrenByTagName(search_elem, GSXML.PARAM_DEFAULT_ELEM);
|
---|
284 | for (int i=0; i<param_defaults_list.getLength(); i++) {
|
---|
285 | Element paramdef = (Element)param_defaults_list.item(i);
|
---|
286 | String name = paramdef.getAttribute(GSXML.NAME_ATT);
|
---|
287 | String val = paramdef.getAttribute(GSXML.VALUE_ATT);
|
---|
288 | if (!name.equals("") && !val.equals("")) {
|
---|
289 | paramDefaults.put(name, val);
|
---|
290 | if (name.equals(FIELD_STEM_PARAM)) {
|
---|
291 | found_f_stem = true;
|
---|
292 | } else if (name.equals(FIELD_CASE_PARAM)) {
|
---|
293 | found_f_case = true;
|
---|
294 | } else if (name.equals(FIELD_ACCENT_PARAM)) {
|
---|
295 | found_f_accent = true;
|
---|
296 | }
|
---|
297 | if (!found_f_stem) {
|
---|
298 | paramDefaults.put (FIELD_STEM_PARAM, paramDefaults.get(STEM_PARAM));
|
---|
299 | }
|
---|
300 | if (!found_f_case) {
|
---|
301 | paramDefaults.put (FIELD_CASE_PARAM, paramDefaults.get(CASE_PARAM));
|
---|
302 | }
|
---|
303 | if (!found_f_accent) {
|
---|
304 | paramDefaults.put (FIELD_ACCENT_PARAM, paramDefaults.get(ACCENT_PARAM));
|
---|
305 | }
|
---|
306 |
|
---|
307 | }
|
---|
308 | }
|
---|
309 | }
|
---|
310 | protected Element getServiceDescription(Document doc, String service_id, String lang, String subset)
|
---|
311 | {
|
---|
312 | // should we check that the service is actually on offer? presumably we wont get asked for services that we haven't advertised previously.
|
---|
313 |
|
---|
314 | if (!service_id.equals(FIELD_QUERY_SERVICE) && !service_id.equals(ADVANCED_FIELD_QUERY_SERVICE) && !service_id.equals(RAW_QUERY_SERVICE))
|
---|
315 | {
|
---|
316 | return super.getServiceDescription(doc, service_id, lang, subset);
|
---|
317 | }
|
---|
318 |
|
---|
319 | Element service = doc.createElement(GSXML.SERVICE_ELEM);
|
---|
320 | service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
|
---|
321 | service.setAttribute(GSXML.NAME_ATT, service_id);
|
---|
322 | if (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER))
|
---|
323 | {
|
---|
324 | service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_NAME, getTextString(service_id + ".name", lang)));
|
---|
325 | service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_SUBMIT, getTextString(service_id + ".submit", lang)));
|
---|
326 | service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(service_id + ".description", lang)));
|
---|
327 |
|
---|
328 | }
|
---|
329 | if (subset == null || subset.equals(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER))
|
---|
330 | {
|
---|
331 | Element param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
332 | service.appendChild(param_list);
|
---|
333 | if (service_id.equals(FIELD_QUERY_SERVICE))
|
---|
334 | {
|
---|
335 |
|
---|
336 | addCustomQueryParams(param_list, lang);
|
---|
337 | if (!default_index_subcollection.equals(""))
|
---|
338 | {
|
---|
339 | createParameter(INDEX_SUBCOLLECTION_PARAM, param_list, lang);
|
---|
340 | }
|
---|
341 | if (!default_index_language.equals(""))
|
---|
342 | {
|
---|
343 | createParameter(INDEX_LANGUAGE_PARAM, param_list, lang);
|
---|
344 | }
|
---|
345 |
|
---|
346 | if (does_chunking) {
|
---|
347 | createParameter(MAXDOCS_PARAM, param_list, lang);
|
---|
348 | }
|
---|
349 | if (does_paging)
|
---|
350 | {
|
---|
351 | createParameter(HITS_PER_PAGE_PARAM, param_list, lang);
|
---|
352 | createParameter(START_PAGE_PARAM, param_list, lang);
|
---|
353 | }
|
---|
354 |
|
---|
355 | // create a multi param for the fields etc
|
---|
356 | // text box, field
|
---|
357 | Element multiparam = null;
|
---|
358 | Element param = null;
|
---|
359 | multiparam = GSXML.createParameterDescription(doc, SIMPLE_FIELD_PARAM, "", GSXML.PARAM_TYPE_MULTI, null, null, null);
|
---|
360 | multiparam.setAttribute("occurs", "4");
|
---|
361 | param_list.appendChild(multiparam);
|
---|
362 |
|
---|
363 | // the components
|
---|
364 |
|
---|
365 | createParameter(FIELD_QUERY_PARAM, multiparam, lang);
|
---|
366 | createParameter(FIELD_FIELD_PARAM, multiparam, lang);
|
---|
367 |
|
---|
368 | }
|
---|
369 | else if (service_id.equals(ADVANCED_FIELD_QUERY_SERVICE))
|
---|
370 | {
|
---|
371 | addCustomQueryParamsAdvField(param_list, lang);
|
---|
372 | if (!default_index_subcollection.equals(""))
|
---|
373 | {
|
---|
374 | createParameter(INDEX_SUBCOLLECTION_PARAM, param_list, lang);
|
---|
375 | }
|
---|
376 | if (!default_index_language.equals(""))
|
---|
377 | {
|
---|
378 | createParameter(INDEX_LANGUAGE_PARAM, param_list, lang);
|
---|
379 | }
|
---|
380 |
|
---|
381 | // create a multi param for the fields etc
|
---|
382 | // text box, stem, case, field
|
---|
383 |
|
---|
384 | Element multiparam = null;
|
---|
385 | Element param = null;
|
---|
386 |
|
---|
387 | multiparam = GSXML.createParameterDescription(doc, ADVANCED_FIELD_PARAM, "", GSXML.PARAM_TYPE_MULTI, null, null, null);
|
---|
388 | multiparam.setAttribute("occurs", "4");
|
---|
389 | param_list.appendChild(multiparam);
|
---|
390 |
|
---|
391 | createParameter(FIELD_COMBINE_PARAM, multiparam, lang);
|
---|
392 | createParameter(FIELD_QUERY_PARAM, multiparam, lang);
|
---|
393 | if (this.does_case)
|
---|
394 | {
|
---|
395 | createParameter(FIELD_CASE_PARAM, multiparam, lang);
|
---|
396 | }
|
---|
397 | if (this.does_stem)
|
---|
398 | {
|
---|
399 | createParameter(FIELD_STEM_PARAM, multiparam, lang);
|
---|
400 | }
|
---|
401 | if (this.does_accent)
|
---|
402 | {
|
---|
403 | createParameter(FIELD_ACCENT_PARAM, multiparam, lang);
|
---|
404 | }
|
---|
405 | if (does_chunking) {
|
---|
406 | createParameter(MAXDOCS_PARAM, param_list, lang);
|
---|
407 | }
|
---|
408 | if (does_paging)
|
---|
409 | {
|
---|
410 | createParameter(HITS_PER_PAGE_PARAM, param_list, lang);
|
---|
411 | createParameter(START_PAGE_PARAM, param_list, lang);
|
---|
412 | }
|
---|
413 | createParameter(FIELD_FIELD_PARAM, multiparam, lang);
|
---|
414 |
|
---|
415 | }
|
---|
416 | else if (service_id.equals(RAW_QUERY_SERVICE))
|
---|
417 | {
|
---|
418 | if (does_chunking)
|
---|
419 | {
|
---|
420 | createParameter(MAXDOCS_PARAM, param_list, lang);
|
---|
421 | }
|
---|
422 | if (does_paging)
|
---|
423 | {
|
---|
424 | createParameter(HITS_PER_PAGE_PARAM, param_list, lang);
|
---|
425 | createParameter(START_PAGE_PARAM, param_list, lang);
|
---|
426 | }
|
---|
427 | createParameter(RAW_PARAM, param_list, lang);
|
---|
428 | service.appendChild(param_list);
|
---|
429 | }
|
---|
430 | }
|
---|
431 | if (subset == null || subset.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER)) {
|
---|
432 | if (service_metadata_list == null) {
|
---|
433 | Document ml_doc = XMLConverter.newDOM();
|
---|
434 | service_metadata_list = ml_doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
|
---|
435 | if (does_paging) {
|
---|
436 | service_metadata_list.appendChild(GSXML.createMetadataElement(ml_doc, "does_paging", "true"));
|
---|
437 | }
|
---|
438 | }
|
---|
439 | service.appendChild(doc.importNode(service_metadata_list, true));
|
---|
440 | }
|
---|
441 | return service;
|
---|
442 |
|
---|
443 | }
|
---|
444 |
|
---|
445 | /** add in the level params to TextQuery */
|
---|
446 | protected void addCustomQueryParams(Element param_list, String lang)
|
---|
447 | {
|
---|
448 | createParameter(LEVEL_PARAM, param_list, lang);
|
---|
449 | super.addCustomQueryParams(param_list, lang);
|
---|
450 | }
|
---|
451 | /** add in the level params to TextQuery */
|
---|
452 | protected void addCustomQueryParamsAdvField(Element param_list, String lang)
|
---|
453 | {
|
---|
454 | createParameter(LEVEL_PARAM, param_list, lang);
|
---|
455 | }
|
---|
456 |
|
---|
457 | /** create a param and add to the list */
|
---|
458 | protected void createParameter(String name, Element param_list, String lang)
|
---|
459 | {
|
---|
460 | Document doc = param_list.getOwnerDocument();
|
---|
461 | Element param = null;
|
---|
462 | String param_default = paramDefaults.get(name);
|
---|
463 | if (name.equals(LEVEL_PARAM))
|
---|
464 | {
|
---|
465 | ArrayList<String> level_ids = new ArrayList<String>();
|
---|
466 | ArrayList<String> level_names = new ArrayList<String>();
|
---|
467 | getLevelData(level_ids, level_names, lang);
|
---|
468 | if (level_ids.size() > 1)
|
---|
469 | {
|
---|
470 | // the first one is the default
|
---|
471 | //param = GSXML.createParameterDescription2(doc, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)level_ids.get(0), level_ids, level_names);
|
---|
472 | param = GSXML.createParameterDescription2(doc, LEVEL_PARAM, getTextString("param." + LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, this.default_level, level_ids, level_names);
|
---|
473 | }
|
---|
474 | else
|
---|
475 | {
|
---|
476 | // we need to set the level, but hidden, in case there is an invalid level saved
|
---|
477 | //param = GSXML.createParameterDescription(doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, (String)level_ids.get(0), null, null);
|
---|
478 | param = GSXML.createParameterDescription(doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, this.default_level, null, null);
|
---|
479 | }
|
---|
480 | }
|
---|
481 | else if (name.equals(RANK_PARAM))
|
---|
482 | {
|
---|
483 | String[] vals1 = { RANK_PARAM_RANK, RANK_PARAM_NONE };
|
---|
484 | String[] vals1_texts = { getTextString("param." + RANK_PARAM + "." + RANK_PARAM_RANK, lang), getTextString("param." + RANK_PARAM + "." + RANK_PARAM_NONE, lang) };
|
---|
485 |
|
---|
486 | param = GSXML.createParameterDescription(doc, RANK_PARAM, getTextString("param." + RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, param_default, vals1, vals1_texts);
|
---|
487 |
|
---|
488 | }
|
---|
489 | else if (name.equals(FIELD_QUERY_PARAM))
|
---|
490 | {
|
---|
491 | param = GSXML.createParameterDescription(doc, FIELD_QUERY_PARAM, getTextString("param." + FIELD_QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
|
---|
492 |
|
---|
493 | }
|
---|
494 | else if (name.equals(FIELD_CASE_PARAM) || name.equals(FIELD_STEM_PARAM) || name.equals(FIELD_ACCENT_PARAM))
|
---|
495 | {
|
---|
496 | String[] bool_ops = { "0", "1" };
|
---|
497 | String[] bool_texts = { getTextString("param.boolean.off", lang), getTextString("param.boolean.on", lang) };
|
---|
498 | param = GSXML.createParameterDescription(doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_BOOLEAN, param_default, bool_ops, bool_texts);
|
---|
499 |
|
---|
500 | }
|
---|
501 | else if (name.equals(FIELD_FIELD_PARAM))
|
---|
502 | {
|
---|
503 | ArrayList<String> fields = new ArrayList<String>();
|
---|
504 | ArrayList<String> field_names = new ArrayList<String>();
|
---|
505 | getIndexData(fields, field_names, lang);
|
---|
506 | // the field list - read from config file
|
---|
507 |
|
---|
508 | // Fix for http://trac.greenstone.org/ticket/245 "java crash, index out of bounds"
|
---|
509 | // org.greenstone.gsdl3.service.AbstractGS2FieldSearch.createParameter(AbstractGS2FieldSearch.java:362)
|
---|
510 | // Changed from:
|
---|
511 | // param = GSXML.createParameterDescription2(doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names );
|
---|
512 | String default_value = (fields.size() > 0) ? fields.get(0) : null;
|
---|
513 | // don't want to access element 0 if fields.size()==0, and
|
---|
514 | // GSXML.createParameterDescription2 checks for default_value==null condition
|
---|
515 | param = GSXML.createParameterDescription2(doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, default_value, fields, field_names);
|
---|
516 |
|
---|
517 | }
|
---|
518 | else if (name.equals(FIELD_COMBINE_PARAM))
|
---|
519 | {
|
---|
520 |
|
---|
521 | String[] vals = { FIELD_COMBINE_PARAM_AND, FIELD_COMBINE_PARAM_OR, FIELD_COMBINE_PARAM_NOT };
|
---|
522 | String[] val_texts = { getTextString("param." + FIELD_COMBINE_PARAM + "." + FIELD_COMBINE_PARAM_AND, lang), getTextString("param." + FIELD_COMBINE_PARAM + "." + FIELD_COMBINE_PARAM_OR, lang), getTextString("param." + FIELD_COMBINE_PARAM + "." + FIELD_COMBINE_PARAM_NOT, lang) };
|
---|
523 |
|
---|
524 | param = GSXML.createParameterDescription(doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, param_default, vals, val_texts);
|
---|
525 | param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
|
---|
526 | }
|
---|
527 |
|
---|
528 | if (param != null)
|
---|
529 | {
|
---|
530 | param_list.appendChild(param);
|
---|
531 | }
|
---|
532 | else
|
---|
533 | {
|
---|
534 | super.createParameter(name, param_list, lang);
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | // should cache some of this
|
---|
539 | protected void getLevelData(ArrayList<String> level_ids, ArrayList<String> level_names, String lang)
|
---|
540 | {
|
---|
541 | Element level_list = (Element) GSXML.getChildByTagName(this.config_info, LEVEL_ELEM + GSXML.LIST_MODIFIER);
|
---|
542 | NodeList levels = level_list.getElementsByTagName(LEVEL_ELEM);
|
---|
543 | for (int i = 0; i < levels.getLength(); i++)
|
---|
544 | {
|
---|
545 | Element level = (Element) levels.item(i);
|
---|
546 | String shortname = level.getAttribute(GSXML.SHORTNAME_ATT);
|
---|
547 | if (shortname.equals(""))
|
---|
548 | {
|
---|
549 | continue;
|
---|
550 | }
|
---|
551 | level_ids.add(shortname);
|
---|
552 | String display_name = getDisplayText(level, GSXML.DISPLAY_TEXT_NAME, lang, "en");
|
---|
553 | if (display_name.equals(""))
|
---|
554 | {
|
---|
555 | // we'll use the name, and look it up in the dictionary
|
---|
556 | display_name = level.getAttribute(GSXML.NAME_ATT);
|
---|
557 | if (display_name.equals(""))
|
---|
558 | {
|
---|
559 | display_name = shortname;
|
---|
560 | }
|
---|
561 | else
|
---|
562 | {
|
---|
563 | display_name = getTextString("level." + display_name, lang);
|
---|
564 | }
|
---|
565 | }
|
---|
566 | level_names.add(display_name);
|
---|
567 | }
|
---|
568 | }
|
---|
569 |
|
---|
570 | // the following three functions are needed so the base class can
|
---|
571 | // call the process+SERVICE_NAME methods
|
---|
572 | /** process a text query */
|
---|
573 | protected Element processTextQuery(Element request)
|
---|
574 | {
|
---|
575 | return processAnyQuery(request, TEXT_QUERY);
|
---|
576 | }
|
---|
577 |
|
---|
578 | /** process a field query */
|
---|
579 | protected Element processFieldQuery(Element request)
|
---|
580 | {
|
---|
581 | return processAnyQuery(request, SIMPLE_QUERY);
|
---|
582 | }
|
---|
583 |
|
---|
584 | /** process an advanced field query */
|
---|
585 | protected Element processAdvancedFieldQuery(Element request)
|
---|
586 | {
|
---|
587 | return processAnyQuery(request, ADVANCED_QUERY);
|
---|
588 | }
|
---|
589 |
|
---|
590 | protected Element processRawQuery(Element request)
|
---|
591 | {
|
---|
592 | return processAnyQuery(request, RAW_QUERY);
|
---|
593 | }
|
---|
594 |
|
---|
595 | /** process a query */
|
---|
596 | protected Element processAnyQuery(Element request, int query_type)
|
---|
597 | {
|
---|
598 |
|
---|
599 | String service_name = null;
|
---|
600 | String empty_query_test_param = null;
|
---|
601 | // set up the type specific bits
|
---|
602 | switch (query_type)
|
---|
603 | {
|
---|
604 | case TEXT_QUERY:
|
---|
605 | service_name = QUERY_SERVICE;
|
---|
606 | empty_query_test_param = QUERY_PARAM;
|
---|
607 | break;
|
---|
608 | case SIMPLE_QUERY:
|
---|
609 | service_name = FIELD_QUERY_SERVICE;
|
---|
610 | empty_query_test_param = FIELD_QUERY_PARAM;
|
---|
611 | break;
|
---|
612 | case ADVANCED_QUERY:
|
---|
613 | service_name = ADVANCED_FIELD_QUERY_SERVICE;
|
---|
614 | empty_query_test_param = FIELD_QUERY_PARAM;
|
---|
615 | break;
|
---|
616 | case RAW_QUERY:
|
---|
617 | service_name = RAW_QUERY_SERVICE;
|
---|
618 | empty_query_test_param = RAW_PARAM;
|
---|
619 | break;
|
---|
620 | default:
|
---|
621 | // should never get here
|
---|
622 | logger.error("wrong query type!!");
|
---|
623 | return null;
|
---|
624 | }
|
---|
625 |
|
---|
626 | // Create a new (empty) result message
|
---|
627 | Document result_doc = XMLConverter.newDOM();
|
---|
628 | Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
629 | result.setAttribute(GSXML.FROM_ATT, service_name);
|
---|
630 | result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
|
---|
631 |
|
---|
632 | // Get the parameters of the request
|
---|
633 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
634 | if (param_list == null)
|
---|
635 | {
|
---|
636 | logger.error("TextQuery request had no paramList.");
|
---|
637 | return result; // Return the empty result
|
---|
638 | }
|
---|
639 |
|
---|
640 | // Process the request parameters
|
---|
641 |
|
---|
642 | HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
|
---|
643 | //Save as variable to make it accessable from GS2SolrSearch
|
---|
644 | hldocOID = (String) params.get("hldocOID");
|
---|
645 | //System.out.println("@@@@@Extracted hldocOID is " + hldocOID);
|
---|
646 | // Make sure a query has been specified
|
---|
647 | String query = (String) params.get(empty_query_test_param);
|
---|
648 | if (query == null || query.equals(""))
|
---|
649 | {
|
---|
650 | return result; // Return the empty result
|
---|
651 | }
|
---|
652 |
|
---|
653 | // If a field hasn't been specified, use the default - for textQuery
|
---|
654 | String field = (String) params.get(INDEX_PARAM);
|
---|
655 | //Save as variable to make it accessable from GS2SolrSearch
|
---|
656 |
|
---|
657 | if (field == null)
|
---|
658 | {
|
---|
659 | field = default_index;
|
---|
660 | }
|
---|
661 | indexField = field;
|
---|
662 | // set up the appropriate query system
|
---|
663 | if (!setUpQueryer(params))
|
---|
664 | {
|
---|
665 | return result;
|
---|
666 | }
|
---|
667 |
|
---|
668 | // if field search, create the query string
|
---|
669 | switch (query_type)
|
---|
670 | {
|
---|
671 | case TEXT_QUERY:
|
---|
672 | query = addFieldInfo(query, field);
|
---|
673 | break;
|
---|
674 | case SIMPLE_QUERY:
|
---|
675 | query = parseFieldQueryParams(params);
|
---|
676 | break;
|
---|
677 | case ADVANCED_QUERY:
|
---|
678 | query = parseAdvancedFieldQueryParams(params);
|
---|
679 | break;
|
---|
680 | }
|
---|
681 |
|
---|
682 | // run the query
|
---|
683 | Object query_result = runQuery(query);
|
---|
684 |
|
---|
685 | // We want highlighted text to be returned right now!
|
---|
686 | if (hldocOID != null && does_full_field_highlighting)
|
---|
687 | {
|
---|
688 | Element nodeContentElement = result_doc.createElement(GSXML.NODE_CONTENT_ELEM);
|
---|
689 | nodeContentElement.setTextContent((String) query_result);
|
---|
690 | result.appendChild(nodeContentElement);
|
---|
691 | return result;
|
---|
692 | }
|
---|
693 |
|
---|
694 |
|
---|
695 | // build up the response
|
---|
696 |
|
---|
697 | // Create a metadata list to store information about the query results
|
---|
698 | // should we be using metadataList? or something else?
|
---|
699 | Element metadata_list = result_doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
|
---|
700 | result.appendChild(metadata_list);
|
---|
701 |
|
---|
702 | // Add a metadata element specifying the number of matching documents
|
---|
703 | long totalDocs = numDocsMatched(query_result);
|
---|
704 |
|
---|
705 | GSXML.addMetadata(metadata_list, "numDocsMatched", "" + totalDocs);
|
---|
706 |
|
---|
707 | // Create a document list to store the matching documents, and add them
|
---|
708 | String[] docs = getDocIDs(query_result);
|
---|
709 | String[] doc_ranks = getDocRanks(query_result);
|
---|
710 |
|
---|
711 | // add a metadata item to specify docs returned
|
---|
712 | if (does_chunking) // this means we have a max docs param, and might ask for only a subset of results
|
---|
713 | {
|
---|
714 | logger.error("does_chunking = true");
|
---|
715 | int docs_returned = docs.length;
|
---|
716 | String maxdocs_str = (String) params.get(MAXDOCS_PARAM);
|
---|
717 | if (maxdocs_str != null)
|
---|
718 | {
|
---|
719 | int maxdocs = Integer.parseInt(maxdocs_str);
|
---|
720 | if (maxdocs > 0) { // maxdocs==-1 means return all
|
---|
721 | docs_returned = (maxdocs < (int) totalDocs ? maxdocs : (int) totalDocs);
|
---|
722 | }
|
---|
723 | }
|
---|
724 | GSXML.addMetadata(metadata_list, "numDocsReturned", "" + docs_returned);
|
---|
725 | }
|
---|
726 |
|
---|
727 | Map<String, Map<String, List<String>>> hlResults = null;
|
---|
728 | if (does_highlight_snippets)
|
---|
729 | {
|
---|
730 | hlResults = getHighlightSnippets(query_result);
|
---|
731 | }
|
---|
732 |
|
---|
733 | // add a metadata item to specify what actual query was done - eg if stuff was stripped out etc. and then we can use the query later, cos we don't know which parameter was the query
|
---|
734 | GSXML.addMetadata(metadata_list, "query", query);
|
---|
735 | if (docs.length > 0)
|
---|
736 | {
|
---|
737 | Element document_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
738 | result.appendChild(document_list);
|
---|
739 | Element snippet_list = result_doc.createElement(GSXML.HL_SNIPPET_ELEM + GSXML.LIST_MODIFIER);
|
---|
740 | result.appendChild(snippet_list);
|
---|
741 | for (int d = 0; d < docs.length; d++)
|
---|
742 | {
|
---|
743 | String doc_id = internalNum2OID(docs[d]);
|
---|
744 | Element doc_node = createDocNode(result_doc, doc_id, doc_ranks[d]);
|
---|
745 | if (hlResults != null && hlResults.get(docs[d]) != null && hlResults.get(docs[d]).get(indexField) != null) {
|
---|
746 | for (String snippet : hlResults.get(docs[d]).get(indexField)){
|
---|
747 | //remove html tags
|
---|
748 | snippet = snippet.replaceAll("\\<.*?>", "");
|
---|
749 | //remove truncated tags
|
---|
750 | snippet = snippet.replaceAll(".*>", "");
|
---|
751 | snippet = snippet.replaceAll("\\<.*", "");
|
---|
752 | //remove unwanted symbols at start of line
|
---|
753 | snippet = snippet.replaceAll("^[ .,»):;-â]+", "");
|
---|
754 | //highlighting tags transformation
|
---|
755 | snippet = snippet.replaceAll("<", "<");
|
---|
756 | snippet = snippet.replaceAll(">", ">");
|
---|
757 | Element snippet_node = result_doc.createElement(GSXML.HL_SNIPPET_ELEM);
|
---|
758 | snippet_node.setAttribute(GSXML.NODE_ID_ATT, doc_id);
|
---|
759 | snippet_node.setTextContent(snippet);
|
---|
760 | snippet_list.appendChild(snippet_node);
|
---|
761 | }
|
---|
762 | }
|
---|
763 | document_list.appendChild(doc_node);
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 | // Create a term list to store the term information, and add it
|
---|
768 | Element term_list = result_doc.createElement(GSXML.TERM_ELEM + GSXML.LIST_MODIFIER);
|
---|
769 | result.appendChild(term_list);
|
---|
770 | addTermInfo(term_list, params, query_result);
|
---|
771 |
|
---|
772 | if(does_faceting)
|
---|
773 | {
|
---|
774 | ArrayList<FacetWrapper> facets = getFacets(query_result);
|
---|
775 | if(facets != null)
|
---|
776 | {
|
---|
777 | Element facet_list = result_doc.createElement(GSXML.FACET_ELEM + GSXML.LIST_MODIFIER);
|
---|
778 | result.appendChild(facet_list);
|
---|
779 |
|
---|
780 | for(FacetWrapper currentFacet : facets)
|
---|
781 | {
|
---|
782 | Element facet_elem = result_doc.createElement(GSXML.FACET_ELEM);
|
---|
783 | facet_elem.setAttribute(GSXML.NAME_ATT, currentFacet.getName());
|
---|
784 | facet_list.appendChild(facet_elem);
|
---|
785 |
|
---|
786 | HashMap<String, Long> countMap = currentFacet.getCounts();
|
---|
787 |
|
---|
788 | for(String countName : countMap.keySet())
|
---|
789 | {
|
---|
790 | long countValue = countMap.get(countName);
|
---|
791 | if(countValue > 0)
|
---|
792 | {
|
---|
793 | Element count_elem = result_doc.createElement(GSXML.COUNT_ELEM);
|
---|
794 | count_elem.setAttribute(GSXML.NAME_ATT, countName);
|
---|
795 | count_elem.setTextContent("" + countValue);
|
---|
796 |
|
---|
797 | facet_elem.appendChild(count_elem);
|
---|
798 | }
|
---|
799 | }
|
---|
800 | }
|
---|
801 | }
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | return result;
|
---|
806 |
|
---|
807 | }
|
---|
808 |
|
---|
809 | /** methods to handle actually doing the query */
|
---|
810 | /** do any initialisation of the query object */
|
---|
811 | abstract protected boolean setUpQueryer(HashMap<String, Serializable> params);
|
---|
812 |
|
---|
813 | /** do the query */
|
---|
814 | abstract protected Object runQuery(String query);
|
---|
815 |
|
---|
816 | /** get the total number of docs that match */
|
---|
817 | abstract protected long numDocsMatched(Object query_result);
|
---|
818 |
|
---|
819 | /** get the list of doc ids */
|
---|
820 | abstract protected String[] getDocIDs(Object query_result);
|
---|
821 |
|
---|
822 | /** get the list of doc ranks */
|
---|
823 | abstract protected String[] getDocRanks(Object query_result);
|
---|
824 |
|
---|
825 | /** get the list of facets */
|
---|
826 | abstract protected ArrayList<FacetWrapper> getFacets(Object query_result);
|
---|
827 |
|
---|
828 | /** get the map of highlighting snippets */
|
---|
829 | abstract protected Map<String, Map<String, List<String>>> getHighlightSnippets(Object query_result);
|
---|
830 |
|
---|
831 | /** add in term info if available */
|
---|
832 | abstract protected boolean addTermInfo(Element term_list, HashMap<String, Serializable> params, Object query_result);
|
---|
833 |
|
---|
834 | /**
|
---|
835 | * combines all the field params into a single query - for simple field
|
---|
836 | * query
|
---|
837 | */
|
---|
838 | /** We assume the combination (AND/OR) is done by the match param */
|
---|
839 | protected String parseFieldQueryParams(HashMap<String, Serializable> params)
|
---|
840 | {
|
---|
841 |
|
---|
842 | StringBuffer final_query = new StringBuffer(256);
|
---|
843 | String text_line = (String) params.get(FIELD_QUERY_PARAM);
|
---|
844 | String[] texts = text_line.split(",", -1);
|
---|
845 | String field_line = (String) params.get(FIELD_FIELD_PARAM);
|
---|
846 | String[] fields = field_line.split(",", -1);
|
---|
847 |
|
---|
848 | for (int i = 0; i < texts.length; i++)
|
---|
849 | {
|
---|
850 | String q = texts[i].trim();
|
---|
851 | if (!q.equals(""))
|
---|
852 | {
|
---|
853 | final_query.append(" " + addFieldInfo(q, fields[i]));
|
---|
854 | }
|
---|
855 | }
|
---|
856 |
|
---|
857 | return final_query.toString();
|
---|
858 | }
|
---|
859 |
|
---|
860 | abstract protected String addFieldInfo(String query, String field);
|
---|
861 |
|
---|
862 | /**
|
---|
863 | * combines all the field params into a single query - for advanced field
|
---|
864 | * query
|
---|
865 | */
|
---|
866 | protected String parseAdvancedFieldQueryParams(HashMap<String, Serializable> params)
|
---|
867 | {
|
---|
868 |
|
---|
869 | StringBuffer final_query = new StringBuffer(256);
|
---|
870 | String text_line = (String) params.get(FIELD_QUERY_PARAM);
|
---|
871 | String[] texts = text_line.split(",", -1);
|
---|
872 | String field_line = (String) params.get(FIELD_FIELD_PARAM);
|
---|
873 | String[] fields = field_line.split(",", -1);
|
---|
874 | String[] cases = null;
|
---|
875 | String[] stems = null;
|
---|
876 | String[] accents = null;
|
---|
877 | if (does_case)
|
---|
878 | {
|
---|
879 | String case_line = (String) params.get(FIELD_CASE_PARAM);
|
---|
880 | if (case_line != null)
|
---|
881 | cases = case_line.split(",", -1);
|
---|
882 | }
|
---|
883 | if (does_stem)
|
---|
884 | {
|
---|
885 | String stem_line = (String) params.get(FIELD_STEM_PARAM);
|
---|
886 | if (stem_line != null)
|
---|
887 | stems = stem_line.split(",", -1);
|
---|
888 | }
|
---|
889 | if (does_accent)
|
---|
890 | {
|
---|
891 | String accent_line = (String) params.get(FIELD_ACCENT_PARAM);
|
---|
892 | if (accent_line != null)
|
---|
893 | accents = accent_line.split(",", -1);
|
---|
894 | }
|
---|
895 | String combine_line = (String) params.get(FIELD_COMBINE_PARAM);
|
---|
896 | String[] combines = combine_line.split(",", -1);
|
---|
897 | String combine = "";
|
---|
898 | for (int i = 0; i < texts.length; i++)
|
---|
899 | {
|
---|
900 | if (i == 0)
|
---|
901 | {// assume first one is blank
|
---|
902 | combine = "";
|
---|
903 | }
|
---|
904 | else
|
---|
905 | {
|
---|
906 | String x = combines[i];
|
---|
907 | if (x.equals(FIELD_COMBINE_PARAM_AND))
|
---|
908 | {
|
---|
909 | combine = AND_OPERATOR;
|
---|
910 | }
|
---|
911 | else if (x.equals(FIELD_COMBINE_PARAM_OR))
|
---|
912 | {
|
---|
913 | combine = OR_OPERATOR;
|
---|
914 | }
|
---|
915 | else if (x.equals(FIELD_COMBINE_PARAM_NOT))
|
---|
916 | {
|
---|
917 | combine = NOT_OPERATOR;
|
---|
918 | }
|
---|
919 |
|
---|
920 | }
|
---|
921 |
|
---|
922 | String q = texts[i].trim();
|
---|
923 | boolean modified = false;
|
---|
924 | if (!q.equals(""))
|
---|
925 | {
|
---|
926 | String c = null;
|
---|
927 | String s = null;
|
---|
928 | String a = null;
|
---|
929 | if (does_case)
|
---|
930 | {
|
---|
931 | modified = true;
|
---|
932 | c = cases[i];
|
---|
933 | }
|
---|
934 | if (does_stem)
|
---|
935 | {
|
---|
936 | modified = true;
|
---|
937 | s = stems[i];
|
---|
938 | }
|
---|
939 | if (does_accent)
|
---|
940 | {
|
---|
941 | modified = true;
|
---|
942 | a = accents[i];
|
---|
943 | }
|
---|
944 | if (modified)
|
---|
945 | {
|
---|
946 | q = addStemOptions(q, s, c, a);
|
---|
947 | }
|
---|
948 | addQueryElem(final_query, q, fields[i], combine);
|
---|
949 | }
|
---|
950 | }
|
---|
951 | return final_query.toString();
|
---|
952 | }
|
---|
953 |
|
---|
954 | abstract protected void addQueryElem(StringBuffer final_query, String query, String field, String combine);
|
---|
955 |
|
---|
956 | abstract protected String addStemOptions(String query, String stem, String casef, String accent);
|
---|
957 |
|
---|
958 | }
|
---|