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

Last change on this file since 13270 was 13270, checked in by shaoqun, 17 years ago

replace Category class which is deprecated with Logger class

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