source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java@ 4903

Last change on this file since 4903 was 4903, checked in by kjdon, 21 years ago

tidied up a lot of stuff, particularly the display text stuff, including how its formatted, and some of the service rack methods

  • Property svn:keywords set to Author Date Id Revision
File size: 22.4 KB
Line 
1
2/*
3 * GS2MGPPSearch.java
4 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20package org.greenstone.gsdl3.service;
21
22
23// Greenstone classes
24import org.greenstone.mgpp.*;
25import org.greenstone.gsdl3.util.*;
26
27// XML classes
28import org.w3c.dom.Element;
29import org.w3c.dom.Node;
30import org.w3c.dom.NodeList;
31
32// General Java classes
33import java.io.File;
34import java.util.HashMap;
35import java.util.Vector;
36import java.util.Set;
37import java.util.Map;
38import java.util.Iterator;
39
40
41/**
42 * A ServiceRack class for searching in greenstone 2 MGPP collections
43 *
44 * @author <a href="mailto:[email protected]">Katherine Don</a>
45 * @version $Revision: 4903 $
46 * @see ServiceRack
47 */
48public class GS2MGPPSearch
49 extends GS2Search {
50
51 // extra services offered by mgpp collections
52 private static final String FIELD_QUERY_SERVICE = "FieldQuery";
53 private static final String ADVANCED_FIELD_QUERY_SERVICE = "AdvancedFieldQuery";
54
55 // extra parameters used
56 private static final String INDEX_FIELD_PARAM = "index";
57 private static final String LEVEL_PARAM = "level";
58 private static final String RANK_PARAM = "sortBy";
59 private static final String RANK_PARAM_RANK = "1";
60 private static final String RANK_PARAM_NONE = "0";
61 private static final String SIMPLE_FIELD_PARAM = "simpleField";
62 private static final String ADVANCED_FIELD_PARAM = "complexField";
63 // more params for field query
64 private static final String FIELD_QUERY_PARAM = "fqv";
65 private static final String FIELD_STEM_PARAM = "fqs";
66 private static final String FIELD_CASE_PARAM = "fqc";
67 private static final String FIELD_FIELD_PARAM = "fqf";
68 private static final String FIELD_COMBINE_PARAM = "fqk";
69 private static final String FIELD_COMBINE_PARAM_AND = "0";
70 private static final String FIELD_COMBINE_PARAM_OR = "1";
71 private static final String FIELD_COMBINE_PARAM_NOT = "2";
72
73 private static final int TEXT_QUERY = 0;
74 private static final int SIMPLE_QUERY = 1;
75 private static final int ADVANCED_QUERY = 2;
76
77 protected static final String FIELD_ATT = "field";
78 private MGPPWrapper mgpp_src_=null;
79
80 // the default level for retrieval - and we'll use it for searching too
81 private String default_level_=null;
82
83 /** constructor */
84 public GS2MGPPSearch()
85 {
86 mgpp_src_ = new MGPPWrapper();
87 }
88
89
90 /** configure this service */
91 public boolean configure(Element info, Element extra_info)
92 {
93 // Do generic configuration
94 if (super.configure(info, extra_info) == false)
95 return false;
96
97 // Do specific configuration
98 System.out.println("Configuring GS2MGPPSearch...");
99
100 // Get the default level out of <defaultLevel> (buildConfig.xml)
101 Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
102 if (def != null) {
103 default_level_ = def.getAttribute(GSXML.NAME_ATT);
104 }
105 if (default_level_ == null || default_level_.equals("")) {
106 System.err.println("Error: default level not specified!");
107 return false;
108 }
109
110 // the default level is also the level which gdbm is expecting
111 // this must not be overwritten
112 mgpp_src_.setReturnLevel(default_level_);
113 // return term info
114 mgpp_src_.setReturnTerms(true);
115 // set the default - this may be overwritten by query params
116 mgpp_src_.setQueryLevel(default_level_);
117
118 // set up the extra services which are available for this collection
119 // check the config info - if there is no field list, then there is no fielded searching
120
121 Element field_list = (Element) GSXML.getChildByTagName(info, GSXML.FIELD_ELEM+GSXML.LIST_MODIFIER);
122 if (field_list==null) {
123 // nothing more to do
124 return true;
125 }
126 // else set up the fielded query services
127
128 // set up short_service_info_ - for now just has id and type - name will be added in on teh fly
129 Element fq_service = doc_.createElement(GSXML.SERVICE_ELEM);
130 fq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
131 fq_service.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE);
132 short_service_info_.appendChild(fq_service);
133
134 Element afq_service = doc_.createElement(GSXML.SERVICE_ELEM);
135 afq_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
136 afq_service.setAttribute(GSXML.NAME_ATT, ADVANCED_FIELD_QUERY_SERVICE);
137 short_service_info_.appendChild(afq_service);
138
139
140 //set up format info - the info is the same as that for text query
141 Element format_info = (Element)format_info_map_.get(TEXT_QUERY_SERVICE);
142 if (format_info != null) {
143 format_info_map_.put(FIELD_QUERY_SERVICE, format_info);
144 format_info_map_.put(ADVANCED_FIELD_QUERY_SERVICE, format_info);
145 }
146 return true;
147 }
148
149 protected Element getServiceDescription(String service_id, String lang) {
150
151 if (!service_id.equals(FIELD_QUERY_SERVICE) && !service_id.equals(ADVANCED_FIELD_QUERY_SERVICE)) {
152 return super.getServiceDescription(service_id, lang);
153 }
154
155 Element service = doc_.createElement(GSXML.SERVICE_ELEM);
156 service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
157 service.setAttribute(GSXML.NAME_ATT, service_id);
158 service.appendChild(GSXML.createDisplayTextElement(doc_, GSXML.DISPLAY_TEXT_NAME, getTextString(service_id+".name", lang)));
159 service.appendChild(GSXML.createDisplayTextElement(doc_, GSXML.DISPLAY_TEXT_SUBMIT, getTextString(service_id+".submit", lang)));
160 Element param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
161 service.appendChild(param_list);
162 if (service_id.equals(FIELD_QUERY_SERVICE)) {
163
164 createFieldQueryParamList(param_list, lang);
165 } else {
166 createAdvancedFieldQueryParamList(param_list, lang);
167 }
168 return service;
169
170 }
171
172 /** creates a new param element and adds it to the param list */
173 protected void createParameter(String id, Element param_list, String lang) {
174 Element param=null;
175
176 if (id.equals(LEVEL_PARAM)) {
177 // the level info - read from config file
178 Element level_list = (Element)GSXML.getChildByTagName(config_info_, LEVEL_ELEM+GSXML.LIST_MODIFIER);
179 NodeList levels = level_list.getElementsByTagName(LEVEL_ELEM);
180 int len = levels.getLength();
181 if (len > 1) { // add level param to list only if more than one index specified
182 String [] levs = new String[len];
183 String [] lev_names = new String[len];
184 for (int i=0; i<len; i++) {
185 levs[i] = ((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT);
186 lev_names[i] = getTextString("level."+levs[i], lang);
187
188 }
189 // the first one is the default
190 param = GSXML.createParameterDescription(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, levs[0], levs, lev_names);
191
192 }
193 } else if (id.equals(RANK_PARAM)) {
194 String [] vals1 = {RANK_PARAM_RANK, RANK_PARAM_NONE };
195 String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang), getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang)};
196
197 param = GSXML.createParameterDescription(doc_, RANK_PARAM, getTextString("param."+RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1, vals1_texts );
198
199 } else if (id.equals(FIELD_QUERY_PARAM)) {
200 param = GSXML.createParameterDescription(doc_, FIELD_QUERY_PARAM, getTextString("param."+FIELD_QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
201
202
203 } else if (id.equals(FIELD_CASE_PARAM) || id.equals(FIELD_STEM_PARAM)) {
204 String[] bool_ops = {"0", "1"};
205 String[] bool_texts = {getTextString("param.boolean.off", lang),getTextString("param.boolean.on", lang)};
206 param = GSXML.createParameterDescription(doc_, id, getTextString("param."+id, lang), GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, bool_ops, bool_texts);
207
208 } else if (id.equals(FIELD_FIELD_PARAM) || id.equals(INDEX_FIELD_PARAM)) {
209
210 // the field list - read from config file
211 Element field_list = (Element)GSXML.getChildByTagName(config_info_, GSXML.FIELD_ELEM+GSXML.LIST_MODIFIER);
212 NodeList fields = field_list.getElementsByTagName(GSXML.FIELD_ELEM);
213 int len = fields.getLength();
214 String [] f_names = new String [len];
215 String [] f_texts = new String [len];
216 for (int i=0; i< len;i++) {
217 f_names[i] = ((Element)fields.item(i)).getAttribute(GSXML.SHORTNAME_ATT);
218 // should these be changed to a text element based on lang?
219 // or is the name of a metadata element eg dc:Title its
220 // name in all langs
221 f_texts[i] = ((Element)fields.item(i)).getAttribute(GSXML.NAME_ATT);
222
223 }
224 param = GSXML.createParameterDescription(doc_, id, getTextString("param."+id, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, f_names[0], f_names, f_texts );
225
226 } else if (id.equals(FIELD_COMBINE_PARAM)) {
227
228 String []vals = {FIELD_COMBINE_PARAM_AND, FIELD_COMBINE_PARAM_OR, FIELD_COMBINE_PARAM_NOT};
229 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)};
230
231
232 param = GSXML.createParameterDescription(doc_, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, FIELD_COMBINE_PARAM_AND, vals, val_texts);
233 param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
234
235
236 }
237
238 // add the param to the list
239 if (param !=null) {
240 param_list.appendChild(param);
241 }
242 else {
243 super.createParameter(id, param_list, lang);
244 }
245 }
246
247
248 /** this creates all teh params and appends them to param_list.
249 * if display=true it creates the text strings version
250 * otherwise it creates the description version
251 */
252 protected boolean createTextQueryParamList(Element param_list,
253
254 String lang)
255 {
256 // the order they are specified here is the order they appear on
257 // the query form
258 //createParameter(INDEX_PARAM, param_list, display, lang); - there is only ever one index now
259 createParameter(INDEX_FIELD_PARAM, param_list, lang);
260 createParameter(LEVEL_PARAM, param_list, lang);
261 createParameter(CASE_PARAM, param_list, lang);
262 createParameter(STEM_PARAM, param_list, lang);
263 createParameter(MATCH_PARAM, param_list, lang);
264 createParameter(RANK_PARAM, param_list, lang);
265 createParameter(MAXDOCS_PARAM, param_list, lang);
266 createParameter(QUERY_PARAM, param_list, lang);
267
268 return true;
269 }
270
271
272
273 /** this creates all teh params and appends them to param_list.
274 * if display=true it creates the text strings version
275 * otherwise it creates the description version
276 */
277 protected boolean createFieldQueryParamList(Element param_list,
278 String lang)
279 {
280 // add in the index param
281 //createParameter(INDEX_PARAM, param_list, display, lang);
282 createParameter(LEVEL_PARAM, param_list, lang);
283 createParameter(MATCH_PARAM, param_list, lang);
284 createParameter(CASE_PARAM, param_list, lang);
285 createParameter(STEM_PARAM, param_list, lang);
286 createParameter(RANK_PARAM, param_list, lang);
287 createParameter(MAXDOCS_PARAM, param_list, lang);
288
289 // create a multi param for the fields etc
290 // text box, field
291 Element multiparam = null;
292 Element param=null;
293 multiparam = GSXML.createParameterDescription(doc_, SIMPLE_FIELD_PARAM, "", GSXML.PARAM_TYPE_MULTI, null, null, null);
294 multiparam.setAttribute("occurs", "4");
295 param_list.appendChild(multiparam);
296
297 // the components
298 createParameter(FIELD_QUERY_PARAM, multiparam, lang);
299 createParameter(FIELD_FIELD_PARAM, multiparam, lang);
300
301 return true;
302 }
303
304 protected boolean createAdvancedFieldQueryParamList(Element param_list,
305 String lang) {
306
307 // first do index and level params
308 //createParameter(INDEX_PARAM, param_list, display, lang);
309 createParameter(LEVEL_PARAM, param_list, lang);
310 createParameter(RANK_PARAM, param_list, lang);
311 createParameter(MAXDOCS_PARAM, param_list, lang);
312
313
314 // create a multi param for the fields etc
315 // text box, stem, case, field
316
317 Element multiparam = null;
318 Element param=null;
319
320 multiparam = GSXML.createParameterDescription(doc_, ADVANCED_FIELD_PARAM, "", GSXML.PARAM_TYPE_MULTI, null, null, null);
321 multiparam.setAttribute("occurs", "4");
322 param_list.appendChild(multiparam);
323
324 createParameter(FIELD_COMBINE_PARAM, multiparam, lang);
325 createParameter(FIELD_QUERY_PARAM, multiparam, lang);
326 createParameter(FIELD_CASE_PARAM, multiparam, lang);
327 createParameter(FIELD_STEM_PARAM, multiparam, lang);
328 createParameter(FIELD_FIELD_PARAM, multiparam, lang);
329
330
331 return true;
332 }
333
334 // the following three functions are needed so the base class can
335 // call the process+SERVICE_NAME methods
336 /** process a text query */
337 protected Element processTextQuery(Element request) {
338 return processAnyQuery(request, TEXT_QUERY);
339 }
340
341 /** process a field query */
342 protected Element processFieldQuery(Element request) {
343 return processAnyQuery(request, SIMPLE_QUERY);
344 }
345
346 /** process an advanced field query */
347 protected Element processAdvancedFieldQuery(Element request) {
348 return processAnyQuery(request, ADVANCED_QUERY);
349 }
350
351 /** process a query */
352 protected Element processAnyQuery(Element request, int query_type)
353 {
354
355 String service_name=null;
356 String empty_query_test_param=null;
357 // set up the type specific bits
358 switch (query_type) {
359 case TEXT_QUERY:
360 service_name = TEXT_QUERY_SERVICE;
361 empty_query_test_param = QUERY_PARAM;
362 break;
363 case SIMPLE_QUERY:
364 service_name = FIELD_QUERY_SERVICE;
365 empty_query_test_param = FIELD_QUERY_PARAM;
366 break;
367 case ADVANCED_QUERY:
368 service_name = ADVANCED_FIELD_QUERY_SERVICE;
369 empty_query_test_param = FIELD_QUERY_PARAM;
370 break;
371 default:
372 // should never get here
373 System.err.println("GS2MGPPSearch: wrong query type!!");
374 return null;
375 }
376
377 // Create a new (empty) result message
378 Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
379 result.setAttribute(GSXML.FROM_ATT, service_name);
380 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
381
382 // Get the parameters of the request
383 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
384 if (param_list == null) {
385 System.err.println("Error: TextQuery request had no paramList.");
386 return result; // Return the empty result
387 }
388
389 // Process the request parameters
390 HashMap params = GSXML.extractParams(param_list, false);
391
392 // Make sure a query has been specified
393 String query = (String) params.get(empty_query_test_param);
394 if (query == null || query.equals("")) {
395 return result; // Return the empty result
396 }
397
398 // If an field hasn't been specified, use all fields
399 String field = (String) params.get(INDEX_FIELD_PARAM);
400 if (field == null) {
401 field = "ZZ";
402 }
403
404 // set up mgpp_src
405 String indexdir = GSFile.collectionBaseDir(site_home_, cluster_name_) +
406 File.separatorChar + GSFile.collectionIndexPath(cluster_name_, default_index_);
407 mgpp_src_.loadIndexData(indexdir);
408 setStandardQueryParams(params);
409
410 // if field search, create the query string
411 switch (query_type) {
412 case TEXT_QUERY:
413 query = addFieldInfo(query, field);
414 break;
415 case SIMPLE_QUERY:
416 query = parseFieldQueryParams(params);
417 break;
418 case ADVANCED_QUERY:
419 query = parseAdvancedFieldQueryParams(params);
420 break;
421 }
422 // run the query
423 mgpp_src_.runQuery(query);
424 MGPPQueryResult mqr= mgpp_src_.getQueryResult();
425
426 // build up the response
427
428 // Create a metadata list to store information about the query results
429 // should we be using metadataList? or something else?
430 Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
431 result.appendChild(metadata_list);
432
433 // Add a metadata element specifying the number of matching documents
434 long totalDocs = mqr.getTotalDocs();
435 Element num_matches_elem = doc_.createElement(GSXML.METADATA_ELEM);
436 num_matches_elem.setAttribute(GSXML.NAME_ATT, "numDocsMatched");
437 num_matches_elem.setAttribute(GSXML.VALUE_ATT, "" + totalDocs);
438 metadata_list.appendChild(num_matches_elem);
439
440 // Create a document list to store the matching documents, and add them
441 Vector docs = mqr.getDocs();
442 Element document_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
443 result.appendChild(document_list);
444 for (int d = 0; d < docs.size(); d++) {
445 long docnum = ((MGPPDocInfo) docs.elementAt(d)).num_;
446 String doc_id = gdbm_src_.docnum2Oid(docnum);
447 Element doc_node = createDocumentNodeElement(doc_id);
448 document_list.appendChild(doc_node);
449 }
450
451 // Create a term list to store the term information, and add it
452 String query_level = (String)params.get(LEVEL_PARAM); // the current query level
453 Element term_list = doc_.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
454 result.appendChild(term_list);
455 Vector terms = mqr.getTerms();
456 for (int t = 0; t < terms.size(); t++) {
457 MGPPTermInfo term_info = (MGPPTermInfo) terms.get(t);
458
459 Element term_elem = doc_.createElement(GSXML.TERM_ELEM);
460 term_elem.setAttribute(GSXML.NAME_ATT, term_info.term_);
461 term_elem.setAttribute(STEM_ATT, "" + term_info.stem_method_);
462 term_elem.setAttribute(FREQ_ATT, "" + term_info.term_freq_);
463 term_elem.setAttribute(NUM_DOCS_MATCH_ATT, "" + term_info.match_docs_);
464 field = term_info.tag_;
465 if (field.equals(query_level)) {
466 // ignore
467 field = "";
468 }
469 term_elem.setAttribute(FIELD_ATT, field);
470
471 Vector equiv_terms = term_info.equiv_terms_;
472 Element equiv_term_list = doc_.createElement(EQUIV_TERM_ELEM+GSXML.LIST_MODIFIER);
473 term_elem.appendChild(equiv_term_list);
474
475 for (int et = 0; et < equiv_terms.size(); et++) {
476 String equiv_term = (String) equiv_terms.get(et);
477
478 Element equiv_term_elem = doc_.createElement(GSXML.TERM_ELEM);
479 equiv_term_elem.setAttribute(GSXML.NAME_ATT, equiv_term);
480 equiv_term_elem.setAttribute(NUM_DOCS_MATCH_ATT, "");
481 equiv_term_elem.setAttribute(FREQ_ATT, "");
482 equiv_term_list.appendChild(equiv_term_elem);
483 }
484
485 term_list.appendChild(term_elem);
486 }
487
488 return result;
489 }
490
491 // should probably use a list rather than map
492 protected boolean setStandardQueryParams(HashMap params) {
493
494 Set entries = params.entrySet();
495 Iterator i = entries.iterator();
496 while (i.hasNext()) {
497 Map.Entry m = (Map.Entry)i.next();
498 String name = (String)m.getKey();
499 String value = (String)m.getValue();
500
501 if (name.equals(CASE_PARAM)) {
502 boolean val = (value.equals(BOOLEAN_PARAM_ON)?true:false);
503 mgpp_src_.setCase(val);
504 } else if (name.equals(STEM_PARAM)) {
505 boolean val = (value.equals(BOOLEAN_PARAM_ON)?true:false);
506 mgpp_src_.setStem(val);
507 } else if (name.equals(MAXDOCS_PARAM)&& !value.equals("")) {
508 int docs = Integer.parseInt(value);
509 mgpp_src_.setMaxDocs(docs);
510 } else if (name.equals(LEVEL_PARAM)) {
511 mgpp_src_.setQueryLevel(value);
512 } else if (name.equals(MATCH_PARAM)) {
513 int mode;
514 if (value.equals(MATCH_PARAM_ALL)) mode=1;
515 else mode=0;
516 mgpp_src_.setMatchMode(mode);
517 } else if (name.equals(RANK_PARAM)) {
518 if (value.equals(RANK_PARAM_RANK)) {
519 mgpp_src_.setSortByRank(true);
520 } else if (value.equals(RANK_PARAM_NONE)) {
521 mgpp_src_.setSortByRank(false);
522 }
523 } // ignore any others
524 }
525 return true;
526 }
527
528 protected String addFieldInfo(String query, String field) {
529 if (field.equals("") || field.equals("ZZ")) {
530 return query;
531 }
532 return "["+query+"]:"+field;
533 }
534 /** combines all the field params into a single query
535 * - for simple field query */
536 protected String parseFieldQueryParams(HashMap params) {
537
538 StringBuffer final_query = new StringBuffer(256);
539 String text_line = (String)params.get(FIELD_QUERY_PARAM);
540 String[] texts = text_line.split(",", -1);
541 String field_line = (String)params.get(FIELD_FIELD_PARAM);
542 String[] fields = field_line.split(",", -1);
543 String combine="&";
544 String match = (String)params.get(MATCH_PARAM);
545 if (match.equals(MATCH_PARAM_SOME)) {
546 combine = "|";
547 }
548
549 for (int i=0; i<texts.length; i++) {
550
551 String q = texts[i].trim();
552 if (!q.equals("")) {
553 addQueryElem(final_query, q, fields[i], combine);
554 }
555 }
556
557 return final_query.toString();
558 }
559
560 /** combines all the field params into a single query
561 * - for advanced field query */
562 protected String parseAdvancedFieldQueryParams(HashMap params) {
563
564 StringBuffer final_query = new StringBuffer(256);
565 String text_line = (String)params.get(FIELD_QUERY_PARAM);
566 String[] texts = text_line.split(",", -1);
567 String field_line = (String)params.get(FIELD_FIELD_PARAM);
568 String[] fields = field_line.split(",", -1);
569 String case_line = (String)params.get(FIELD_CASE_PARAM);
570 String[] cases = case_line.split(",", -1);
571 String stem_line = (String)params.get(FIELD_STEM_PARAM);
572 String[] stems = stem_line.split(",", -1);
573 String combine_line = (String)params.get(FIELD_COMBINE_PARAM);
574 String [] combines = combine_line.split(",", -1);
575 String combine = "&";
576 for (int i=0; i<texts.length; i++) {
577 if (i==0) {// assume first one is blank
578 combine = "";
579 } else {
580 String x = combines[i];
581 if (x.equals(FIELD_COMBINE_PARAM_AND)) {
582 combine = "&";
583 } else if (x.equals(FIELD_COMBINE_PARAM_OR)) {
584 combine = "|";
585 } else if (x.equals(FIELD_COMBINE_PARAM_NOT)) {
586 combine = "!";
587 }
588
589 }
590
591 String q = texts[i].trim();
592 if (!q.equals("")) {
593 q = addStemAndCase(q, stems[i], cases[i]);
594 addQueryElem(final_query, q, fields[i], combine);
595 }
596 }
597
598 return final_query.toString();
599 }
600
601 protected void addQueryElem(StringBuffer s, String q, String f, String c) {
602
603 String combine="";
604 if (s.length()>0) {
605 combine = " "+c+" ";
606 }
607 if (f.equals("")||f.equals("ZZ")) {
608 s.append(combine+q);
609 } else {
610 s.append(combine+"["+q+"]:"+f);
611 }
612 }
613
614 protected String addStemAndCase(String q, String s, String c) {
615 String mods = "#";
616 if (c.equals("1")) {
617 mods += "i";
618 } else {
619 mods += "c";
620 }
621 if (s.equals("1")) {
622 mods += "s";
623 } else {
624 mods+= "u";
625 }
626 StringBuffer temp = new StringBuffer();
627 String [] terms = q.split(" ");
628 for (int i=0; i<terms.length; i++) {
629 String t = terms[i].trim();
630
631 if (!t.equals("") && !t.equals("TX")) {
632 temp.append(" "+t+mods);
633 }
634 }
635 return temp.toString();
636 }
637
638
639}
640
641
Note: See TracBrowser for help on using the repository browser.