source: trunk/java-client/org/nzdl/gsdl/service/NzdlQuery.java@ 2921

Last change on this file since 2921 was 2921, checked in by cs025, 22 years ago

Added stuff to cope with Metadata settings being controlled separately.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/*
2 * NzdlQuery.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20//the package we're in
21package org.nzdl.gsdl.service;
22
23import java.util.HashMap;
24import java.util.Map;
25import java.util.Set;
26import java.util.Collection;
27
28import org.nzdl.gsdl.util.NzdlConstants;
29
30/**
31 * NzdlQuery is an object that holds the options for a query and is
32 * easily configured by the user.
33 *
34 * @author Stuart Yeates ([email protected])
35 * @author Aziz Mahoui ([email protected])
36 * @author Gordon Paynter ([email protected])
37 * @author Brett Sheeran ([email protected]) (comments)
38 * @version $Revision: 2921 $
39 */
40
41public class NzdlQuery extends java.lang.Object
42 implements java.io.Serializable{
43
44
45 private Map m_Options = null;
46
47 /**
48 * Creates an instance of NzdlQuery with an empty query string.
49 * This can then be used as a constructor parameter when creating a
50 * {@link NzdlRequest NzdlRequest} object for servicing by a
51 * {@link NzdlService NzdlService} object.
52 * Default values for a NzdlQuery object are: maxDocs 200, startResults= 1,
53 * endResults= 10, queryType= "ranked", caseFolding= true, stemming= false,
54 * queryTerm= "".
55 */
56 public NzdlQuery() {
57 m_Options = new HashMap();
58 setQueryTerm ( NzdlConstants.DEFAULT_QUERY_TERM );
59 setQueryType ( NzdlConstants.DEFAULT_QUERY_TYPE );
60 setCaseFolding ( NzdlConstants.DEFAULT_CASE_FOLDING );
61 setStemming ( NzdlConstants.DEFAULT_STEMMING );
62 setStartResults( NzdlConstants.DEFAULT_START_RESULTS );
63 setEndResults ( NzdlConstants.DEFAULT_END_RESULTS );
64 setMaxDocs ( NzdlConstants.DEFAULT_MAX_DOCS );
65 setMetadata ( NzdlConstants.DEFAULT_QUERY_META);
66 }
67
68 /**
69 * Creates an instance of NzdlQuery with a value for query string. Has the
70 * same default values as NzdlQuery(), with the exception of term which is
71 * loaded into the query string field.
72 * @param term the query string
73 */
74 public NzdlQuery( String _term ) {
75 m_Options = new HashMap();
76 setQueryTerm ( _term );
77 setQueryType ( NzdlConstants.DEFAULT_QUERY_TYPE );
78 setCaseFolding ( NzdlConstants.DEFAULT_CASE_FOLDING );
79 setStemming ( NzdlConstants.DEFAULT_STEMMING );
80 setStartResults( NzdlConstants.DEFAULT_START_RESULTS );
81 setEndResults ( NzdlConstants.DEFAULT_END_RESULTS );
82 setMaxDocs ( NzdlConstants.DEFAULT_MAX_DOCS );
83 }
84
85 /**
86 * Sets the expression to be queried. Note: this can also be done using the
87 * constructor.
88 * @param term the query expression string
89 */
90 public void setQueryTerm(String _term) {
91 m_Options.put("Term", _term);
92 }
93
94 /**
95 * Sets the query type as either "ranked" or "boolean". "ranked"
96 * orders results by suitability. "boolean" allows use of operators such as
97 * !, &, |. Default is "ranked"
98 * @param type "ranked" or "boolean"
99 */
100 public void setQueryType(String _type) {
101 m_Options.put("QueryType", _type);
102 }
103
104 /**
105 * Sets query to ignore case. Default is true.
106 * @param case if false then sets query to be case sensitive. If true
107 * then sets query to be case insenstive.
108 *
109 * removed the string version - surely we only need a boolean method here
110 * Dave
111 *
112 public void setCaseFolding(String _case) {
113 m_Options.put("CaseFold", _case);
114 }
115 */
116
117 /**
118 * Sets query to ignore case. Default is true.
119 * @param case if false then sets query to be case sensitive. If true
120 * then sets query to be case insenstive.
121 */
122
123 public void setCaseFolding(boolean _case) {
124 if (_case == false)
125 m_Options.put("CaseFold", "false");
126 else
127 m_Options.put("CaseFold", "true");
128 }
129
130 /**
131 * Sets query to ignore word endings. Default is "false."
132 * @param stem if "true", sets query to strip endings such as "...ing",
133 * "...ed". If "false", sets query to only match whole words.
134 *
135 public void setStemming(String _stem) {
136 m_Options.put("Stem", _stem);
137 }
138 *
139 * removed the string version - surely we only need a boolean method here
140 * Dave
141 */
142
143 /**
144 * Sets query to ignore word endings. Default is "false."
145 * @param stem if "true", sets query to strip endings such as "...ing",
146 * "...ed". If "false", sets query to only match whole words.
147 */
148 public void setStemming(boolean _stem) {
149 if (_stem == true)
150 m_Options.put("Stem", "true");
151 else
152 m_Options.put("Stem", "false");
153 }
154
155 /**
156 * Sets the maximum number of documents that can be found by a query.
157 * Default is 200.
158 * @param max The maximum permitted number of documents to be found
159 * by the query
160 */
161 public void setMaxDocs(int _max) {
162 m_Options.put("Maxdocs", new Integer(_max));
163 }
164
165 /**
166 * Sets the start number of the result set. The result set is a subset
167 * of the maximum number of documents that will be found by the query.
168 * Default is 1.
169 * @param start the number of the first document, relative to the found
170 * documents
171 */
172 public void setStartResults(int _start) {
173 m_Options.put("StartResults", new Integer(_start));
174 }
175
176 /**
177 * Sets the end number of the result set. The result set is a subset of the
178 * maximum number documents that could be found by that query.
179 * Default is 10.
180 * @param end the number of the last document relative to the found
181 * documents
182 */
183 public void setEndResults(int _end) {
184 m_Options.put("EndResults", new Integer(_end));
185 }
186
187 /**
188 * Set the retrieval of extended Metadata information in the result set.
189 * The default is off (false)
190 * @param whether to retrieve metadata.
191 */
192 public void setMetadata(boolean _set)
193 { m_Options.put("Metadata", new Boolean(_set));
194 }
195
196 /**
197 * Returns whether query is "ranked" or "boolean". "ranked" orders results by
198 * suitability. "boolean" allows use of operators such as !, &, |. Default is
199 * "ranked"
200 * @return Either "ranked" or "boolean"
201 */
202 public String getQueryType() {
203 return (String)m_Options.get("QueryType");
204 }
205
206 /**
207 * Returns the query string expression.
208 * @return the query string
209 */
210 public String getQueryTerm() {
211 return (String)m_Options.get("Term");
212 }
213
214 /**
215 * Returns "true" if query is case insenstive. Default is "true"
216 * @return "true" if query is case insenstive, "false" if the query is case
217 * senstive.
218 */
219 public String getCaseFolding() {
220 return (String)m_Options.get("CaseFold");
221 }
222
223 public boolean isCaseFolding() {
224 return ((String)m_Options.get("CaseFold") == "true");
225 }
226
227 /**
228 * Returns "true" if query ignores word endings. Default is "false".
229 * @return "true" if query strips endings such as "...ing" or "...ed" , false
230 * if query only matches whole words.
231 */
232 public String getStemming() {
233 return (String)m_Options.get("Stem");
234 }
235
236 public boolean isStemming() {
237 return ((String)m_Options.get("Stem") == "true");
238 }
239
240
241 /**
242 * Returns the current setting for the maximum number of documents that
243 * may be found by a query. Default is 200.
244 * @return The maximum number of documents to be found
245 */
246 public int getMaxDocs() {
247 return ((Integer) m_Options.get("Maxdocs")).intValue();
248 }
249
250 /**
251 * Returns the start number of the result set. The result set is a subset of
252 * the maximum number of documents that could be found by the query.
253 * Default is 1.
254 * @return The number of the first document relative to the documents that
255 * were found to match the query
256 */
257 public int getStartResults() {
258 return ((Integer) m_Options.get("StartResults")).intValue();
259 }
260
261 /**
262 * Returns the end number of the result set. The result set is a subset of
263 * the maximum number documents that could be found by the query.
264 * Default is 10.
265 * @return The number of the last document relative to the documents that
266 * were found to match the query.
267 */
268 public int getEndResults() {
269 return ((Integer) m_Options.get("EndResults")).intValue();
270 }
271
272 /**
273 * Get the retrieval of extended Metadata information in the result set.
274 * The default is off (false)
275 * @return whether to retrieve metadata.
276 */
277 public boolean getMetadata()
278 { return ((Boolean) m_Options.get("Metadata")).booleanValue();
279 }
280
281 /**
282 * Returns the set of query terms.
283 * @return This set: "EndResults", "QueryType", "Term", "MaxDocs",
284 * "StartResults", "Stem", "CaseFold"
285 */
286 public Set queryKeySet() {
287 return m_Options.keySet();
288 }
289
290 /**
291 * Returns a collection of the current query values.
292 * @return For a default query this collection: 10, "ranked", "", 200, 1
293 * , false, true
294 */
295 public Collection queryValues() {
296 return m_Options.values();
297 }
298
299}
300
Note: See TracBrowser for help on using the repository browser.