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