source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java@ 13975

Last change on this file since 13975 was 13975, checked in by kjdon, 17 years ago

check for null maxdocs param before converting to int

  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
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 */
18package org.greenstone.gsdl3.service;
19
20
21// Greenstone classes
22import org.greenstone.mgpp.*;
23import org.greenstone.gsdl3.util.*;
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.Iterator;
32import java.util.Set;
33import java.util.HashMap;
34import java.util.Map;
35import java.util.ArrayList;
36import java.util.Vector;
37import java.io.File;
38
39import org.apache.log4j.*;
40
41
42abstract public class AbstractGS2FieldSearch
43 extends AbstractGS2Search
44{
45
46 // extra services offered by mgpp collections
47 protected static final String FIELD_QUERY_SERVICE = "FieldQuery";
48 protected static final String ADVANCED_FIELD_QUERY_SERVICE = "AdvancedFieldQuery";
49
50 // extra parameters used
51 protected static final String LEVEL_PARAM = "level";
52 protected static final String RANK_PARAM = "sortBy";
53 protected static final String RANK_PARAM_RANK = "1";
54 protected static final String RANK_PARAM_NONE = "0";
55 protected static final String SIMPLE_FIELD_PARAM = "simpleField";
56 protected static final String ADVANCED_FIELD_PARAM = "complexField";
57
58 // more params for field query
59 protected static final String FIELD_QUERY_PARAM = "fqv";
60 protected static final String FIELD_STEM_PARAM = "fqs";
61 protected static final String FIELD_CASE_PARAM = "fqc";
62 protected static final String FIELD_ACCENT_PARAM="fqa";
63 protected static final String FIELD_FIELD_PARAM = "fqf";
64 protected static final String FIELD_COMBINE_PARAM = "fqk";
65 protected static final String FIELD_COMBINE_PARAM_AND = "0";
66 protected static final String FIELD_COMBINE_PARAM_OR = "1";
67 protected static final String FIELD_COMBINE_PARAM_NOT = "2";
68
69 // some stuff for config files
70 protected static final String SEARCH_TYPE_ELEM = "searchType";
71 protected static final String SEARCH_TYPE_PLAIN = "plain";
72 protected static final String SEARCH_TYPE_FORM = "form";
73 protected static final String SEARCH_TYPE_FORM_SIMPLE = "simple";
74 protected static final String SEARCH_TYPE_FORM_ADVANCED = "advanced";
75
76 protected static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
77 protected static final String DEFAULT_GDBM_LEVEL_ELEM = "defaultGDBMLevel";
78 protected static final String LEVEL_ELEM = "level";
79 protected static final String FIELD_ATT = "field";
80
81
82 protected static final int TEXT_QUERY = 0;
83 protected static final int SIMPLE_QUERY = 1;
84 protected static final int ADVANCED_QUERY = 2;
85
86 protected String AND_OPERATOR = "&";
87 protected String OR_OPERATOR = "|";
88 protected String NOT_OPERATOR = "!";
89
90 // the default level for searching
91 protected String default_level=null;
92 // default level for gdbm db
93 protected String default_gdbm_level = null;
94 // which search services will we offer??
95 protected boolean plain_search = false;
96 protected boolean simple_form_search = false;
97 protected boolean advanced_form_search = false;
98
99
100 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2FieldSearch.class.getName());
101
102 /** constructor */
103 public AbstractGS2FieldSearch()
104 {
105 }
106
107 public void cleanUp() {
108 super.cleanUp();
109 }
110
111 /** configure this service */
112 public boolean configure(Element info, Element extra_info)
113 {
114 if (!super.configure(info, extra_info)){
115 return false;
116 }
117 // the generic config has set up the text query service, but we may not want it
118 Element search_type_list = (Element) GSXML.getChildByTagName(info, SEARCH_TYPE_ELEM + GSXML.LIST_MODIFIER);
119 if (search_type_list == null) {
120 // assume form and plain
121 this.plain_search = true;
122 this.simple_form_search = true;
123 this.advanced_form_search = true;
124 } else {
125 NodeList types = search_type_list.getElementsByTagName(SEARCH_TYPE_ELEM);
126 for (int i=0; i<types.getLength(); i++) {
127 Element t = (Element)types.item(i);
128 String type_name = t.getAttribute(GSXML.NAME_ATT);
129 if (type_name.equals(SEARCH_TYPE_PLAIN)) {
130 this.plain_search = true;
131 } else if (type_name.equals(SEARCH_TYPE_FORM)) {
132 String type_type = t.getAttribute(GSXML.TYPE_ATT);
133 if (type_type.equals("")) {
134 this.simple_form_search = true;
135 this.advanced_form_search = true;
136 } else if (type_type.equals(SEARCH_TYPE_FORM_SIMPLE)) {
137 this.simple_form_search = true;
138 } else if (type_type.equals(SEARCH_TYPE_FORM_ADVANCED)) {
139 this.advanced_form_search = true;
140
141 }
142 }
143 }
144 }
145
146 if (!this.plain_search) {
147 // need to remove the TextQuery service
148 Element tq_service = GSXML.getNamedElement(short_service_info, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, TEXT_QUERY_SERVICE);
149 short_service_info.removeChild(tq_service);
150
151 }
152
153
154 // Get the default level out of <defaultLevel> (buildConfig.xml)
155 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
156 if (def != null) {
157 this.default_level = def.getAttribute(GSXML.SHORTNAME_ATT);
158 }
159 if (this.default_level == null || this.default_level.equals("")) {
160 logger.error("default level not specified!, assuming Doc");
161 this.default_level = "Doc";
162 }
163
164 // Get the default GDBM level
165 def = (Element) GSXML.getChildByTagName(info, DEFAULT_GDBM_LEVEL_ELEM);
166 if (def != null) {
167 this.default_gdbm_level = def.getAttribute(GSXML.SHORTNAME_ATT);
168 }
169 if (this.default_gdbm_level == null || this.default_gdbm_level.equals("")) {
170 logger.error("default gdbm level not specified!, assuming Sec");
171 this.default_gdbm_level = "Sec";
172 }
173
174 // get display info from extra info - for levels
175 if (extra_info !=null) {
176 Document owner = info.getOwnerDocument();
177
178 NodeList levels = info.getElementsByTagName(GSXML.LEVEL_ELEM);
179 Element config_search = (Element)GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
180
181 for (int i=0; i<levels.getLength();i++) {
182 Element lev = (Element)levels.item(i);
183 String name = lev.getAttribute(GSXML.NAME_ATT);
184 Element node_extra = GSXML.getNamedElement(config_search,
185 GSXML.LEVEL_ELEM,
186 GSXML.NAME_ATT,
187 name);
188 if (node_extra == null) {
189 logger.error("haven't found extra info for level named "+name);
190 continue;
191 }
192
193 // get the display elements if any - displayName
194 NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
195 if (display_names !=null) {
196 for (int j=0; j<display_names.getLength(); j++) {
197 Element e = (Element)display_names.item(j);
198 lev.appendChild(owner.importNode(e, true));
199 }
200 }
201 } // for each level
202 }
203
204 // the format info is the same for all services
205 Element format_info = (Element)format_info_map.get(TEXT_QUERY_SERVICE);
206
207 // set up the extra services which are available for this collection
208 if (this.simple_form_search) {
209 // set up short_service_info_ - for now just has id and type - name will be added in on the fly
210 Element fq_service = this.doc.createElement(GSXML.SERVICE_ELEM);
211 fq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
212 fq_service.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE);
213 this.short_service_info.appendChild(fq_service);
214
215 if (format_info != null) {
216 this.format_info_map.put(FIELD_QUERY_SERVICE, format_info);
217 }
218 }
219
220 if (this.advanced_form_search) {
221 Element afq_service = this.doc.createElement(GSXML.SERVICE_ELEM);
222 afq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
223 afq_service.setAttribute(GSXML.NAME_ATT, ADVANCED_FIELD_QUERY_SERVICE);
224 this.short_service_info.appendChild(afq_service);
225
226 if (format_info != null) {
227 this.format_info_map.put(ADVANCED_FIELD_QUERY_SERVICE, format_info);
228 }
229 }
230
231 return true;
232 }
233
234
235 protected Element getServiceDescription(String service_id, String lang, String subset) {
236 // should we check that the service is actually on offer? presumably we wont get asked for services that we haven't advertised previously.
237
238 if (!service_id.equals(FIELD_QUERY_SERVICE) && !service_id.equals(ADVANCED_FIELD_QUERY_SERVICE)) {
239 return super.getServiceDescription(service_id, lang, subset);
240 }
241
242
243 Element service = this.doc.createElement(GSXML.SERVICE_ELEM);
244 service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
245 service.setAttribute(GSXML.NAME_ATT, service_id);
246 if (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
247 service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getTextString(service_id+".name", lang)));
248 service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_SUBMIT, getTextString(service_id+".submit", lang)));
249 service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(service_id+".description", lang)));
250
251 }
252 if (subset == null || subset.equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) {
253 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
254 service.appendChild(param_list);
255 if (service_id.equals(FIELD_QUERY_SERVICE)) {
256
257 addCustomQueryParams(param_list, lang);
258 createParameter(MAXDOCS_PARAM, param_list, lang);
259 // create a multi param for the fields etc
260 // text box, field
261 Element multiparam = null;
262 Element param=null;
263 multiparam = GSXML.createParameterDescription(this.doc, SIMPLE_FIELD_PARAM, "", GSXML.PARAM_TYPE_MULTI, null, null, null);
264 multiparam.setAttribute("occurs", "4");
265 param_list.appendChild(multiparam);
266
267 // the components
268 createParameter(FIELD_QUERY_PARAM, multiparam, lang);
269 createParameter(FIELD_FIELD_PARAM, multiparam, lang);
270
271 } else {
272 createParameter(LEVEL_PARAM, param_list, lang);
273 createParameter(RANK_PARAM, param_list, lang);
274 createParameter(MAXDOCS_PARAM, param_list, lang);
275
276
277 // create a multi param for the fields etc
278 // text box, stem, case, field
279
280 Element multiparam = null;
281 Element param=null;
282
283 multiparam = GSXML.createParameterDescription(this.doc, ADVANCED_FIELD_PARAM, "", GSXML.PARAM_TYPE_MULTI, null, null, null);
284 multiparam.setAttribute("occurs", "4");
285 param_list.appendChild(multiparam);
286
287 createParameter(FIELD_COMBINE_PARAM, multiparam, lang);
288 createParameter(FIELD_QUERY_PARAM, multiparam, lang);
289 if (this.does_case) {
290 createParameter(FIELD_CASE_PARAM, multiparam, lang);
291 }
292 if (this.does_stem) {
293 createParameter(FIELD_STEM_PARAM, multiparam, lang);
294 }
295 if (this.does_accent) {
296 createParameter(FIELD_ACCENT_PARAM, multiparam, lang);
297 }
298 createParameter(FIELD_FIELD_PARAM, multiparam, lang);
299
300 }
301 }
302 return service;
303
304 }
305
306 /** add in the level params to TextQuery */
307 protected void addCustomQueryParams(Element param_list, String lang)
308 {
309 createParameter(LEVEL_PARAM, param_list, lang);
310 super.addCustomQueryParams(param_list, lang);
311 }
312
313 /** create a param and add to the list */
314 protected void createParameter(String name, Element param_list, String lang)
315 {
316 Element param = null;
317 if (name.equals(LEVEL_PARAM)) {
318 ArrayList level_ids = new ArrayList();
319 ArrayList level_names = new ArrayList();
320 getLevelData(level_ids, level_names, lang);
321 if (level_ids.size()>1) {
322 // the first one is the default
323 param = GSXML.createParameterDescription2(this.doc, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)level_ids.get(0), level_ids, level_names);
324 } else {
325 // we need to set the level, but hidden, in case there is an invalid level saved
326 param = GSXML.createParameterDescription(this.doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, (String)level_ids.get(0), null, null);
327 }
328 } else if (name.equals(RANK_PARAM)) {
329 String [] vals1 = {RANK_PARAM_RANK, RANK_PARAM_NONE };
330 String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang), getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang)};
331
332 param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param."+RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1, vals1_texts );
333
334 } else if (name.equals(FIELD_QUERY_PARAM)) {
335 param = GSXML.createParameterDescription(this.doc, FIELD_QUERY_PARAM, getTextString("param."+FIELD_QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
336
337
338 } else if (name.equals(FIELD_CASE_PARAM) || name.equals(FIELD_STEM_PARAM) || name.equals(FIELD_ACCENT_PARAM)) {
339 String[] bool_ops = {"0", "1"};
340 String[] bool_texts = {getTextString("param.boolean.off", lang, "AbstractSearch"),getTextString("param.boolean.on", lang, "AbstractSearch")};
341 param = GSXML.createParameterDescription(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, bool_ops, bool_texts);
342
343 } else if (name.equals(FIELD_FIELD_PARAM)) {
344 ArrayList fields = new ArrayList();
345 ArrayList field_names = new ArrayList();
346 getIndexData(fields, field_names, lang);
347 // the field list - read from config file
348 param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names );
349
350 } else if (name.equals(FIELD_COMBINE_PARAM)) {
351
352 String []vals = {FIELD_COMBINE_PARAM_AND, FIELD_COMBINE_PARAM_OR, FIELD_COMBINE_PARAM_NOT};
353 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)};
354
355
356 param = GSXML.createParameterDescription(this.doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, FIELD_COMBINE_PARAM_AND, vals, val_texts);
357 param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
358 }
359
360 if (param != null) {
361 param_list.appendChild(param);
362 } else {
363 super.createParameter(name, param_list, lang);
364 }
365 }
366
367 // should cache some of this
368 protected void getLevelData(ArrayList level_ids, ArrayList level_names, String lang)
369 {
370 Element level_list = (Element)GSXML.getChildByTagName(this.config_info, LEVEL_ELEM+GSXML.LIST_MODIFIER);
371 NodeList levels = level_list.getElementsByTagName(LEVEL_ELEM);
372 for (int i=0; i<levels.getLength(); i++) {
373 Element level = (Element)levels.item(i);
374 String shortname = level.getAttribute(GSXML.SHORTNAME_ATT);
375 if (shortname.equals("")) {
376 continue;
377 }
378 level_ids.add(shortname);
379 String display_name = GSXML.getDisplayText(level, GSXML.DISPLAY_TEXT_NAME, lang, "en");
380 if (display_name.equals("")) {
381 // we'll use the name, and the dictionary
382 display_name = level.getAttribute(GSXML.NAME_ATT);
383 if (display_name.equals("")) {
384 display_name = shortname;
385 } else {
386 display_name = getTextString("level."+display_name, lang);
387 }
388 }
389 level_names.add(display_name);
390 }
391 }
392
393 // the following three functions are needed so the base class can
394 // call the process+SERVICE_NAME methods
395 /** process a text query */
396 protected Element processTextQuery(Element request) {
397 return processAnyQuery(request, TEXT_QUERY);
398 }
399
400 /** process a field query */
401 protected Element processFieldQuery(Element request) {
402 return processAnyQuery(request, SIMPLE_QUERY);
403 }
404
405 /** process an advanced field query */
406 protected Element processAdvancedFieldQuery(Element request) {
407 return processAnyQuery(request, ADVANCED_QUERY);
408 }
409
410 /** process a query */
411 protected Element processAnyQuery(Element request, int query_type)
412 {
413
414 String service_name=null;
415 String empty_query_test_param=null;
416 // set up the type specific bits
417 switch (query_type) {
418 case TEXT_QUERY:
419 service_name = TEXT_QUERY_SERVICE;
420 empty_query_test_param = QUERY_PARAM;
421 break;
422 case SIMPLE_QUERY:
423 service_name = FIELD_QUERY_SERVICE;
424 empty_query_test_param = FIELD_QUERY_PARAM;
425 break;
426 case ADVANCED_QUERY:
427 service_name = ADVANCED_FIELD_QUERY_SERVICE;
428 empty_query_test_param = FIELD_QUERY_PARAM;
429 break;
430 default:
431 // should never get here
432 logger.error("wrong query type!!");
433 return null;
434 }
435
436 // Create a new (empty) result message
437 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
438 result.setAttribute(GSXML.FROM_ATT, service_name);
439 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
440
441 // Get the parameters of the request
442 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
443 if (param_list == null) {
444 logger.error("TextQuery request had no paramList.");
445 return result; // Return the empty result
446 }
447
448 // Process the request parameters
449 HashMap params = GSXML.extractParams(param_list, false);
450
451 // Make sure a query has been specified
452 String query = (String) params.get(empty_query_test_param);
453 if (query == null || query.equals("")) {
454 return result; // Return the empty result
455 }
456
457 // If a field hasn't been specified, use the default - for textQuery
458 String field = (String) params.get(INDEX_PARAM);
459 if (field == null) {
460 field = default_index;
461 }
462
463 // set up the appropriate query system
464 if (!setUpQueryer(params)) {
465 return result;
466 }
467
468 // if field search, create the query string
469 switch (query_type) {
470 case TEXT_QUERY:
471 query = addFieldInfo(query, field);
472 break;
473 case SIMPLE_QUERY:
474 query = parseFieldQueryParams(params);
475 break;
476 case ADVANCED_QUERY:
477 query = parseAdvancedFieldQueryParams(params);
478 break;
479 }
480
481 // run the query
482 Object query_result = runQuery(query);
483
484 // build up the response
485
486 // Create a metadata list to store information about the query results
487 // should we be using metadataList? or something else?
488 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
489 result.appendChild(metadata_list);
490
491 // Add a metadata element specifying the number of matching documents
492 long totalDocs = numDocsMatched(query_result);
493
494 GSXML.addMetadata(this.doc, metadata_list, "numDocsMatched", ""+totalDocs);
495
496 // Create a document list to store the matching documents, and add them
497 String [] docs = getDocIDs(query_result);
498 String [] doc_ranks = getDocRanks(query_result);
499
500 // add a metadata item to specify docs returned
501 int docs_returned = docs.length;
502 if (does_paging) {
503 String maxdocs_str = (String)params.get(MAXDOCS_PARAM);
504 if (maxdocs_str != null) {
505 int maxdocs = Integer.parseInt(maxdocs_str);
506 docs_returned = (maxdocs < (int)totalDocs ? maxdocs : (int)totalDocs);
507 }
508 }
509 GSXML.addMetadata(this.doc, metadata_list, "numDocsReturned", ""+docs_returned);
510
511 // 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
512 GSXML.addMetadata(this.doc, metadata_list, "query", query);
513 if (docs.length>0) {
514 Element document_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
515 result.appendChild(document_list);
516 for (int d = 0; d < docs.length; d++) {
517 String doc_id = internalNum2OID(docs[d]);
518 Element doc_node = createDocNode(doc_id, doc_ranks[d]);
519 document_list.appendChild(doc_node);
520 }
521 }
522
523 // Create a term list to store the term information, and add it
524 Element term_list = this.doc.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
525 result.appendChild(term_list);
526 addTermInfo(term_list, params, query_result);
527
528 return result;
529 }
530
531 /** methods to handle actually doing the query */
532 /** do any initialisation of the query object */
533 abstract protected boolean setUpQueryer(HashMap params);
534 /** do the query */
535 abstract protected Object runQuery(String query);
536 /** get the total number of docs that match */
537 abstract protected long numDocsMatched(Object query_result);
538 /** get the list of doc ids */
539 abstract protected String [] getDocIDs(Object query_result);
540 /** get the list of doc ranks */
541 abstract protected String [] getDocRanks(Object query_result);
542 /** add in term info if available */
543 abstract protected boolean addTermInfo(Element term_list, HashMap params,
544 Object query_result);
545
546 /** combines all the field params into a single query
547 * - for simple field query */
548 /** We assume the combination (AND/OR) is done by the match param */
549 protected String parseFieldQueryParams(HashMap params) {
550
551 StringBuffer final_query = new StringBuffer(256);
552 String text_line = (String)params.get(FIELD_QUERY_PARAM);
553 String[] texts = text_line.split(",", -1);
554 String field_line = (String)params.get(FIELD_FIELD_PARAM);
555 String[] fields = field_line.split(",", -1);
556
557 for (int i=0; i<texts.length; i++) {
558 String q = texts[i].trim();
559 if (!q.equals("")) {
560 final_query.append(" "+addFieldInfo(q, fields[i]));
561 }
562 }
563
564 return final_query.toString();
565 }
566
567 abstract protected String addFieldInfo(String query, String field);
568
569 /** combines all the field params into a single query
570 * - for advanced field query */
571 protected String parseAdvancedFieldQueryParams(HashMap params) {
572
573 StringBuffer final_query = new StringBuffer(256);
574 String text_line = (String)params.get(FIELD_QUERY_PARAM);
575 String[] texts = text_line.split(",", -1);
576 String field_line = (String)params.get(FIELD_FIELD_PARAM);
577 String[] fields = field_line.split(",", -1);
578 String [] cases = null;
579 String [] stems = null;
580 String [] accents = null;
581 if (does_case) {
582 String case_line = (String)params.get(FIELD_CASE_PARAM);
583 cases = case_line.split(",", -1);
584 }
585 if (does_stem) {
586 String stem_line = (String)params.get(FIELD_STEM_PARAM);
587 stems = stem_line.split(",", -1);
588 }
589 if (does_accent) {
590 String accent_line = (String)params.get(FIELD_ACCENT_PARAM);
591 accents = accent_line.split(",", -1);
592 }
593 String combine_line = (String)params.get(FIELD_COMBINE_PARAM);
594 String [] combines = combine_line.split(",", -1);
595 String combine = "";
596 for (int i=0; i<texts.length; i++) {
597 if (i==0) {// assume first one is blank
598 combine = "";
599 } else {
600 String x = combines[i];
601 if (x.equals(FIELD_COMBINE_PARAM_AND)) {
602 combine = AND_OPERATOR;
603 } else if (x.equals(FIELD_COMBINE_PARAM_OR)) {
604 combine = OR_OPERATOR;
605 } else if (x.equals(FIELD_COMBINE_PARAM_NOT)) {
606 combine = NOT_OPERATOR;
607 }
608
609 }
610
611 String q = texts[i].trim();
612 boolean modified = false;
613 if (!q.equals("")) {
614 String c = null;
615 String s = null;
616 String a = null;
617 if (does_case) {
618 modified = true;
619 c = cases[i];
620 }
621 if (does_stem) {
622 modified = true;
623 s = stems[i];
624 }
625 if (does_accent) {
626 modified = true;
627 a = accents[i];
628 }
629 if (modified) {
630 q = addStemOptions(q, s, c, a);
631 }
632 addQueryElem(final_query, q, fields[i], combine);
633 }
634 }
635 return final_query.toString();
636 }
637
638 abstract protected void addQueryElem(StringBuffer final_query,
639 String query, String field,
640 String combine);
641 abstract protected String addStemOptions(String query, String stem,
642 String casef, String accent);
643
644}
645
646
Note: See TracBrowser for help on using the repository browser.