#include "Xpclucene.h" #include "nsCOMPtr.h" #include "nsString.h" #include "nsLuceneUtils.h" #include "nsIComponentManager.h" #include "nsCRT.h" #include "rdfIDataSource.h" #include "nsIServiceManager.h" #include "nsXPIDLString.h" #include "nsPrintfCString.h" #include "nsLuceneStringConverter.h" #include "nsLuceneHits.h" #include "nsLuceneDocument.h" #include "nsLuceneFactory.h" #include "CLucene/CLConfig.h" #include "CLucene.h" NS_IMPL_ISUPPORTS1(nsLuceneHits, nsILuceneHits) nsLuceneHits::nsLuceneHits(lucene::search::Hits *pHits, nsILuceneIndexSearcher *pSearcher) { mHits = pHits; /* * The lucene hits class needs the searcher to stick around, so we take an * owning reference here */ mSearcher = pSearcher; } nsLuceneHits::~nsLuceneHits() { delete mHits; } /* nsILuceneDocument doc (in short n); */ NS_IMETHODIMP nsLuceneHits::Doc(PRInt16 n, nsILuceneDocument **_retval) { LUCENETRYCATCH_START lucene::document::Document& document = mHits->doc(n); if(&document != NULL) { /* * The document object is owned by the hits object, so tell the wrapper not * to delete it */ nsCOMPtr luceneDocument = new nsLuceneDocument(&document, false); NS_ENSURE_TRUE(luceneDocument, NS_ERROR_OUT_OF_MEMORY); *_retval = luceneDocument; NS_ADDREF(*_retval); } else { *_retval = NULL; } return NS_OK; LUCENETRYCATCH_END } /* float score (in short n); */ NS_IMETHODIMP nsLuceneHits::Score(PRInt16 n, double *_retval) { LUCENETRYCATCH_START /* * Casting from a long double to a double. Should be safe since score * is always between 0 and 1 */ *_retval = (double) mHits->score(n); return NS_OK; LUCENETRYCATCH_END } /* short length (); */ NS_IMETHODIMP nsLuceneHits::Length(PRInt16 *_retval) { LUCENETRYCATCH_START *_retval = mHits->length(); return NS_OK; LUCENETRYCATCH_END } /* short id (in short n); */ NS_IMETHODIMP nsLuceneHits::Id(PRInt16 n, PRInt16 *_retval) { LUCENETRYCATCH_START *_retval = mHits->id(n); return NS_OK; LUCENETRYCATCH_END }