Search Class Reference

#include <search.h>

List of all members.


Detailed Description

Search class represents one search sent to one or more modules for processing, emitting events when new results are added, which the original request creator can then handle.

The basic usage of this object evolves around constructing the object on heap, but within boost::shared_ptr, then customizing the search by adding terms and setting other limits, and then passing the pointer to Search::run() static function, which then sends the object to all search handlers.

Modules wishing to support searching may register their search handler method using addHandler() member function (Note: EventTable class also defines a function with same name, however that one is accessible through getEventTable() member function, as defined by Event Handling API). When new search is performed, all handler functions are notified about the search, and can thus perform module-dependant searching procedure, adding results and posting events.

Module developers: When you are adding many results at once to a Search object, do not post a new event after each addition. Instead, post event after all results that are available to that moment have been added to this object. This is needed to save event's processing overhead, as well as processing overhead at target search client.

Definition at line 108 of file search.h.


Public Member Functions

 Search ()
 Construct empty search.
 Search (const std::string &terms)
 Construct a new search object.
void run ()
 Execute the search.
void addResult (SearchResultPtr result)
 Add a new search.
void addResultHandler (SearchHandler handler)
 Set up a results handler, which shall be notified whenever someone adds new results to this search.
void notifyResults ()
 Notify all results handlers that there are new results added to this search query.
Accessors for various internal structures
uint32_t getTermCount () const
std::string getTerm (uint32_t num) const
uint32_t getResultCount () const
uint64_t getMinSize () const
uint64_t getMaxSize () const
FileType getType () const
SearchResultPtr getResult (uint32_t num) const
Setters
void addTerm (const std::string &term)
void setMinSize (uint64_t size)
void setMaxSize (uint64_t size)
void setType (FileType type)

Static Public Member Functions

static void addQueryHandler (SearchHandler handler)
 Add a search query handler, which shall be called whenever someone runs a new search.
static void addLinkHandler (LinkHandler handler)
 Add a handler for links to be downloaded.
static void downloadLink (const std::string &link)
 Start a direct download from link.

Private Attributes

std::vector< SearchResultPtrm_results
 Vector which will be filled by search handlers using addResult() method.
std::vector< std::string > m_terms
 Terms to search for.
uint64_t m_minSize
 Minimum file size.
uint64_t m_maxSize
 Maximum file size.
FileType m_type
 File type.
boost::signal< void(SearchPtr)> m_sigResult
 This signal is fired when new results are added to an existing search.

Static Private Attributes

static boost::signal< void(SearchPtr)> s_sigQuery
 This signal is fired whenever a new search query is started.
static std::vector< LinkHandlers_linkHandlers
 Handlers for text-based link downloadings.

Constructor & Destructor Documentation

Search::Search  ) 
 

Construct empty search.

The object should later be customized by by adding terms and limitations to the search, before run()'ing it.

Definition at line 35 of file search.cpp.

References FT_UNKNOWN.

Search::Search const std::string &  terms  ) 
 

Construct a new search object.

This should be called by client code which wishes to perform the search.

Parameters:
terms Search terms, separated by spaces

Definition at line 39 of file search.cpp.

References FT_UNKNOWN, and m_terms.


Member Function Documentation

void Search::addLinkHandler LinkHandler  handler  )  [static]
 

Add a handler for links to be downloaded.

A link is defined as any string. It may be a ed2k://, http://, ftp:// links, but it may also be a full path to a local file for example - it's up to the modules to decide what they can (or cannot) accept as "download starter" string.

Definition at line 63 of file search.cpp.

References s_linkHandlers.

void Search::addQueryHandler SearchHandler  handler  )  [static]
 

Add a search query handler, which shall be called whenever someone runs a new search.

It is recommended that the object is set up using boost::connection::trackable to automate the removal process.

Definition at line 47 of file search.cpp.

References s_sigQuery.

void Search::addResult SearchResultPtr  result  ) 
 

Add a new search.

This is used by search handlers to append new search results to the object.

Parameters:
result Search result to be added.

Definition at line 53 of file search.cpp.

References m_results.

void Search::addResultHandler SearchHandler  handler  ) 
 

Set up a results handler, which shall be notified whenever someone adds new results to this search.

Note that the actual notification is done on demand by the results adder via notifyResults() method, not whenever a new result is added to the query. This is done to avoid excessive function calls when adding many results at same time.

Definition at line 56 of file search.cpp.

References m_sigResult.

void Search::addTerm const std::string &  term  )  [inline]
 

Definition at line 193 of file search.h.

void Search::downloadLink const std::string &  link  )  [static]
 

Start a direct download from link.

The passed here is sent to all link handlers. The handler handling the download will return true, others return false.

Definition at line 66 of file search.cpp.

References s_linkHandlers.

uint64_t Search::getMaxSize  )  const [inline]
 

Definition at line 184 of file search.h.

uint64_t Search::getMinSize  )  const [inline]
 

Definition at line 183 of file search.h.

SearchResultPtr Search::getResult uint32_t  num  )  const [inline]
 

Definition at line 186 of file search.h.

uint32_t Search::getResultCount  )  const [inline]
 

Definition at line 182 of file search.h.

std::string Search::getTerm uint32_t  num  )  const [inline]
 

Definition at line 181 of file search.h.

uint32_t Search::getTermCount  )  const [inline]
 

Definition at line 180 of file search.h.

FileType Search::getType  )  const [inline]
 

Definition at line 185 of file search.h.

void Search::notifyResults  ) 
 

Notify all results handlers that there are new results added to this search query.

Definition at line 59 of file search.cpp.

References m_sigResult.

void Search::run  ) 
 

Execute the search.

Call this method after setting up event handlers for results.

Parameters:
search Search to be run.

Definition at line 50 of file search.cpp.

References s_sigQuery.

void Search::setMaxSize uint64_t  size  )  [inline]
 

Definition at line 195 of file search.h.

void Search::setMinSize uint64_t  size  )  [inline]
 

Definition at line 194 of file search.h.

void Search::setType FileType  type  )  [inline]
 

Definition at line 196 of file search.h.


Member Data Documentation

uint64_t Search::m_maxSize [private]
 

Maximum file size.

Definition at line 207 of file search.h.

uint64_t Search::m_minSize [private]
 

Minimum file size.

Definition at line 206 of file search.h.

std::vector<SearchResultPtr> Search::m_results [private]
 

Vector which will be filled by search handlers using addResult() method.

Definition at line 204 of file search.h.

Referenced by addResult().

boost::signal<void (SearchPtr)> Search::m_sigResult [private]
 

This signal is fired when new results are added to an existing search.

This is fired by Search object in addResult method.

Definition at line 224 of file search.h.

Referenced by addResultHandler(), and notifyResults().

std::vector<std::string> Search::m_terms [private]
 

Terms to search for.

Definition at line 205 of file search.h.

Referenced by Search().

FileType Search::m_type [private]
 

File type.

Definition at line 208 of file search.h.

std::vector< LinkHandler > Search::s_linkHandlers [static, private]
 

Handlers for text-based link downloadings.

Definition at line 33 of file search.cpp.

Referenced by addLinkHandler(), and downloadLink().

boost::signal< void(SearchPtr)> Search::s_sigQuery [static, private]
 

This signal is fired whenever a new search query is started.

Modules must connect their handlers to this signal to receive search query notifications.

Definition at line 32 of file search.cpp.

Referenced by addQueryHandler(), and run().


The documentation for this class was generated from the following files: