Changeset 25853
- Timestamp:
- 2012-06-28T11:24:00+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java
r25726 r25853 1 1 /* 2 * SharedSoleneGS2FieldSearch.java -- shared base code for Solr and Lucene3 * Copyright (C) 2006 New Zealand Digital Library, http://www.nzdl.org4 *5 * This program is free software; you can redistribute it and/or modify6 * the Free Software Foundation; either version 2 of the License, or7 * (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 of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with this program; if not, write to the Free Software16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.17 */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 18 19 19 package org.greenstone.gsdl3.service; 20 20 21 21 // Greenstone classes 22 import org.greenstone.gsdl3.util.*;22 import java.util.ArrayList; 23 23 24 // XML classes 25 import org.w3c.dom.Element; 24 import org.apache.log4j.Logger; 25 import org.greenstone.LuceneWrapper3.SharedSoleneQuery; 26 import org.greenstone.gsdl3.util.GSXML; 27 import org.w3c.dom.Element; 26 28 import org.w3c.dom.NodeList; 27 import org.w3c.dom.Document;28 // java classes29 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 // Logging38 import org.apache.log4j.Logger;39 40 import org.greenstone.LuceneWrapper3.SharedSoleneQueryResult;41 import org.greenstone.LuceneWrapper3.SharedSoleneQuery;42 29 43 30 // Shared code for Solr and Lucene GS2FieldSearch … … 45 32 public abstract class SharedSoleneGS2FieldSearch extends AbstractGS2FieldSearch 46 33 { 47 34 protected static final String RANK_PARAM_RANK_VALUE = "rank"; 48 35 49 36 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.SharedSoleneGS2FieldSearch.class.getName()); 50 37 51 protected SharedSoleneQuery solene_src=null; 38 protected SharedSoleneQuery solene_src = null; 52 39 53 54 55 // Lucene/Solr uses double operators, not single56 AND_OPERATOR = "&&";57 OR_OPERATOR = "||";40 public SharedSoleneGS2FieldSearch() 41 { 42 // Lucene/Solr uses double operators, not single 43 AND_OPERATOR = "&&"; 44 OR_OPERATOR = "||"; 58 45 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; 46 does_paging = true; 47 does_chunking = true; 69 48 } 70 71 // Lucene/Solr doesn't do case folding or stemming or accent folding at the72 // moment73 does_case = false;74 does_stem = false;75 does_accent = false;76 49 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 { 50 /** configure this service */ 51 public boolean configure(Element info, Element extra_info) 52 { 53 if (!super.configure(info, extra_info)) 54 { 55 return false; 56 } 57 58 // Lucene/Solr doesn't do case folding or stemming or accent folding at the 59 // moment 60 does_case = false; 61 does_stem = false; 62 does_accent = false; 63 64 return true; 65 } 66 67 /** add in the Lucene/Solr specific params to TextQuery */ 68 protected void addCustomQueryParams(Element param_list, String lang) 69 { 70 super.addCustomQueryParams(param_list, lang); 71 /** Lucene's/Solr's rank param is based on index fields, not ranked/not */ 72 createParameter(RANK_PARAM, param_list, lang); 73 } 74 75 /** create a param and add to the list */ 76 /** we override this to do a special rank param */ 77 protected void createParameter(String name, Element param_list, String lang) 78 { 92 79 Element param = null; 93 if (name.equals(RANK_PARAM)) { 80 if (name.equals(RANK_PARAM)) 81 { 94 82 // get the fields 95 83 ArrayList<String> fields = new ArrayList<String>(); 96 84 fields.add(RANK_PARAM_RANK_VALUE); 97 85 ArrayList<String> field_names = new ArrayList<String>(); 98 field_names.add(getTextString("param.sortBy.rank", lang)); 86 field_names.add(getTextString("param.sortBy.rank", lang)); 99 87 getSortByIndexData(fields, field_names, lang); 100 101 param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." +name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);88 89 param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names); 102 90 } 103 if (param != null) { 91 if (param != null) 92 { 104 93 param_list.appendChild(param); 105 } else { 94 } 95 else 96 { 106 97 super.createParameter(name, param_list, lang); 107 98 } 108 99 } 109 110 protected void getSortByIndexData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang) { 100 101 protected void getSortByIndexData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang) 102 { 111 103 // the index info - 112 Element index_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_ELEM+GSXML.LIST_MODIFIER);104 Element index_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_ELEM + GSXML.LIST_MODIFIER); 113 105 NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM); 114 106 int len = indexes.getLength(); 115 107 // now add even if there is only one 116 for (int i=0; i<len; i++) { 117 Element index = (Element)indexes.item(i); 108 for (int i = 0; i < len; i++) 109 { 110 Element index = (Element) indexes.item(i); 118 111 String shortname = index.getAttribute(GSXML.SHORTNAME_ATT); 119 if (shortname.equals("") || shortname.equals("ZZ") || shortname.equals("TX")) { 112 if (shortname.equals("") || shortname.equals("ZZ") || shortname.equals("TX")) 113 { 120 114 continue; 121 115 } 122 index_ids.add("by" +shortname);116 index_ids.add("by" + shortname); 123 117 String display_name = GSXML.getDisplayText(index, GSXML.DISPLAY_TEXT_NAME, lang, "en"); 124 if (display_name.equals("")) { 118 if (display_name.equals("")) 119 { 125 120 display_name = index.getAttribute(GSXML.NAME_ATT); 126 if (display_name.equals("")) { 121 if (display_name.equals("")) 122 { 127 123 display_name = shortname; 128 124 } 129 125 } 130 126 index_names.add(display_name); 131 127 132 128 } 133 129 134 130 } 135 131 136 protected String addFieldInfo(String query, String field) { 137 // currently, allfields (ZZ) is stored as a extra field for Lucene 138 if (field.equals("")) { // || field.equals("ZZ")) { 139 return query; 132 protected String addFieldInfo(String query, String field) 133 { 134 // currently, allfields (ZZ) is stored as a extra field for Lucene 135 if (field.equals("")) 136 { // || field.equals("ZZ")) { 137 return query; 138 } 139 return field + ":(" + query + ")"; 140 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+" "; 141 142 protected void addQueryElem(StringBuffer s, String q, String f, String c) 143 { 144 145 String combine = ""; 146 if (s.length() > 0) 147 { 148 combine = " " + c + " "; 149 } 150 s.append(combine + addFieldInfo(q, f)); 149 151 } 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 152 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 } 153 /** Lucene/Solr doesn't use these options at the moment */ 154 protected String addStemOptions(String query, String stem, String casef, String accent) 155 { 156 return query; 157 } 167 158 168 protected String internalNum2OID(String docnum) 169 { 170 return docnum; 171 172 } 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 */ 163 /** convert indexer internal id to Greenstone oid */ 164 protected String internalNum2OID(long docnum) 165 { 166 return Long.toString(docnum); 167 } 168 169 protected String internalNum2OID(String docnum) 170 { 171 return docnum; 172 173 } 173 174 }
Note:
See TracChangeset
for help on using the changeset viewer.