Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsSearch.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsSearch.cpp
4  *
5  * Description:
6  *
7  * Created: 03/08/2012 02:35:21 PM
8  *
9  * Author: Benoit Daccache, ben.daccache@gmail.com
10  *
11  */
12 
13 #include "WsSearch.h"
14 
15 WsSearch::WsSearch(FileSystemTreePtr fst, const string& query):
16  m_fst(fst),
17  m_searchImpl(0),
18  m_query(query)
19 {
20 }
21 
23 {
24  delete m_searchImpl;
25 }
26 
28 {
29  /* Load module */
30  if (loadModule() == -1)
31  return -1;
32  /* Load search results */
33  return m_searchImpl->load(m_fst, m_query);
34 }
35 
37 {
38  return m_searchImpl->getSize();
39 }
40 
41 vector<WsResultItem> WsSearch::getResults(const set<string>& groups)
42 {
43  return m_searchImpl->getResults(groups);
44 }
45 
47 {
48  LOG(INFO) << "WsSearch::loadModule() : Loading search module";
49  /* Load libname */
50  string libName = WsGlobalProperties::instance()->get("global", "search_libname", "libWsModMnoGoSearch.so");
51 #if GDDEBUG == 1
52  /* If debug flag, load debug lib instead */
53  boost::replace_first(libName, ".so", "d.so");
54 #endif
55  /* Load module */
56  void* hndl = dlopen(libName.c_str(), RTLD_LAZY);
57  if ( hndl == NULL ) {
58  LOG(ERROR) << "WsSearch::loadModule() : load ERROR " << dlerror();
59  return -1;
60  }
61  LOG(DEBUG) << "WsSearch::loadModule() : Building module";
62  /* Link function pointer to adequate function in module (buildModule function) */
63  pf_wsSearchMod func = (pf_wsSearchMod) dlsym(hndl, "buildModule");
64  LOG(DEBUG) << "WsSearch::loadModule() : Casting module to specified object";
65  m_searchImpl = func();
66  LOG(DEBUG) << "WsSearch::loadModule() : Done loading";
67  return 0;
68 }
virtual vector< WsResultItem > getResults(const std::set< std::string > &groups)=0
return the results found for the query filtered for the user
WsAbstractSearch *(* pf_wsSearchMod)()
Definition: WsSearch.h:78
~WsSearch()
Definition: WsSearch.cpp:22
#define DEBUG
Definition: WsLogger.h:27
virtual int load(FileSystemTreePtr fs, std::string q)=0
load the results (execute the search query)
int loadModule()
loads the search module.
Definition: WsSearch.cpp:46
FileSystemTreePtr m_fst
Definition: WsSearch.h:73
virtual int getSize()=0
return the number of results found
#define LOG
Definition: WsLogger.h:22
#define INFO
Definition: WsLogger.h:32
boost::shared_ptr< WsFileSystemTree > FileSystemTreePtr
int load()
Loads all search results.
Definition: WsSearch.cpp:27
WsAbstractSearch * m_searchImpl
Definition: WsSearch.h:72
string m_query
Definition: WsSearch.h:74
std::string get(const std::string &section, const std::string &id, const std::string &def)
static WsGlobalProperties * instance()
int getSize()
Loads all search results.
Definition: WsSearch.cpp:36
vector< WsResultItem > getResults(const std::set< std::string > &groups)
Get list of documents readable by person member of all groups passed in parameter.
Definition: WsSearch.cpp:41
#define ERROR
Definition: WsLogger.h:42
WsSearch(FileSystemTreePtr fst, const std::string &query)
Constructor for the Search object.
Definition: WsSearch.cpp:15