/*
 * BEGIN FLOCK GPL
 *
 * Copyright Flock Inc. 2005-2009
 * http://flock.com
 *
 * This file may be used under the terms of the
 * GNU General Public License Version 2 or later (the "GPL"),
 * http://www.gnu.org/licenses/gpl.html
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * END FLOCK GPL
 */

#ifndef __flockLuceneImpl_h__
#define __flockLuceneImpl_h__

#include "nsCOMPtr.h"

#include "nsISimpleEnumerator.h"

#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"

#include "flockILucene.h"

#ifndef _MSC_VER
#undef _DEBUG // hack until CLucene stops polluting the preprocessor namespace
#endif

#include "CLucene.h"
#include "CLucene/util/Reader.h"


enum {
  LOOKUP_FIELD_URI,
  LOOKUP_FIELD_URL,
  LOOKUP_FIELD_TITLE,
  LOOKUP_FIELD_TAGS,
  LOOKUP_FIELD_DESCRIPTION,
  LOOKUP_FIELD_TEXT,
  LOOKUP_FIELD_TYPE,
  NUM_CONVERSIONS
};


class flockLuceneImpl : public flockILucene {
public:
  flockLuceneImpl();
  virtual ~flockLuceneImpl();

  NS_DECL_ISUPPORTS
  NS_DECL_FLOCKILUCENE

protected:
  PRBool mShuttingDown;

  friend class flockLucene;

private:
  nsresult ReturnResults(lucene::search::Hits *aHits,
                         PRInt32 aMaxResults,
                         PRUint32 *aNumResults,
                         nsISimpleEnumerator **aResults);

  lucene::analysis::PerFieldAnalyzerWrapper *mAnalyzer; 

  lucene::store::Directory *mDirectory;
  lucene::index::IndexReader *mReader;

  TCHAR *mConversions[NUM_CONVERSIONS];
  nsresult CreateConversions(void);
  
  PRUint16 mAddDocumentCount;

  nsresult EnsureReader(void);

#ifndef XP_WIN
  nsCOMPtr <nsIUnicodeEncoder> mEncoder;
  nsCOMPtr <nsIUnicodeDecoder> mDecoder;
#endif
};

#endif
