org.weborganic.bastille.flint.helpers
Class MultiSearchResults

java.lang.Object
  extended by org.weborganic.bastille.flint.helpers.MultiSearchResults
All Implemented Interfaces:
XMLWritable

public final class MultiSearchResults
extends Object
implements XMLWritable

A container for search results of a query ran on multiple indexes.

Use this class to serialise Lucene Search results as XML.

Note: the current implementation is a "throw away" object, once the toXML method has been called, this instance is useless.


Constructor Summary
MultiSearchResults(SearchQuery query, ScoreDoc[] hits, int totalHits, SearchPaging paging, MultiSearcher searcher, Map<IndexMaster,IndexSearcher> indexes)
          Creates a new SearchResults.
MultiSearchResults(SearchQuery query, TopFieldDocs fielddocs, SearchPaging paging, MultiSearcher searcher, Map<IndexMaster,IndexSearcher> indexes)
          Creates a new SearchResults.
 
Method Summary
 Document getDocument(int id)
          Load a document from the index.
 SearchPaging getPaging()
           
 ScoreDoc[] getScoreDoc()
          Return the results.
 int getTotalNbOfResults()
          Returns the total number of results.
 boolean isEmpty()
          Indicates whether the search results are empty.
 void setTimeZone(int timezoneInMinutes)
          Sets the time zone to use when formatting the results as XML.
 void terminate()
          Release all references to all the searchers used.
 void toXML(XMLWriter xml)
          Serialises the search results as XML.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiSearchResults

public MultiSearchResults(SearchQuery query,
                          TopFieldDocs fielddocs,
                          SearchPaging paging,
                          MultiSearcher searcher,
                          Map<IndexMaster,IndexSearcher> indexes)
                   throws IOException,
                          IndexException
Creates a new SearchResults.

Parameters:
fielddocs - The actual search results from Lucene in TopFieldDocs.
paging - The paging configuration.
io - The IndexIO object, used to release the searcher when terminated
searcher - The Lucene searcher.
Throws:
IndexException - if the documents could not be retrieved from the Index
IOException

MultiSearchResults

public MultiSearchResults(SearchQuery query,
                          ScoreDoc[] hits,
                          int totalHits,
                          SearchPaging paging,
                          MultiSearcher searcher,
                          Map<IndexMaster,IndexSearcher> indexes)
                   throws IndexException
Creates a new SearchResults.

Parameters:
hits - The actual search results from Lucene in ScoreDoc.
paging - The paging configuration.
io - The IndexIO object, used to release the searcher when terminated
searcher - The Lucene searcher.
Throws:
IndexException - if the documents could not be retrieved from the Index
Method Detail

getPaging

public SearchPaging getPaging()
Returns:
the paging used

getTotalNbOfResults

public int getTotalNbOfResults()
Returns the total number of results.

Returns:
the total number of results.

isEmpty

public boolean isEmpty()
Indicates whether the search results are empty.

Returns:
true if the results are empty; false if there is more than one hit.

setTimeZone

public void setTimeZone(int timezoneInMinutes)
Sets the time zone to use when formatting the results as XML.

Parameters:
timezoneInMinutes - the timezone offset in minutes (difference with GMT)

toXML

public void toXML(XMLWriter xml)
           throws IOException
Serialises the search results as XML.

Specified by:
toXML in interface XMLWritable
Parameters:
xml - The XML writer.
Throws:
IOException - Should there be any I/O exception while writing the XML.

getScoreDoc

public ScoreDoc[] getScoreDoc()
                       throws IndexException
Return the results.

Returns:
the search results
Throws:
IndexException

getDocument

public Document getDocument(int id)
                     throws IndexException
Load a document from the index.

Parameters:
id - the id of the document
Returns:
the document object loaded from the index, could be null
Throws:
IndexException - if the index is invalid

terminate

public void terminate()
               throws IndexException
Release all references to all the searchers used.

Throws:
IndexException