/***************************************************************************

    supportware
    Copyright (C) 2001-2007 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#ifndef DDWEBRELATEDMANAGER_H
#define DDWEBRELATEDMANAGER_H

#include <ddstringrow.h>
#include <dditemset.h>
#include <ddthread.h>
#include <deque>
#include <ddthreadmutex.h>
#include <ddconfig.h>
#include <ddwebpage.h>
#include <dddataconnection.h>
#include <ddwebview.h>
#include <fstream>
#include <ddstringset.h>



///
/**
*/

class ddwebrelateddata : public ddbaseobject
{

public: 
	
	ddstring id;
	ddstring msgsubject;
	ddstring idgrp;
	
	ddwebrelateddata()
	{
	}
	
	ddwebrelateddata( const ddstring& aid,	const ddstring& amsgsubject, const ddstring& aidgrp )
	: id( aid ),	msgsubject( amsgsubject ), idgrp( aidgrp )
	{
	}
	
	virtual ~ddwebrelateddata()
	{
	}
	
};



/// ddwebrelatedmanager
/**
*/

typedef deque<ddwebrelateddata> ddwebrelatedqueue;



class ddwebrelatedmanager : public ddthreadrunnable 
{

public: 
	
	ddwebrelatedmanager();
	virtual ~ddwebrelatedmanager();
	
	void   init( ddconfig& config, const ddstring& stopwords );
	size_t enqueue_related_query( const ddstring& id, const ddstring& msgsubject, const ddstring& idgrp );
	
	void   run();
	
	void	 create_related_links( const ddstring& id, const ddstring& msgsubject, const ddstring& idgrp );

protected:
	
	void 	 init_searchkey_boolean( const ddstring& key, ddstring& query, bool usecaps=false );
	void 	 init_searchkey_fuzzy( const ddstring& key, ddstring& query );
		
	ddwebrelatedqueue 		_queue;
	ddthreadmutex			 		_mutex;	
	ddwebview 						_table;
	ddstringset 					_stopwords;
	ddstring 							_evilchars;
	
};


#endif
