source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java@ 25853

Last change on this file since 25853 was 25853, checked in by sjm84, 12 years ago

Reformatting and tidying the imports of this file

  • Property svn:executable set to *
File size: 5.0 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 java.util.ArrayList;
23
24import org.apache.log4j.Logger;
25import org.greenstone.LuceneWrapper3.SharedSoleneQuery;
26import org.greenstone.gsdl3.util.GSXML;
27import org.w3c.dom.Element;
28import org.w3c.dom.NodeList;
29
30// Shared code for Solr and Lucene GS2FieldSearch
31
32public abstract class SharedSoleneGS2FieldSearch extends AbstractGS2FieldSearch
33{
34 protected static final String RANK_PARAM_RANK_VALUE = "rank";
35
36 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.SharedSoleneGS2FieldSearch.class.getName());
37
38 protected SharedSoleneQuery solene_src = null;
39
40 public SharedSoleneGS2FieldSearch()
41 {
42 // Lucene/Solr uses double operators, not single
43 AND_OPERATOR = "&&";
44 OR_OPERATOR = "||";
45
46 does_paging = true;
47 does_chunking = true;
48 }
49
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 {
79 Element param = null;
80 if (name.equals(RANK_PARAM))
81 {
82 // get the fields
83 ArrayList<String> fields = new ArrayList<String>();
84 fields.add(RANK_PARAM_RANK_VALUE);
85 ArrayList<String> field_names = new ArrayList<String>();
86 field_names.add(getTextString("param.sortBy.rank", lang));
87 getSortByIndexData(fields, field_names, lang);
88
89 param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);
90 }
91 if (param != null)
92 {
93 param_list.appendChild(param);
94 }
95 else
96 {
97 super.createParameter(name, param_list, lang);
98 }
99 }
100
101 protected void getSortByIndexData(ArrayList<String> index_ids, ArrayList<String> index_names, String lang)
102 {
103 // the index info -
104 Element index_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_ELEM + GSXML.LIST_MODIFIER);
105 NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM);
106 int len = indexes.getLength();
107 // now add even if there is only one
108 for (int i = 0; i < len; i++)
109 {
110 Element index = (Element) indexes.item(i);
111 String shortname = index.getAttribute(GSXML.SHORTNAME_ATT);
112 if (shortname.equals("") || shortname.equals("ZZ") || shortname.equals("TX"))
113 {
114 continue;
115 }
116 index_ids.add("by" + shortname);
117 String display_name = GSXML.getDisplayText(index, GSXML.DISPLAY_TEXT_NAME, lang, "en");
118 if (display_name.equals(""))
119 {
120 display_name = index.getAttribute(GSXML.NAME_ATT);
121 if (display_name.equals(""))
122 {
123 display_name = shortname;
124 }
125 }
126 index_names.add(display_name);
127
128 }
129
130 }
131
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 }
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));
151 }
152
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 }
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 */
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 }
174}
Note: See TracBrowser for help on using the repository browser.