Package eu.clarin.sru.server
Class SRUSearchResultSet
- java.lang.Object
-
- eu.clarin.sru.server.SRUSearchResultSet
-
public abstract class SRUSearchResultSet extends Object
A result set of a searchRetrieve operation. It it used to iterate over the result set and provides a method to serialize the record in the requested format.A
SRUSearchResultSetobject maintains a cursor pointing to its current record. Initially the cursor is positioned before the first record. Thenextmethod moves the cursor to the next record, and because it returnsfalsewhen there are no more records in theSRUSearchResultSetobject, it can be used in awhileloop to iterate through the result set.This class needs to be implemented for the target search engine.
- See Also:
- SRU Search Retrieve Operation
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSRUSearchResultSet(SRUDiagnosticList diagnostics)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddDiagnostic(String uri)Add a non surrogate diagnostic to the response.protected voidaddDiagnostic(String uri, String details)Add a non surrogate diagnostic to the response.protected voidaddDiagnostic(String uri, String details, String message)Add a non surrogate diagnostic to the response.voidclose()Release this result and free any associated resources.abstract intgetRecordCount()The number of records matched by the query but at most as the number of records requested to be returned (maximumRecords parameter).abstract StringgetRecordIdentifier()An identifier for the current record by which it can unambiguously be retrieved in a subsequent operation.abstract StringgetRecordSchemaIdentifier()The record schema identifier in which the records are returned (recordSchema parameter).SRUResultCountPrecisiongetResultCountPrecision()(SRU 2.0) Indicate the accuracy of the result count reported by total number of records that matched the query.StringgetResultSetId()The result set id of this result. the default implementation returnsnull.intgetResultSetTTL()The result set time to live.SRUDiagnosticgetSurrogateDiagnostic()Get surrogate diagnostic for current record.abstract intgetTotalRecordCount()The number of records matched by the query.booleanhasExtraRecordData()Check, if extra record data should be serialized for the current record.booleanhasExtraResponseData()Check, if extra response data should be serialized for this request.abstract booleannextRecord()Moves the cursor forward one record from its current position.voidwriteExtraRecordData(XMLStreamWriter writer)Serialize extra record data for the current record.voidwriteExtraResponseData(XMLStreamWriter writer)Serialize extra response data for this request.abstract voidwriteRecord(XMLStreamWriter writer)Serialize the current record in the requested format.
-
-
-
Constructor Detail
-
SRUSearchResultSet
protected SRUSearchResultSet(SRUDiagnosticList diagnostics)
Constructor.- Parameters:
diagnostics- an instance of a SRUDiagnosticList- See Also:
SRUDiagnosticList
-
-
Method Detail
-
getTotalRecordCount
public abstract int getTotalRecordCount()
The number of records matched by the query. If the query fails this must be 0. If the search engine cannot determine the total number of matched by a query, it must return -1.- Returns:
- the total number of results or 0 if the query failed or -1 if the search engine cannot determine the total number of results
-
getRecordCount
public abstract int getRecordCount()
The number of records matched by the query but at most as the number of records requested to be returned (maximumRecords parameter). If the query fails this must be 0.- Returns:
- the number of results or 0 if the query failed
-
getResultSetId
public String getResultSetId()
The result set id of this result. the default implementation returnsnull.- Returns:
- the result set id or
nullif not applicable for this result
-
getResultSetTTL
public int getResultSetTTL()
The result set time to live. In SRU 2.0 it will be serialized as<resultSetTTL>element; in SRU 1.2 as<resultSetIdleTime>element.The default implementation returns-1.- Returns:
- the result set time to live or
-1if not applicable for this result
-
getResultCountPrecision
public SRUResultCountPrecision getResultCountPrecision()
(SRU 2.0) Indicate the accuracy of the result count reported by total number of records that matched the query. Default implementation returnsnull.- Returns:
- the result count precision or
nullif not applicable for this result - See Also:
SRUResultCountPrecision
-
getRecordSchemaIdentifier
public abstract String getRecordSchemaIdentifier()
The record schema identifier in which the records are returned (recordSchema parameter).- Returns:
- the record schema identifier
-
nextRecord
public abstract boolean nextRecord() throws SRUExceptionMoves the cursor forward one record from its current position. ASRUSearchResultSetcursor is initially positioned before the first record; the first call to the methodnextmakes the first record the current record; the second call makes the second record the current record, and so on.When a call to the
nextmethod returnsfalse, the cursor is positioned after the last record.- Returns:
trueif the new current record is valid;falseif there are no more records- Throws:
SRUException- if an error occurred while fetching the next record
-
getRecordIdentifier
public abstract String getRecordIdentifier()
An identifier for the current record by which it can unambiguously be retrieved in a subsequent operation.- Returns:
- identifier for the record or
nullof none is available - Throws:
NoSuchElementException- result set is past all records
-
getSurrogateDiagnostic
public SRUDiagnostic getSurrogateDiagnostic()
Get surrogate diagnostic for current record. If this method returns a diagnostic, the writeRecord method will not be called. The default implementation returnsnull.- Returns:
- a surrogate diagnostic or
null
-
writeRecord
public abstract void writeRecord(XMLStreamWriter writer) throws XMLStreamException
Serialize the current record in the requested format.- Parameters:
writer- theXMLStreamExceptioninstance to be used- Throws:
XMLStreamException- an error occurred while serializing the resultNoSuchElementException- result set past all records- See Also:
getRecordSchemaIdentifier()
-
hasExtraRecordData
public boolean hasExtraRecordData()
Check, if extra record data should be serialized for the current record. The default implementation returnsfalse.- Returns:
trueif the record has extra record data- Throws:
NoSuchElementException- result set is already advanced past all records- See Also:
writeExtraResponseData(XMLStreamWriter)
-
writeExtraRecordData
public void writeExtraRecordData(XMLStreamWriter writer) throws XMLStreamException
Serialize extra record data for the current record. A no-op default implementation is provided for convince.- Parameters:
writer- theXMLStreamExceptioninstance to be used- Throws:
XMLStreamException- an error occurred while serializing the result extra dataNoSuchElementException- result set past already advanced past all records- See Also:
hasExtraRecordData()
-
addDiagnostic
protected final void addDiagnostic(String uri, String details, String message)
Add a non surrogate diagnostic to the response.- Parameters:
uri- the diagnostic's identifying URIdetails- supplementary information available, often in a format specified by the diagnostic ornullmessage- human readable message to display to the end user ornull
-
addDiagnostic
protected final void addDiagnostic(String uri, String details)
Add a non surrogate diagnostic to the response.- Parameters:
uri- the diagnostic's identifying URIdetails- supplementary information available, often in a format specified by the diagnostic ornull
-
addDiagnostic
protected final void addDiagnostic(String uri)
Add a non surrogate diagnostic to the response.- Parameters:
uri- the diagnostic's identifying URI
-
hasExtraResponseData
public boolean hasExtraResponseData()
Check, if extra response data should be serialized for this request. Default implementation is provided for convince and always returnsfalse.- Returns:
trueif extra response data should be serialized.- See Also:
writeExtraResponseData(XMLStreamWriter)
-
writeExtraResponseData
public void writeExtraResponseData(XMLStreamWriter writer) throws XMLStreamException
Serialize extra response data for this request.- Parameters:
writer- theXMLStreamExceptioninstance to be used- Throws:
XMLStreamException- an error occurred while serializing the result- See Also:
hasExtraResponseData()
-
close
public void close()
Release this result and free any associated resources.This method must not throw any exceptions
Calling the method
closeon a result object that is already closed is a no-op.
-
-