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
SRUSearchResultSet
object maintains a cursor pointing to its current record. Initially the cursor is positioned before the first record. Thenext
method moves the cursor to the next record, and because it returnsfalse
when there are no more records in theSRUSearchResultSet
object, it can be used in awhile
loop 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 protected
SRUSearchResultSet(SRUDiagnosticList diagnostics)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addDiagnostic(String uri)
Add a non surrogate diagnostic to the response.protected void
addDiagnostic(String uri, String details)
Add a non surrogate diagnostic to the response.protected void
addDiagnostic(String uri, String details, String message)
Add a non surrogate diagnostic to the response.void
close()
Release this result and free any associated resources.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).abstract String
getRecordIdentifier()
An identifier for the current record by which it can unambiguously be retrieved in a subsequent operation.abstract String
getRecordSchemaIdentifier()
The record schema identifier in which the records are returned (recordSchema parameter).SRUResultCountPrecision
getResultCountPrecision()
(SRU 2.0) Indicate the accuracy of the result count reported by total number of records that matched the query.String
getResultSetId()
The result set id of this result.int
getResultSetTTL()
The result set time to live.SRUDiagnostic
getSurrogateDiagnostic()
Get surrogate diagnostic for current record.abstract int
getTotalRecordCount()
The number of records matched by the query.boolean
hasExtraRecordData()
Check, if extra record data should be serialized for the current record.boolean
hasExtraResponseData()
Check, if extra response data should be serialized for this request.abstract boolean
nextRecord()
Moves the cursor forward one record from its current position.void
writeExtraRecordData(XMLStreamWriter writer)
Serialize extra record data for the current record.void
writeExtraResponseData(XMLStreamWriter writer)
Serialize extra response data for this request.abstract void
writeRecord(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
null
if 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
-1
if 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
null
if 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 SRUException
Moves the cursor forward one record from its current position. ASRUSearchResultSet
cursor is initially positioned before the first record; the first call to the methodnext
makes the first record the current record; the second call makes the second record the current record, and so on.When a call to the
next
method returnsfalse
, the cursor is positioned after the last record.- Returns:
true
if the new current record is valid;false
if 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
null
of 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
- theXMLStreamException
instance 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:
true
if 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
- theXMLStreamException
instance 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 ornull
message
- 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:
true
if 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
- theXMLStreamException
instance 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
close
on a result object that is already closed is a no-op.
-
-