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

Last change on this file since 2316 was 2257, checked in by daven, 23 years ago

added isStemming and isCaseFolding as accessor methods to
provide symmetry with the new set methods.
Didn't delete the string versions - but I don't see a good reason
to keep them...

  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 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: 2257 $
39 */
40
41public class NzdlQuery extends java.lang.Object {
42
43
44 private Map m_Options = null;
45
46 /**
47 * Creates an instance of NzdlQuery with an empty query string.
48 * This can then be used as a constructor parameter when creating a
49 * {@link NzdlRequest NzdlRequest} object for servicing by a
50 * {@link NzdlService NzdlService} object.
51 * Default values for a NzdlQuery object are: maxDocs 200, startResults= 1,
52 * endResults= 10, queryType= "ranked", caseFolding= true, stemming= false,
53 * queryTerm= "".
54 */
55 public NzdlQuery() {
56 m_Options = new HashMap();
57 setQueryTerm ( NzdlConstants.DEFAULT_QUERY_TERM );
58 setQueryType ( NzdlConstants.DEFAULT_QUERY_TYPE );
59 setCaseFolding ( NzdlConstants.DEFAULT_CASE_FOLDING );
60 setStemming ( NzdlConstants.DEFAULT_STEMMING );
61 setStartResults( NzdlConstants.DEFAULT_START_RESULTS );
62 setEndResults ( NzdlConstants.DEFAULT_END_RESULTS );
63 setMaxDocs ( NzdlConstants.DEFAULT_MAX_DOCS );
64 }
65
66 /**
67 * Creates an instance of NzdlQuery with a value for query string. Has the
68 * same default values as NzdlQuery(), with the exception of term which is
69 * loaded into the query string field.
70 * @param term the query string
71 */
72 public NzdlQuery( String _term ) {
73 m_Options = new HashMap();
74 setQueryTerm ( _term );
75 setQueryType ( NzdlConstants.DEFAULT_QUERY_TYPE );
76 setCaseFolding ( NzdlConstants.DEFAULT_CASE_FOLDING );
77 setStemming ( NzdlConstants.DEFAULT_STEMMING );
78 setStartResults( NzdlConstants.DEFAULT_START_RESULTS );
79 setEndResults ( NzdlConstants.DEFAULT_END_RESULTS );
80 setMaxDocs ( NzdlConstants.DEFAULT_MAX_DOCS );
81 }
82
83 /**
84 * Sets the expression to be queried. Note: this can also be done using the
85 * constructor.
86 * @param term the query expression string
87 */
88 public void setQueryTerm(String _term) {
89 m_Options.put("Term", _term);
90 }
91
92 /**
93 * Sets the query type as either "ranked" or "boolean". "ranked"
94 * orders results by suitability. "boolean" allows use of operators such as
95 * !, &, |. Default is "ranked"
96 * @param type "ranked" or "boolean"
97 */
98 public void setQueryType(String _type) {
99 m_Options.put("QueryType", _type);
100 }
101
102 /**
103 * Sets query to ignore case. Default is true.
104 * @param case if false then sets query to be case sensitive. If true
105 * then sets query to be case insenstive.
106 *
107 * removed the string version - surely we only need a boolean method here
108 * Dave
109 *
110 public void setCaseFolding(String _case) {
111 m_Options.put("CaseFold", _case);
112 }
113 */
114
115 /**
116 * Sets query to ignore case. Default is true.
117 * @param case if false then sets query to be case sensitive. If true
118 * then sets query to be case insenstive.
119 */
120
121 public void setCaseFolding(boolean _case) {
122 if (_case == false)
123 m_Options.put("CaseFold", "false");
124 else
125 m_Options.put("CaseFold", "true");
126 }
127
128 /**
129 * Sets query to ignore word endings. Default is "false."
130 * @param stem if "true", sets query to strip endings such as "...ing",
131 * "...ed". If "false", sets query to only match whole words.
132 *
133 public void setStemming(String _stem) {
134 m_Options.put("Stem", _stem);
135 }
136 *
137 * removed the string version - surely we only need a boolean method here
138 * Dave
139 */
140
141 /**
142 * Sets query to ignore word endings. Default is "false."
143 * @param stem if "true", sets query to strip endings such as "...ing",
144 * "...ed". If "false", sets query to only match whole words.
145 */
146 public void setStemming(boolean _stem) {
147 if (_stem == true)
148 m_Options.put("Stem", "true");
149 else
150 m_Options.put("Stem", "false");
151 }
152
153 /**
154 * Sets the maximum number of documents that can be found by a query.
155 * Default is 200.
156 * @param max The maximum permitted number of documents to be found
157 * by the query
158 */
159 public void setMaxDocs(int _max) {
160 m_Options.put("Maxdocs", new Integer(_max));
161 }
162
163 /**
164 * Sets the start number of the result set. The result set is a subset
165 * of the maximum number of documents that will be found by the query.
166 * Default is 1.
167 * @param start the number of the first document, relative to the found
168 * documents
169 */
170 public void setStartResults(int _start) {
171 m_Options.put("StartResults", new Integer(_start));
172 }
173
174 /**
175 * Sets the end number of the result set. The result set is a subset of the
176 * maximum number documents that could be found by that query.
177 * Default is 10.
178 * @param end the number of the last document relative to the found
179 * documents
180 */
181 public void setEndResults(int _end) {
182 m_Options.put("EndResults", new Integer(_end));
183 }
184
185 /**
186 * Returns whether query is "ranked" or "boolean". "ranked" orders results by
187 * suitability. "boolean" allows use of operators such as !, &, |. Default is
188 * "ranked"
189 * @return Either "ranked" or "boolean"
190 */
191 public String getQueryType() {
192 return (String)m_Options.get("QueryType");
193 }
194
195 /**
196 * Returns the query string expression.
197 * @return the query string
198 */
199 public String getQueryTerm() {
200 return (String)m_Options.get("Term");
201 }
202
203 /**
204 * Returns "true" if query is case insenstive. Default is "true"
205 * @return "true" if query is case insenstive, "false" if the query is case
206 * senstive.
207 */
208 public String getCaseFolding() {
209 return (String)m_Options.get("CaseFold");
210 }
211
212 public boolean isCaseFolding() {
213 return ((String)m_Options.get("CaseFold") == "true");
214 }
215
216 /**
217 * Returns "true" if query ignores word endings. Default is "false".
218 * @return "true" if query strips endings such as "...ing" or "...ed" , false
219 * if query only matches whole words.
220 */
221 public String getStemming() {
222 return (String)m_Options.get("Stem");
223 }
224
225 public boolean isStemming() {
226 return ((String)m_Options.get("Stem") == "true");
227 }
228
229
230 /**
231 * Returns the current setting for the maximum number of documents that
232 * may be found by a query. Default is 200.
233 * @return The maximum number of documents to be found
234 */
235 public int getMaxDocs() {
236 return ((Integer) m_Options.get("Maxdocs")).intValue();
237 }
238
239 /**
240 * Returns the start number of the result set. The result set is a subset of
241 * the maximum number of documents that could be found by the query.
242 * Default is 1.
243 * @return The number of the first document relative to the documents that
244 * were found to match the query
245 */
246 public int getStartResults() {
247 return ((Integer) m_Options.get("StartResults")).intValue();
248 }
249
250 /**
251 * Returns the end number of the result set. The result set is a subset of
252 * the maximum number documents that could be found by the query.
253 * Default is 10.
254 * @return The number of the last document relative to the documents that
255 * were found to match the query.
256 */
257 public int getEndResults() {
258 return ((Integer) m_Options.get("EndResults")).intValue();
259 }
260
261 /**
262 * Returns the set of query terms.
263 * @return This set: "EndResults", "QueryType", "Term", "MaxDocs",
264 * "StartResults", "Stem", "CaseFold"
265 */
266 public Set queryKeySet() {
267 return m_Options.keySet();
268 }
269
270 /**
271 * Returns a collection of the current query values.
272 * @return For a default query this collection: 10, "ranked", "", 200, 1
273 * , false, true
274 */
275 public Collection queryValues() {
276 return m_Options.values();
277 }
278
279}
280
Note: See TracBrowser for help on using the repository browser.