mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 07:25:36 -04:00
added regexp search to turtle router
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1564 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
bb7e3684f0
commit
3c09b4f2d2
19 changed files with 846 additions and 220 deletions
|
@ -65,6 +65,22 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
|
|||
std::list<FileEntry *> firesults;
|
||||
|
||||
fi.searchTerms(keywords, firesults);
|
||||
|
||||
return filterResults(firesults,results,flags) ;
|
||||
}
|
||||
|
||||
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& results,uint32_t flags) const
|
||||
{
|
||||
results.clear();
|
||||
std::list<FileEntry *> firesults;
|
||||
|
||||
fi.searchBoolExp(exp, firesults);
|
||||
|
||||
return filterResults(firesults,results,flags) ;
|
||||
}
|
||||
|
||||
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const
|
||||
{
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
/* translate/filter results */
|
||||
|
|
|
@ -76,6 +76,9 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
|||
/* external interface for filetransfer */
|
||||
bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const;
|
||||
int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) ;
|
||||
int SearchBoolExp(Expression *exp, std::list<FileDetail> &results,uint32_t flags) const ;
|
||||
int filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const ;
|
||||
|
||||
|
||||
/* external interface for local access to files */
|
||||
bool convertSharedFilePath(std::string path, std::string &fullpath);
|
||||
|
|
|
@ -29,12 +29,20 @@
|
|||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
|
||||
/******************************************************************************************
|
||||
eval functions of relational expressions.
|
||||
|
||||
******************************************************************************************/
|
||||
|
||||
template<>
|
||||
void RelExpression<int>::linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._ints.push_back(Op) ;
|
||||
e._ints.push_back(LowerValue) ;
|
||||
e._ints.push_back(HigherValue) ;
|
||||
}
|
||||
|
||||
|
||||
bool DateExpression::eval(FileEntry *file)
|
||||
{
|
||||
return evalRel(file->modtime);
|
||||
|
@ -148,3 +156,125 @@ bool StringExpression :: evalStr ( std::string &str ){
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* linearization code
|
||||
*************************************************************************/
|
||||
|
||||
void CompoundExpression::linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_COMP) ;
|
||||
e._ints.push_back(Op) ;
|
||||
|
||||
Lexp->linearize(e) ;
|
||||
Rexp->linearize(e) ;
|
||||
}
|
||||
|
||||
void StringExpression::linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._ints.push_back(Op) ;
|
||||
e._ints.push_back(IgnoreCase) ;
|
||||
e._ints.push_back(terms.size()) ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(terms.begin());it!=terms.end();++it)
|
||||
e._strings.push_back(*it) ;
|
||||
}
|
||||
|
||||
Expression *LinearizedExpression::toExpr(const LinearizedExpression& e)
|
||||
{
|
||||
int i=0,j=0,k=0 ;
|
||||
return toExpr(e,i,j,k) ;
|
||||
}
|
||||
|
||||
void LinearizedExpression::readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list<std::string>& strings,bool& b,StringOperator& op)
|
||||
{
|
||||
op = static_cast<StringOperator>(e._ints[n_ints++]) ;
|
||||
b = e._ints[n_ints++] ;
|
||||
int n = e._ints[n_ints++] ;
|
||||
|
||||
strings.clear() ;
|
||||
for(int i=0;i<n;++i)
|
||||
strings.push_back(e._strings[n_strings++]) ;
|
||||
}
|
||||
|
||||
Expression *LinearizedExpression::toExpr(const LinearizedExpression& e,int& n_tok,int& n_ints,int& n_strings)
|
||||
{
|
||||
LinearizedExpression::token tok = static_cast<LinearizedExpression::token>(e._tokens[n_tok++]) ;
|
||||
|
||||
switch(tok)
|
||||
{
|
||||
case EXPR_COMP: {
|
||||
LogicalOperator op = static_cast<LogicalOperator>(e._ints[n_ints++]) ;
|
||||
|
||||
Expression *e1 = toExpr(e,n_tok,n_ints,n_strings) ;
|
||||
Expression *e2 = toExpr(e,n_tok,n_ints,n_strings) ;
|
||||
|
||||
return new CompoundExpression(op,e1,e2) ;
|
||||
}
|
||||
|
||||
case EXPR_POP: {
|
||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||
int lv = e._ints[n_ints++] ;
|
||||
int hv = e._ints[n_ints++] ;
|
||||
|
||||
return new PopExpression(op,lv,hv) ;
|
||||
}
|
||||
case EXPR_SIZE: {
|
||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||
int lv = e._ints[n_ints++] ;
|
||||
int hv = e._ints[n_ints++] ;
|
||||
|
||||
return new SizeExpression(op,lv,hv) ;
|
||||
}
|
||||
case EXPR_DATE: {
|
||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||
int lv = e._ints[n_ints++] ;
|
||||
int hv = e._ints[n_ints++] ;
|
||||
|
||||
return new DateExpression(op,lv,hv) ;
|
||||
}
|
||||
case EXPR_HASH: {
|
||||
std::list<std::string> strings ;
|
||||
StringOperator op ;
|
||||
bool b ;
|
||||
|
||||
readStringExpr(e,n_ints,n_strings,strings,b,op) ;
|
||||
return new HashExpression(op,strings) ;
|
||||
}
|
||||
case EXPR_EXT:
|
||||
{
|
||||
std::list<std::string> strings ;
|
||||
StringOperator op ;
|
||||
bool b ;
|
||||
|
||||
readStringExpr(e,n_ints,n_strings,strings,b,op) ;
|
||||
|
||||
return new ExtExpression(op,strings,b) ;
|
||||
}
|
||||
case EXPR_PATH:
|
||||
{
|
||||
std::list<std::string> strings ;
|
||||
StringOperator op ;
|
||||
bool b ;
|
||||
|
||||
readStringExpr(e,n_ints,n_strings,strings,b,op) ;
|
||||
|
||||
return new ExtExpression(op,strings,b) ;
|
||||
}
|
||||
case EXPR_NAME:
|
||||
{
|
||||
std::list<std::string> strings ;
|
||||
StringOperator op ;
|
||||
bool b ;
|
||||
|
||||
readStringExpr(e,n_ints,n_strings,strings,b,op) ;
|
||||
|
||||
return new NameExpression(op,strings,b) ;
|
||||
}
|
||||
default:
|
||||
std::cerr << "No expression match the current value " << tok << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue