source: gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java@ 24647

Last change on this file since 24647 was 24647, checked in by davidb, 13 years ago

Addition files to patch Lucene code in main Greenstone 3 service area

  • Property svn:executable set to *
File size: 5.1 KB
Line 
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
19package org.greenstone.gsdl3.service;
20
21// Greenstone classes
22import org.greenstone.gsdl3.util.*;
23
24// XML classes
25import org.w3c.dom.Element;
26import org.w3c.dom.NodeList;
27import org.w3c.dom.Document;
28// java classes
29import java.util.ArrayList;
30import java.util.HashMap;
31import java.io.File;
32import java.util.Iterator;
33import java.util.Set;
34import java.util.Map;
35import java.util.Vector;
36
37// Logging
38import org.apache.log4j.Logger;
39
40import org.greenstone.LuceneWrapper.SharedSoleneQueryResult;
41import org.greenstone.LuceneWrapper.SharedSoleneQuery;
42
43// Shared code for Solr and Lucene GS2FieldSearch
44
45public 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
95 ArrayList fields = new ArrayList();
96 fields.add(RANK_PARAM_RANK_VALUE);
97 ArrayList field_names = new ArrayList();
98 field_names.add(getTextString("param.sortBy.rank", lang));
99 getSortByIndexData(fields, field_names, lang);
100
101 param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names );
102 }
103 if (param != null) {
104 param_list.appendChild(param);
105 } else {
106 super.createParameter(name, param_list, lang);
107 }
108 }
109
110 protected void getSortByIndexData(ArrayList index_ids, ArrayList index_names, String lang) {
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) {
137 if (field.equals("") || field.equals("ZZ")) {
138 return query;
139 }
140 return field+":("+query+")";
141 }
142
143 protected void addQueryElem(StringBuffer s, String q, String f, String c) {
144
145 String combine="";
146 if (s.length()>0) {
147 combine = " "+c+" ";
148 }
149 s.append(combine + addFieldInfo(q,f));
150 }
151
152 /** Lucene/Solr doesn't use these options at the moment */
153 protected String addStemOptions(String query, String stem,
154 String casef, String accent)
155 {
156 return query;
157 }
158
159 /** Lucene/Solr does not use internal ids. It just uses hash ids. So we need
160 to override these methods so no conversion is done. */
161 /** convert indexer internal id to Greenstone oid */
162 protected String internalNum2OID(long docnum)
163 {
164 return Long.toString(docnum);
165 }
166
167 protected String internalNum2OID(String docnum)
168 {
169 return docnum;
170
171 }
172}
Note: See TracBrowser for help on using the repository browser.