[24722] | 1 | /*
|
---|
| 2 | * SharedSoleneGS2FieldSearch.java -- shared base code for Solr and Lucene
|
---|
| 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 |
|
---|
| 19 | package org.greenstone.gsdl3.service;
|
---|
| 20 |
|
---|
| 21 | // Greenstone classes
|
---|
| 22 | import org.greenstone.gsdl3.util.*;
|
---|
| 23 |
|
---|
| 24 | // XML classes
|
---|
| 25 | import org.w3c.dom.Element;
|
---|
| 26 | import org.w3c.dom.NodeList;
|
---|
| 27 | import org.w3c.dom.Document;
|
---|
| 28 | // java classes
|
---|
| 29 | import java.util.ArrayList;
|
---|
| 30 | import java.util.HashMap;
|
---|
| 31 | import java.io.File;
|
---|
| 32 | import java.util.Iterator;
|
---|
| 33 | import java.util.Set;
|
---|
| 34 | import java.util.Map;
|
---|
| 35 | import java.util.Vector;
|
---|
| 36 |
|
---|
| 37 | // Logging
|
---|
| 38 | import org.apache.log4j.Logger;
|
---|
| 39 |
|
---|
[24738] | 40 | import org.greenstone.LuceneWrapper3.SharedSoleneQueryResult;
|
---|
| 41 | import org.greenstone.LuceneWrapper3.SharedSoleneQuery;
|
---|
[24722] | 42 |
|
---|
| 43 | // Shared code for Solr and Lucene GS2FieldSearch
|
---|
| 44 |
|
---|
| 45 | public abstract class SharedSoleneGS2FieldSearch extends AbstractGS2FieldSearch
|
---|
| 46 | {
|
---|
| 47 | protected static final String RANK_PARAM_RANK_VALUE = "rank";
|
---|
| 48 |
|
---|
| 49 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.SharedSoleneGS2FieldSearch.class.getName());
|
---|
| 50 |
|
---|
| 51 | protected SharedSoleneQuery solene_src=null;
|
---|
| 52 |
|
---|
| 53 | public SharedSoleneGS2FieldSearch()
|
---|
| 54 | {
|
---|
| 55 | // Lucene/Solr uses double operators, not single
|
---|
| 56 | AND_OPERATOR = "&&";
|
---|
| 57 | OR_OPERATOR = "||";
|
---|
| 58 |
|
---|
| 59 | does_paging = true;
|
---|
| 60 | does_chunking = true;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /** configure this service */
|
---|
| 65 | public boolean configure(Element info, Element extra_info)
|
---|
| 66 | {
|
---|
| 67 | if (!super.configure(info, extra_info)){
|
---|
| 68 | return false;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | // Lucene/Solr doesn't do case folding or stemming or accent folding at the
|
---|
| 72 | // moment
|
---|
| 73 | does_case = false;
|
---|
| 74 | does_stem = false;
|
---|
| 75 | does_accent = false;
|
---|
| 76 |
|
---|
| 77 | return true;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | /** add in the Lucene/Solr specific params to TextQuery */
|
---|
| 81 | protected void addCustomQueryParams(Element param_list, String lang)
|
---|
| 82 | {
|
---|
| 83 | super.addCustomQueryParams(param_list, lang);
|
---|
| 84 | /** Lucene's/Solr's rank param is based on index fields, not ranked/not */
|
---|
| 85 | createParameter(RANK_PARAM, param_list, lang);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /** create a param and add to the list */
|
---|
| 89 | /** we override this to do a special rank param */
|
---|
| 90 | protected void createParameter(String name, Element param_list, String lang)
|
---|
| 91 | {
|
---|
| 92 | Element param = null;
|
---|
| 93 | if (name.equals(RANK_PARAM)) {
|
---|
| 94 | // get the fields
|
---|
[25635] | 95 | ArrayList<String> fields = new ArrayList<String>();
|
---|
[24722] | 96 | fields.add(RANK_PARAM_RANK_VALUE);
|
---|
[25635] | 97 | ArrayList<String> field_names = new ArrayList<String>();
|
---|
[24722] | 98 | field_names.add(getTextString("param.sortBy.rank", lang));
|
---|
| 99 | getSortByIndexData(fields, field_names, lang);
|
---|
| 100 |
|
---|
[25635] | 101 | param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names );
|
---|
[24722] | 102 | }
|
---|
| 103 | if (param != null) {
|
---|
| 104 | param_list.appendChild(param);
|
---|
| 105 | } else {
|
---|
| 106 | super.createParameter(name, param_list, lang);
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[25635] | 110 | protected void getSortByIndexData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang) {
|
---|
[24722] | 111 | // the index info -
|
---|
| 112 | Element index_list = (Element)GSXML.getChildByTagName(this.config_info, INDEX_ELEM+GSXML.LIST_MODIFIER);
|
---|
| 113 | NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM);
|
---|
| 114 | int len = indexes.getLength();
|
---|
| 115 | // now add even if there is only one
|
---|
| 116 | for (int i=0; i<len; i++) {
|
---|
| 117 | Element index = (Element)indexes.item(i);
|
---|
| 118 | String shortname = index.getAttribute(GSXML.SHORTNAME_ATT);
|
---|
| 119 | if (shortname.equals("") || shortname.equals("ZZ") || shortname.equals("TX")) {
|
---|
| 120 | continue;
|
---|
| 121 | }
|
---|
| 122 | index_ids.add("by"+shortname);
|
---|
| 123 | String display_name = GSXML.getDisplayText(index, GSXML.DISPLAY_TEXT_NAME, lang, "en");
|
---|
| 124 | if (display_name.equals("")) {
|
---|
| 125 | display_name = index.getAttribute(GSXML.NAME_ATT);
|
---|
| 126 | if (display_name.equals("")) {
|
---|
| 127 | display_name = shortname;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | index_names.add(display_name);
|
---|
| 131 |
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | protected String addFieldInfo(String query, String field) {
|
---|
[25726] | 137 | // currently, allfields (ZZ) is stored as a extra field for Lucene
|
---|
| 138 | if (field.equals("")) { // || field.equals("ZZ")) {
|
---|
[24722] | 139 | return query;
|
---|
| 140 | }
|
---|
| 141 | return field+":("+query+")";
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | protected void addQueryElem(StringBuffer s, String q, String f, String c) {
|
---|
| 145 |
|
---|
| 146 | String combine="";
|
---|
| 147 | if (s.length()>0) {
|
---|
| 148 | combine = " "+c+" ";
|
---|
| 149 | }
|
---|
| 150 | s.append(combine + addFieldInfo(q,f));
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | /** Lucene/Solr doesn't use these options at the moment */
|
---|
| 154 | protected String addStemOptions(String query, String stem,
|
---|
| 155 | String casef, String accent)
|
---|
| 156 | {
|
---|
| 157 | return query;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /** Lucene/Solr does not use internal ids. It just uses hash ids. So we need
|
---|
| 161 | to override these methods so no conversion is done. */
|
---|
| 162 | /** convert indexer internal id to Greenstone oid */
|
---|
| 163 | protected String internalNum2OID(long docnum)
|
---|
| 164 | {
|
---|
| 165 | return Long.toString(docnum);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | protected String internalNum2OID(String docnum)
|
---|
| 169 | {
|
---|
| 170 | return docnum;
|
---|
| 171 |
|
---|
| 172 | }
|
---|
| 173 | }
|
---|