gui: Perform content search and path search by default
Search for content and paths. Merge lone words for content search. This behaviour is much more natural than typing "c:()".
This commit is contained in:
@ -157,15 +157,15 @@ void LooqsQuery::addToken(Token t)
|
||||
* thus, "Downloads zip" becomes essentailly "path.contains:(Downloads) AND path.contains:(zip)"
|
||||
*
|
||||
* TODO: It's a bit ugly still*/
|
||||
LooqsQuery LooqsQuery::build(QString expression)
|
||||
LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, bool mergeLoneWords)
|
||||
{
|
||||
if(!checkParanthesis(expression))
|
||||
{
|
||||
throw LooqsGeneralException("Invalid paranthesis");
|
||||
}
|
||||
|
||||
QStringList loneWords;
|
||||
LooqsQuery result;
|
||||
// TODO: merge lonewords
|
||||
QRegularExpression rx("((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([\\w,])+)|(?<boolean>AND|OR)"
|
||||
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>\\w+))");
|
||||
QRegularExpressionMatchIterator i = rx.globalMatch(expression);
|
||||
@ -233,7 +233,14 @@ LooqsQuery LooqsQuery::build(QString expression)
|
||||
|
||||
if(loneword != "")
|
||||
{
|
||||
result.addToken(Token(FILTER_PATH_CONTAINS, loneword));
|
||||
if(mergeLoneWords)
|
||||
{
|
||||
loneWords.append(loneword);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.addToken(Token(loneWordsTokenType, loneword));
|
||||
}
|
||||
}
|
||||
|
||||
if(filtername != "")
|
||||
@ -292,6 +299,11 @@ LooqsQuery LooqsQuery::build(QString expression)
|
||||
}
|
||||
}
|
||||
|
||||
if(mergeLoneWords)
|
||||
{
|
||||
result.addToken(Token(loneWordsTokenType, loneWords.join(' ')));
|
||||
}
|
||||
|
||||
bool contentsearch = (result.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
|
||||
bool sortsForContent = std::any_of(result.sortConditions.begin(), result.sortConditions.end(),
|
||||
[](SortCondition c) { return c.field == CONTENT_TEXT; });
|
||||
|
@ -54,7 +54,7 @@ class LooqsQuery
|
||||
}
|
||||
void addSortCondition(SortCondition sc);
|
||||
static bool checkParanthesis(QString query);
|
||||
static LooqsQuery build(QString query);
|
||||
static LooqsQuery build(QString query, TokenType loneWordsTokenType, bool mergeLoneWords);
|
||||
};
|
||||
|
||||
#endif // LOOQSQUERY_H
|
||||
|
Reference in New Issue
Block a user