fixed search and filter for regular expressions and terms

This commit is contained in:
mr-alice 2016-09-13 13:53:51 +02:00
parent 6ac9b27d7b
commit 02d2fb42b7
3 changed files with 59 additions and 25 deletions

View File

@ -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<D
return false;
}
class DirectoryStorageExprFileEntry: public RsRegularExpression::ExpFileEntry
{
public:
DirectoryStorageExprFileEntry(const InternalFileHierarchyStorage::FileEntry& fe,const InternalFileHierarchyStorage::DirEntry& parent) : mFe(fe),mDe(parent) {}
inline virtual const std::string& file_name() const { return mFe.file_name ; }
inline virtual uint64_t file_size() const { return mFe.file_size ; }
inline virtual const RsFileHash& file_hash() const { return mFe.file_hash ; }
inline virtual time_t file_modtime() const { return mFe.file_modtime ; }
inline virtual std::string file_parent_path()const { return mDe.dir_parent_path + "/" + mDe.dir_name ; }
inline virtual uint32_t file_popularity() const { NOT_IMPLEMENTED() ; return 0; }
private:
const InternalFileHierarchyStorage::FileEntry& mFe ;
const InternalFileHierarchyStorage::DirEntry& mDe ;
};
int InternalFileHierarchyStorage::searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const
{
#ifdef TODO
for(std::map<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it)
{
const std::string &str1 = static_cast<FileEntry*>(mNodes[fit->second])->file_name;
if(mNodes[it->second] != NULL && exp->eval(
DirectoryStorageExprFileEntry(*static_cast<const FileEntry*>(mNodes[it->second]),
*static_cast<const DirEntry*>(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<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const

View File

@ -807,19 +807,37 @@ bool p3FileDatabase::findLocalFile(const RsFileHash& hash,FileSearchFlags flags,
int p3FileDatabase::SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& client_peer_id)
{
RS_STACK_MUTEX(mFLSMtx) ;
std::list<EntryIndex> firesults;
mLocalSharedDirs->searchTerms(keywords,firesults) ;
{
RS_STACK_MUTEX(mFLSMtx) ;
mLocalSharedDirs->searchTerms(keywords,firesults) ;
for(std::list<EntryIndex>::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<DirDetails>& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const
{
RS_STACK_MUTEX(mFLSMtx) ;
std::list<EntryIndex> firesults;
mLocalSharedDirs->searchBoolExp(exp,firesults) ;
{
RS_STACK_MUTEX(mFLSMtx) ;
mLocalSharedDirs->searchBoolExp(exp,firesults) ;
for(std::list<EntryIndex>::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<EntryIndex>& 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<EntryIndex>::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())

View File

@ -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;
};