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

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

if there is only one level, add level param as an invisible parameter just in case there is level info hanging around in the cached params which may not be valid. also, doc_returned, don't rely on docs.length - if we are doing paging in the indexer, then we are only returning a subset of the results available

  • Property svn:keywords set to Author Date Id Revision
File size: 23.0 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 } else {
297 // we need to set the level, but hidden, in case there is an invalid level saved
298 param = GSXML.createParameterDescription(this.doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, (String)level_ids.get(0), null, null);
299 }
300 } else if (name.equals(RANK_PARAM)) {
301 String [] vals1 = {RANK_PARAM_RANK, RANK_PARAM_NONE };
302 String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang), getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang)};
303
304 param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param."+RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1, vals1_texts );
305
306 } else if (name.equals(FIELD_QUERY_PARAM)) {
307 param = GSXML.createParameterDescription(this.doc, FIELD_QUERY_PARAM, getTextString("param."+FIELD_QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
308
309
310 } else if (name.equals(FIELD_CASE_PARAM) || name.equals(FIELD_STEM_PARAM) || name.equals(FIELD_ACCENT_PARAM)) {
311 String[] bool_ops = {"0", "1"};
312 String[] bool_texts = {getTextString("param.boolean.off", lang, "AbstractSearch"),getTextString("param.boolean.on", lang, "AbstractSearch")};
313 param = GSXML.createParameterDescription(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, bool_ops, bool_texts);
314
315 } else if (name.equals(FIELD_FIELD_PARAM)) {
316 ArrayList fields = new ArrayList();
317 ArrayList field_names = new ArrayList();
318 getIndexData(fields, field_names, lang);
319 // the field list - read from config file
320 param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names );
321
322 } else if (name.equals(FIELD_COMBINE_PARAM)) {
323
324 String []vals = {FIELD_COMBINE_PARAM_AND, FIELD_COMBINE_PARAM_OR, FIELD_COMBINE_PARAM_NOT};
325 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)};
326
327
328 param = GSXML.createParameterDescription(this.doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, FIELD_COMBINE_PARAM_AND, vals, val_texts);
329 param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
330 }
331
332 if (param != null) {
333 param_list.appendChild(param);
334 } else {
335 super.createParameter(name, param_list, lang);
336 }
337 }
338
339 // should cache some of this
340 protected void getLevelData(ArrayList level_ids, ArrayList level_names, String lang)
341 {
342 Element level_list = (Element)GSXML.getChildByTagName(this.config_info, LEVEL_ELEM+GSXML.LIST_MODIFIER);
343 NodeList levels = level_list.getElementsByTagName(LEVEL_ELEM);
344 for (int i=0; i<levels.getLength(); i++) {
345 level_ids.add(((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT));
346 level_names.add(getTextString("level."+level_ids.get(i), lang));
347 }
348
349 }
350 protected void getIndexData(ArrayList index_ids, ArrayList index_names, String lang){
351 // we currently only have one index, and use the field data as the index
352
353 // the field list - read from config file
354 Element field_list = (Element)GSXML.getChildByTagName(this.config_info, GSXML.FIELD_ELEM+GSXML.LIST_MODIFIER);
355 NodeList fields = field_list.getElementsByTagName(GSXML.FIELD_ELEM);
356 for (int i=0; i< fields.getLength();i++) {
357 String shortname = ((Element)fields.item(i)).getAttribute(GSXML.SHORTNAME_ATT);
358 String name = ((Element)fields.item(i)).getAttribute(GSXML.NAME_ATT);
359 if (name.equals("")) {
360 // no name, ignore
361 continue;
362 }
363 // TODO change field so that name is the id, and full metadata name is somthing else
364 if (shortname.equals("")) {
365 shortname = name;
366 }
367 index_ids.add(shortname);
368 // should these be changed to a text element based on lang?
369 // or is the name of a metadata element eg dc:Title its
370 // name in all langs
371 index_names.add(name);
372 }
373 }
374
375
376 // the following three functions are needed so the base class can
377 // call the process+SERVICE_NAME methods
378 /** process a text query */
379 protected Element processTextQuery(Element request) {
380 return processAnyQuery(request, TEXT_QUERY);
381 }
382
383 /** process a field query */
384 protected Element processFieldQuery(Element request) {
385 return processAnyQuery(request, SIMPLE_QUERY);
386 }
387
388 /** process an advanced field query */
389 protected Element processAdvancedFieldQuery(Element request) {
390 return processAnyQuery(request, ADVANCED_QUERY);
391 }
392
393 /** process a query */
394 protected Element processAnyQuery(Element request, int query_type)
395 {
396
397 String service_name=null;
398 String empty_query_test_param=null;
399 // set up the type specific bits
400 switch (query_type) {
401 case TEXT_QUERY:
402 service_name = TEXT_QUERY_SERVICE;
403 empty_query_test_param = QUERY_PARAM;
404 break;
405 case SIMPLE_QUERY:
406 service_name = FIELD_QUERY_SERVICE;
407 empty_query_test_param = FIELD_QUERY_PARAM;
408 break;
409 case ADVANCED_QUERY:
410 service_name = ADVANCED_FIELD_QUERY_SERVICE;
411 empty_query_test_param = FIELD_QUERY_PARAM;
412 break;
413 default:
414 // should never get here
415 logger.error("wrong query type!!");
416 return null;
417 }
418
419 // Create a new (empty) result message
420 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
421 result.setAttribute(GSXML.FROM_ATT, service_name);
422 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
423
424 // Get the parameters of the request
425 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
426 if (param_list == null) {
427 logger.error("TextQuery request had no paramList.");
428 return result; // Return the empty result
429 }
430
431 // Process the request parameters
432 HashMap params = GSXML.extractParams(param_list, false);
433
434 // Make sure a query has been specified
435 String query = (String) params.get(empty_query_test_param);
436 if (query == null || query.equals("")) {
437 return result; // Return the empty result
438 }
439
440 // If a field hasn't been specified, use the default - for textQuery
441 String field = (String) params.get(INDEX_PARAM);
442 if (field == null) {
443 field = default_field;
444 }
445
446 // set up the appropriate query system
447 if (!setUpQueryer(params)) {
448 return result;
449 }
450
451 // if field search, create the query string
452 switch (query_type) {
453 case TEXT_QUERY:
454 query = addFieldInfo(query, field);
455 break;
456 case SIMPLE_QUERY:
457 query = parseFieldQueryParams(params);
458 break;
459 case ADVANCED_QUERY:
460 query = parseAdvancedFieldQueryParams(params);
461 break;
462 }
463
464
465 // run the query
466 Object query_result = runQuery(query);
467
468 // build up the response
469
470 // Create a metadata list to store information about the query results
471 // should we be using metadataList? or something else?
472 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
473 result.appendChild(metadata_list);
474
475 // Add a metadata element specifying the number of matching documents
476 long totalDocs = numDocsMatched(query_result);
477
478 GSXML.addMetadata(this.doc, metadata_list, "numDocsMatched", ""+totalDocs);
479
480 // Create a document list to store the matching documents, and add them
481 String [] docs = getDocIDs(query_result);
482 String [] doc_ranks = getDocRanks(query_result);
483
484 // add a metadata item to specify docs returned
485 int docs_returned = docs.length;
486 if (does_paging) {
487 int maxdocs = Integer.parseInt((String)params.get(MAXDOCS_PARAM));
488 docs_returned = (maxdocs < (int)totalDocs ? maxdocs : (int)totalDocs);
489 }
490 GSXML.addMetadata(this.doc, metadata_list, "numDocsReturned", ""+docs_returned);
491 // 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
492 GSXML.addMetadata(this.doc, metadata_list, "query", query);
493 if (docs.length>0) {
494 Element document_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
495 result.appendChild(document_list);
496 for (int d = 0; d < docs.length; d++) {
497 String doc_id = internalNum2OID(docs[d]);
498 Element doc_node = createDocNode(doc_id, doc_ranks[d]);
499 document_list.appendChild(doc_node);
500 }
501 }
502 // Create a term list to store the term information, and add it
503 Element term_list = this.doc.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
504 result.appendChild(term_list);
505 addTermInfo(term_list, params, query_result);
506
507 return result;
508 }
509
510 /** methods to handle actually doing the query */
511 /** do any initialisation of the query object */
512 abstract protected boolean setUpQueryer(HashMap params);
513 /** do the query */
514 abstract protected Object runQuery(String query);
515 /** get the total number of docs that match */
516 abstract protected long numDocsMatched(Object query_result);
517 /** get the list of doc ids */
518 abstract protected String [] getDocIDs(Object query_result);
519 /** get the list of doc ranks */
520 abstract protected String [] getDocRanks(Object query_result);
521 /** add in term info if available */
522 abstract protected boolean addTermInfo(Element term_list, HashMap params,
523 Object query_result);
524
525 /** combines all the field params into a single query
526 * - for simple field query */
527 /** We assume the combination (AND/OR) is done by the match param */
528 protected String parseFieldQueryParams(HashMap params) {
529
530 StringBuffer final_query = new StringBuffer(256);
531 String text_line = (String)params.get(FIELD_QUERY_PARAM);
532 String[] texts = text_line.split(",", -1);
533 String field_line = (String)params.get(FIELD_FIELD_PARAM);
534 String[] fields = field_line.split(",", -1);
535
536 for (int i=0; i<texts.length; i++) {
537 String q = texts[i].trim();
538 if (!q.equals("")) {
539 final_query.append(" "+addFieldInfo(q, fields[i]));
540 }
541 }
542
543 return final_query.toString();
544 }
545
546 abstract protected String addFieldInfo(String query, String field);
547
548 /** combines all the field params into a single query
549 * - for advanced field query */
550 protected String parseAdvancedFieldQueryParams(HashMap params) {
551
552 StringBuffer final_query = new StringBuffer(256);
553 String text_line = (String)params.get(FIELD_QUERY_PARAM);
554 String[] texts = text_line.split(",", -1);
555 String field_line = (String)params.get(FIELD_FIELD_PARAM);
556 String[] fields = field_line.split(",", -1);
557 String [] cases = null;
558 String [] stems = null;
559 String [] accents = null;
560 if (does_case) {
561 String case_line = (String)params.get(FIELD_CASE_PARAM);
562 cases = case_line.split(",", -1);
563 }
564 if (does_stem) {
565 String stem_line = (String)params.get(FIELD_STEM_PARAM);
566 stems = stem_line.split(",", -1);
567 }
568 if (does_accent) {
569 String accent_line = (String)params.get(FIELD_ACCENT_PARAM);
570 accents = accent_line.split(",", -1);
571 }
572 String combine_line = (String)params.get(FIELD_COMBINE_PARAM);
573 String [] combines = combine_line.split(",", -1);
574 String combine = "";
575 for (int i=0; i<texts.length; i++) {
576 if (i==0) {// assume first one is blank
577 combine = "";
578 } else {
579 String x = combines[i];
580 if (x.equals(FIELD_COMBINE_PARAM_AND)) {
581 combine = AND_OPERATOR;
582 } else if (x.equals(FIELD_COMBINE_PARAM_OR)) {
583 combine = OR_OPERATOR;
584 } else if (x.equals(FIELD_COMBINE_PARAM_NOT)) {
585 combine = NOT_OPERATOR;
586 }
587
588 }
589
590 String q = texts[i].trim();
591 boolean modified = false;
592 if (!q.equals("")) {
593 String c = null;
594 String s = null;
595 String a = null;
596 if (does_case) {
597 modified = true;
598 c = cases[i];
599 }
600 if (does_stem) {
601 modified = true;
602 s = stems[i];
603 }
604 if (does_accent) {
605 modified = true;
606 a = accents[i];
607 }
608 if (modified) {
609 q = addStemOptions(q, s, c, a);
610 }
611 addQueryElem(final_query, q, fields[i], combine);
612 }
613 }
614 return final_query.toString();
615 }
616
617 abstract protected void addQueryElem(StringBuffer final_query,
618 String query, String field,
619 String combine);
620 abstract protected String addStemOptions(String query, String stem,
621 String casef, String accent);
622
623}
624
625
Note: See TracBrowser for help on using the repository browser.