1 | /** |
---|
2 | * This software is copyright (c) 2011-2022 by |
---|
3 | * - Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
4 | * This is free software. You can redistribute it |
---|
5 | * and/or modify it under the terms described in |
---|
6 | * the GNU General Public License v3 of which you |
---|
7 | * should have received a copy. Otherwise you can download |
---|
8 | * it from |
---|
9 | * |
---|
10 | * http://www.gnu.org/licenses/gpl-3.0.txt |
---|
11 | * |
---|
12 | * @copyright Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
13 | * |
---|
14 | * @license http://www.gnu.org/licenses/gpl-3.0.txt |
---|
15 | * GNU General Public License v3 |
---|
16 | */ |
---|
17 | package eu.clarin.sru.server; |
---|
18 | |
---|
19 | import java.util.NoSuchElementException; |
---|
20 | |
---|
21 | import javax.xml.stream.XMLStreamException; |
---|
22 | import javax.xml.stream.XMLStreamWriter; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | * A result set of a <em>searchRetrieve</em> operation. It it used to iterate |
---|
27 | * over the result set and provides a method to serialize the record in the |
---|
28 | * requested format. |
---|
29 | * <p> |
---|
30 | * A <code>SRUSearchResultSet</code> object maintains a cursor pointing to its |
---|
31 | * current record. Initially the cursor is positioned before the first record. |
---|
32 | * The <code>next</code> method moves the cursor to the next record, and because |
---|
33 | * it returns <code>false</code> when there are no more records in the |
---|
34 | * <code>SRUSearchResultSet</code> object, it can be used in a |
---|
35 | * <code>while</code> loop to iterate through the result set. |
---|
36 | * </p> |
---|
37 | * <p> |
---|
38 | * This class needs to be implemented for the target search engine. |
---|
39 | * </p> |
---|
40 | * |
---|
41 | * @see <a href="http://www.loc.gov/standards/sru/specs/search-retrieve.html"> |
---|
42 | * SRU Search Retrieve Operation</a> |
---|
43 | */ |
---|
44 | public abstract class SRUSearchResultSet extends SRUAbstractResult { |
---|
45 | |
---|
46 | /** |
---|
47 | * Constructor. |
---|
48 | * |
---|
49 | * @param diagnostics |
---|
50 | * an instance of a SRUDiagnosticList |
---|
51 | * @see SRUDiagnosticList |
---|
52 | */ |
---|
53 | protected SRUSearchResultSet(SRUDiagnosticList diagnostics) { |
---|
54 | super(diagnostics); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /** |
---|
59 | * The number of records matched by the query. If the query fails this must |
---|
60 | * be 0. If the search engine cannot determine the total number of matched |
---|
61 | * by a query, it must return -1. |
---|
62 | * |
---|
63 | * @return the total number of results or 0 if the query failed or -1 if the |
---|
64 | * search engine cannot determine the total number of results |
---|
65 | */ |
---|
66 | public abstract int getTotalRecordCount(); |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * The number of records matched by the query but at most as the number of |
---|
71 | * records requested to be returned (maximumRecords parameter). If the query |
---|
72 | * fails this must be 0. |
---|
73 | * |
---|
74 | * @return the number of results or 0 if the query failed |
---|
75 | */ |
---|
76 | public abstract int getRecordCount(); |
---|
77 | |
---|
78 | |
---|
79 | /** |
---|
80 | * The result set id of this result. the default implementation returns |
---|
81 | * <code>null</code>. |
---|
82 | * |
---|
83 | * @return the result set id or <code>null</code> if not applicable for this |
---|
84 | * result |
---|
85 | */ |
---|
86 | public String getResultSetId() { |
---|
87 | return null; |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | /** |
---|
92 | * The result set time to live. In SRU 2.0 it will be serialized as |
---|
93 | * <code><resultSetTTL></code> element; in SRU 1.2 as |
---|
94 | * <code><resultSetIdleTime></code> element.The default implementation |
---|
95 | * returns <code>-1</code>. |
---|
96 | * |
---|
97 | * @return the result set time to live or <code>-1</code> if not applicable for |
---|
98 | * this result |
---|
99 | */ |
---|
100 | public int getResultSetTTL() { |
---|
101 | return -1; |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | /** |
---|
106 | * (SRU 2.0) Indicate the accuracy of the result count reported by total |
---|
107 | * number of records that matched the query. Default implementation returns |
---|
108 | * <code>null</code>. |
---|
109 | * |
---|
110 | * @see SRUResultCountPrecision |
---|
111 | * @return the result count precision or <code>null</code> if not applicable |
---|
112 | * for this result |
---|
113 | */ |
---|
114 | public SRUResultCountPrecision getResultCountPrecision() { |
---|
115 | return null; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | /** |
---|
120 | * The record schema identifier in which the records are returned |
---|
121 | * (recordSchema parameter). |
---|
122 | * |
---|
123 | * @return the record schema identifier |
---|
124 | */ |
---|
125 | public abstract String getRecordSchemaIdentifier(); |
---|
126 | |
---|
127 | |
---|
128 | /** |
---|
129 | * Moves the cursor forward one record from its current position. A |
---|
130 | * <code>SRUSearchResultSet</code> cursor is initially positioned before the |
---|
131 | * first record; the first call to the method <code>next</code> makes the |
---|
132 | * first record the current record; the second call makes the second record |
---|
133 | * the current record, and so on. |
---|
134 | * <p> |
---|
135 | * When a call to the <code>next</code> method returns <code>false</code>, |
---|
136 | * the cursor is positioned after the last record. |
---|
137 | * </p> |
---|
138 | * |
---|
139 | * @return <code>true</code> if the new current record is valid; |
---|
140 | * <code>false</code> if there are no more records |
---|
141 | * @throws SRUException |
---|
142 | * if an error occurred while fetching the next record |
---|
143 | */ |
---|
144 | public abstract boolean nextRecord() throws SRUException; |
---|
145 | |
---|
146 | |
---|
147 | /** |
---|
148 | * An identifier for the current record by which it can unambiguously be |
---|
149 | * retrieved in a subsequent operation. |
---|
150 | * |
---|
151 | * @return identifier for the record or <code>null</code> of none is |
---|
152 | * available |
---|
153 | * @throws NoSuchElementException |
---|
154 | * result set is past all records |
---|
155 | */ |
---|
156 | public abstract String getRecordIdentifier(); |
---|
157 | |
---|
158 | |
---|
159 | /** |
---|
160 | * Get surrogate diagnostic for current record. If this method returns a |
---|
161 | * diagnostic, the writeRecord method will not be called. The default |
---|
162 | * implementation returns <code>null</code>. |
---|
163 | * |
---|
164 | * @return a surrogate diagnostic or <code>null</code> |
---|
165 | */ |
---|
166 | public SRUDiagnostic getSurrogateDiagnostic() { |
---|
167 | return null; |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | /** |
---|
172 | * Serialize the current record in the requested format. |
---|
173 | * |
---|
174 | * @param writer |
---|
175 | * the {@link XMLStreamException} instance to be used |
---|
176 | * @throws XMLStreamException |
---|
177 | * an error occurred while serializing the result |
---|
178 | * @throws NoSuchElementException |
---|
179 | * result set past all records |
---|
180 | * @see #getRecordSchemaIdentifier() |
---|
181 | */ |
---|
182 | public abstract void writeRecord(XMLStreamWriter writer) |
---|
183 | throws XMLStreamException; |
---|
184 | |
---|
185 | |
---|
186 | /** |
---|
187 | * Check, if extra record data should be serialized for the current record. |
---|
188 | * The default implementation returns <code>false</code>. |
---|
189 | * |
---|
190 | * @return <code>true</code> if the record has extra record data |
---|
191 | * @throws NoSuchElementException |
---|
192 | * result set is already advanced past all records |
---|
193 | * @see #writeExtraResponseData(XMLStreamWriter) |
---|
194 | */ |
---|
195 | public boolean hasExtraRecordData() { |
---|
196 | return false; |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | /** |
---|
201 | * Serialize extra record data for the current record. A no-op default |
---|
202 | * implementation is provided for convince. |
---|
203 | * |
---|
204 | * @param writer |
---|
205 | * the {@link XMLStreamException} instance to be used |
---|
206 | * @throws XMLStreamException |
---|
207 | * an error occurred while serializing the result extra data |
---|
208 | * @throws NoSuchElementException |
---|
209 | * result set past already advanced past all records |
---|
210 | * @see #hasExtraRecordData() |
---|
211 | */ |
---|
212 | public void writeExtraRecordData(XMLStreamWriter writer) |
---|
213 | throws XMLStreamException { |
---|
214 | } |
---|
215 | |
---|
216 | } // class SRUSearchResultSet |
---|