mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
fixed search and filter for regular expressions and terms
This commit is contained in:
parent
6ac9b27d7b
commit
02d2fb42b7
3 changed files with 59 additions and 25 deletions
|
@ -23,6 +23,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
#include "retroshare/rsexpr.h"
|
||||||
|
|
||||||
#include "dir_hierarchy.h"
|
#include "dir_hierarchy.h"
|
||||||
#include "filelist_io.h"
|
#include "filelist_io.h"
|
||||||
|
@ -595,21 +596,33 @@ bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list<D
|
||||||
return false;
|
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
|
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)
|
for(std::map<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it)
|
||||||
{
|
if(mNodes[it->second] != NULL && exp->eval(
|
||||||
const std::string &str1 = static_cast<FileEntry*>(mNodes[fit->second])->file_name;
|
DirectoryStorageExprFileEntry(*static_cast<const FileEntry*>(mNodes[it->second]),
|
||||||
|
*static_cast<const DirEntry*>(mNodes[mNodes[it->second]->parent_index])
|
||||||
|
)))
|
||||||
|
results.push_back(it->second);
|
||||||
|
|
||||||
{
|
return 0;
|
||||||
/*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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int InternalFileHierarchyStorage::searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const
|
int InternalFileHierarchyStorage::searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const
|
||||||
|
|
|
@ -806,21 +806,39 @@ 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)
|
int p3FileDatabase::SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& client_peer_id)
|
||||||
|
{
|
||||||
|
std::list<EntryIndex> firesults;
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mFLSMtx) ;
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
|
||||||
std::list<EntryIndex> firesults;
|
|
||||||
mLocalSharedDirs->searchTerms(keywords,firesults) ;
|
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) ;
|
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
|
int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const
|
||||||
|
{
|
||||||
|
std::list<EntryIndex> firesults;
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mFLSMtx) ;
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
|
||||||
std::list<EntryIndex> firesults;
|
|
||||||
mLocalSharedDirs->searchBoolExp(exp,firesults) ;
|
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) ;
|
return filterResults(firesults,results,flags,client_peer_id) ;
|
||||||
}
|
}
|
||||||
bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const
|
||||||
|
@ -854,18 +872,21 @@ int p3FileDatabase::filterResults(const std::list<EntryIndex>& firesults,std::li
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
|
|
||||||
#ifdef P3FILELISTS_DEBUG
|
flags &= RS_FILE_HINTS_PERMISSION_MASK; // remove other flags.
|
||||||
if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0)
|
|
||||||
std::cerr << "(EE) ***** FileIndexMonitor:: Flags ERROR in filterResults!!" << std::endl;
|
|
||||||
#endif
|
|
||||||
/* translate/filter results */
|
/* translate/filter results */
|
||||||
|
|
||||||
for(std::list<EntryIndex>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
|
for(std::list<EntryIndex>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
|
||||||
{
|
{
|
||||||
DirDetails cdetails ;
|
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
|
#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
|
#endif
|
||||||
|
|
||||||
if(!peer_id.isNull())
|
if(!peer_id.isNull())
|
||||||
|
|
|
@ -115,8 +115,8 @@ public:
|
||||||
virtual const std::string& file_name() const =0;
|
virtual const std::string& file_name() const =0;
|
||||||
virtual uint64_t file_size() const =0;
|
virtual uint64_t file_size() const =0;
|
||||||
virtual time_t file_modtime() const =0;
|
virtual time_t file_modtime() const =0;
|
||||||
virtual time_t file_popularity() const =0;
|
virtual uint32_t file_popularity() const =0;
|
||||||
virtual const std::string file_parent_path() const =0;
|
virtual std::string file_parent_path() const =0;
|
||||||
virtual const RsFileHash& file_hash() const =0;
|
virtual const RsFileHash& file_hash() const =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue