From 02d2fb42b7b6093084354afc5cbbe10fa59780a8 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 13 Sep 2016 13:53:51 +0200 Subject: [PATCH] fixed search and filter for regular expressions and terms --- .../src/file_sharing/dir_hierarchy.cc | 35 ++++++++++----- libretroshare/src/file_sharing/p3filelists.cc | 45 ++++++++++++++----- libretroshare/src/retroshare/rsexpr.h | 4 +- 3 files changed, 59 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index 1735beb79..8b03060d1 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -23,6 +23,7 @@ * */ #include "util/rsdir.h" +#include "retroshare/rsexpr.h" #include "dir_hierarchy.h" #include "filelist_io.h" @@ -595,21 +596,33 @@ bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list &results) const { -#ifdef TODO for(std::map::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it) - { - const std::string &str1 = static_cast(mNodes[fit->second])->file_name; + if(mNodes[it->second] != NULL && exp->eval( + DirectoryStorageExprFileEntry(*static_cast(mNodes[it->second]), + *static_cast(mNodes[mNodes[it->second]->parent_index]) + ))) + results.push_back(it->second); - { - /*Evaluate the boolean expression and add it to the results if its true*/ - bool ret = exp->eval(fit->second); - if (ret == true){ - results.push_back(fit->second); - } - } -#endif + return 0; } int InternalFileHierarchyStorage::searchTerms(const std::list& terms, std::list &results) const diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index ea77de3a6..3eaf21c87 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -807,19 +807,37 @@ bool p3FileDatabase::findLocalFile(const RsFileHash& hash,FileSearchFlags flags, int p3FileDatabase::SearchKeywords(const std::list& keywords, std::list& results,FileSearchFlags flags,const RsPeerId& client_peer_id) { - RS_STACK_MUTEX(mFLSMtx) ; - std::list firesults; - mLocalSharedDirs->searchTerms(keywords,firesults) ; + { + RS_STACK_MUTEX(mFLSMtx) ; + + mLocalSharedDirs->searchTerms(keywords,firesults) ; + + for(std::list::iterator it(firesults.begin());it!=firesults.end();++it) + { + void *p=NULL; + convertEntryIndexToPointer(*it,0,p); + *it = (intptr_t)p ; + } + } return filterResults(firesults,results,flags,client_peer_id) ; } int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const { - RS_STACK_MUTEX(mFLSMtx) ; - std::list firesults; - mLocalSharedDirs->searchBoolExp(exp,firesults) ; + { + RS_STACK_MUTEX(mFLSMtx) ; + + mLocalSharedDirs->searchBoolExp(exp,firesults) ; + + for(std::list::iterator it(firesults.begin());it!=firesults.end();++it) + { + void *p=NULL; + convertEntryIndexToPointer(*it,0,p); + *it = (intptr_t)p ; + } + } return filterResults(firesults,results,flags,client_peer_id) ; } @@ -854,18 +872,21 @@ int p3FileDatabase::filterResults(const std::list& firesults,std::li { results.clear(); -#ifdef P3FILELISTS_DEBUG - if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0) - std::cerr << "(EE) ***** FileIndexMonitor:: Flags ERROR in filterResults!!" << std::endl; -#endif + flags &= RS_FILE_HINTS_PERMISSION_MASK; // remove other flags. + /* translate/filter results */ for(std::list::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit) { DirDetails cdetails ; - RequestDirDetails ((void*)(intptr_t)*rit,cdetails,FileSearchFlags(0u)); + + if(!RequestDirDetails ((void*)(intptr_t)*rit,cdetails,RS_FILE_HINTS_LOCAL)) + { + std::cerr << "(EE) Cannot get dir details for entry " << (void*)(intptr_t)*rit << std::endl; + continue ; + } #ifdef P3FILELISTS_DEBUG - std::cerr << "Filtering candidate " << (*rit) << ", flags=" << cdetails.flags << ", peer=" << peer_id ; + std::cerr << "Filtering candidate " << (void*)(intptr_t)(*rit) << ", flags=" << cdetails.flags << ", peer=" << peer_id ; #endif if(!peer_id.isNull()) diff --git a/libretroshare/src/retroshare/rsexpr.h b/libretroshare/src/retroshare/rsexpr.h index fc339e87c..4cf9e7983 100644 --- a/libretroshare/src/retroshare/rsexpr.h +++ b/libretroshare/src/retroshare/rsexpr.h @@ -115,8 +115,8 @@ public: virtual const std::string& file_name() const =0; virtual uint64_t file_size() const =0; virtual time_t file_modtime() const =0; - virtual time_t file_popularity() const =0; - virtual const std::string file_parent_path() const =0; + virtual uint32_t file_popularity() const =0; + virtual std::string file_parent_path() const =0; virtual const RsFileHash& file_hash() const =0; };