Compare commits

..

No commits in common. "52b296ff01b78aa79fb426f40e61270adabc30d4" and "4187c3bfcad28c67c6396cf5a03c6533e2ddd5fb" have entirely different histories.

5 changed files with 32 additions and 69 deletions

View File

@ -411,20 +411,10 @@ void MainWindow::lineEditReturnPressed()
if(addPathSearch) if(addPathSearch)
{ {
LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false); LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false);
if(filesQuery.getLimit() == -1)
{
filesQuery.setLimit(1000);
}
results.append(searcher.search(filesQuery)); results.append(searcher.search(filesQuery));
} }
if(addContentSearch) if(addContentSearch)
{ {
if(this->contentSearchQuery.getLimit() == -1)
{
this->contentSearchQuery.setLimit(1000);
}
results.append(searcher.search(this->contentSearchQuery)); results.append(searcher.search(this->contentSearchQuery));
} }
return results; return results;
@ -454,12 +444,9 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
bool exists = pathInfo.exists(); bool exists = pathInfo.exists();
if(exists) if(exists)
{ {
if(!pathInfo.suffix().contains("htm")) // hack until we can preview them properly... if(PreviewGenerator::get(pathInfo) != nullptr)
{ {
if(PreviewGenerator::get(pathInfo) != nullptr) this->previewableSearchResults.append(result);
{
this->previewableSearchResults.append(result);
}
} }
} }
else else
@ -482,7 +469,7 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
QString statusText = "Results: " + QString::number(results.size()) + " files"; QString statusText = "Results: " + QString::number(results.size()) + " files";
if(hasDeleted) if(hasDeleted)
{ {
statusText += " WARNING: Some files are inaccessible. No preview available for those. Index may be out of sync"; statusText += " WARNING: Some files don't exist anymore. No preview available for those. Index out of sync";
} }
ui->lblSearchResults->setText(statusText); ui->lblSearchResults->setText(statusText);
} }

View File

@ -220,8 +220,19 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
{ {
throw LooqsGeneralException("Can't have two negations following each other"); throw LooqsGeneralException("Can't have two negations following each other");
} }
if(!previousWasBool())
{
result.addToken(Token(BOOL_AND)); // Implicit and, our default operation
}
result.addToken(Token(NEGATION)); result.addToken(Token(NEGATION));
} }
if(!result.tokens.isEmpty() && !previousWasBool() && !previousWas(NEGATION) && !previousWas(BRACKET_OPEN) &&
bracket != ")")
{
// the current token isn't a negation, isn't a boolean. Thus, implicit AND is required
result.addToken(Token(BOOL_AND));
}
if(bracket != "") if(bracket != "")
{ {
if(bracket == "(") if(bracket == "(")
@ -248,7 +259,7 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
if(filtername != "") if(filtername != "")
{ {
TokenType tokenType = WORD; TokenType tokenType;
QString value = m.captured("innerargs"); QString value = m.captured("innerargs");
if(value == "") if(value == "")
{ {
@ -259,15 +270,15 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
throw LooqsGeneralException("value cannot be empty for filters"); throw LooqsGeneralException("value cannot be empty for filters");
} }
if(filtername == "p" || filtername == "path.contains") if(filtername == "path.contains")
{ {
tokenType = FILTER_PATH_CONTAINS; tokenType = FILTER_PATH_CONTAINS;
} }
else if(filtername == "pb" || filtername == "path.starts") else if(filtername == "path.starts")
{ {
tokenType = FILTER_PATH_STARTS; tokenType = FILTER_PATH_STARTS;
} }
else if(filtername == "pe" || filtername == "path.ends") else if(filtername == "path.ends")
{ {
tokenType = FILTER_PATH_ENDS; tokenType = FILTER_PATH_ENDS;
} }
@ -283,21 +294,21 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
{ {
tokenType = FILTER_CONTENT_PAGE; tokenType = FILTER_CONTENT_PAGE;
} }
// TODO: given this is not really a "filter", this feels slightly misplaced here else if(filtername ==
else if(filtername == "sort") "sort") // TODO: given this is not really a "filter", this feels slightly misplaced here
{ {
if(!result.sortConditions.empty()) if(!result.sortConditions.empty())
{ {
throw LooqsGeneralException("Two sort statements are illegal"); throw LooqsGeneralException("Two sort statements are illegal");
} }
// TODO: hack, since we are not a "filter", we must remove a preceeding (implicit) boolean
if((result.tokens.last().type & BOOL) == BOOL)
{
result.tokens.pop_back();
}
result.sortConditions = createSortConditions(value); result.sortConditions = createSortConditions(value);
continue; continue;
} }
else if(filtername == "limit")
{
result.limit = value.toInt();
continue;
}
else else
{ {
throw LooqsGeneralException("Unknown filter provided!"); throw LooqsGeneralException("Unknown filter provided!");
@ -315,26 +326,6 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
} }
} }
/* Add our default implicit AND boolean condition where appropriate */
QVector<Token> newTokens;
TokenType prevType = BOOL_AND;
int needsBoolean = FILTER_CONTENT | FILTER_PATH | NEGATION;
for(Token &t : result.tokens)
{
if(t.type == BRACKET_OPEN || t.type & needsBoolean)
{
if(!((prevType & BOOL) == BOOL) && !((prevType & NEGATION) == NEGATION) &&
!((prevType & BRACKET_OPEN) == BRACKET_OPEN))
{
newTokens.append(Token(BOOL_AND));
}
}
prevType = t.type;
newTokens.append(t);
}
result.tokens = newTokens;
bool contentsearch = result.hasContentSearch(); bool contentsearch = result.hasContentSearch();
bool sortsForContent = std::any_of(result.sortConditions.begin(), result.sortConditions.end(), bool sortsForContent = std::any_of(result.sortConditions.begin(), result.sortConditions.end(),
[](SortCondition c) { return c.field == CONTENT_TEXT; }); [](SortCondition c) { return c.field == CONTENT_TEXT; });

View File

@ -40,7 +40,6 @@ class LooqsQuery
/* Helper field to determine quertype as well as to quickly check what kind of filters etc. /* Helper field to determine quertype as well as to quickly check what kind of filters etc.
* are being used in this query*/ * are being used in this query*/
int tokensMask = 0; int tokensMask = 0;
int limit = -1;
QVector<Token> tokens; QVector<Token> tokens;
QVector<SortCondition> sortConditions; QVector<SortCondition> sortConditions;
void addToken(Token t); void addToken(Token t);
@ -53,14 +52,6 @@ class LooqsQuery
{ {
return tokensMask; return tokensMask;
} }
int getLimit() const
{
return limit;
}
void setLimit(int limit)
{
this->limit = limit;
}
bool hasContentSearch(); bool hasContentSearch();
bool hasPathSearch(); bool hasPathSearch();

View File

@ -183,11 +183,6 @@ QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
whereSql + " " + sortSql; whereSql + " " + sortSql;
} }
if(query.getLimit() > 0)
{
prepSql += " LIMIT " + QString::number(query.getLimit());
}
QSqlQuery dbquery(*db); QSqlQuery dbquery(*db);
dbquery.prepare(prepSql); dbquery.prepare(prepSql);
for(const QString &value : bindValues) for(const QString &value : bindValues)

View File

@ -4,25 +4,24 @@
enum TokenType enum TokenType
{ {
WORD = 8, WORD,
NEGATION = 16, NEGATION = 2,
BOOL = 32, BOOL = 4,
BOOL_AND, BOOL_AND,
BOOL_OR, BOOL_OR,
GROUP = 64, GROUP = 8,
BRACKET_OPEN, BRACKET_OPEN,
BRACKET_CLOSE, BRACKET_CLOSE,
SORT = 128, SORT = 16,
FILTER_PATH = 256, FILTER_PATH = 32,
FILTER_PATH_MTIME, FILTER_PATH_MTIME,
FILTER_PATH_CONTAINS, FILTER_PATH_CONTAINS,
FILTER_PATH_SIZE, FILTER_PATH_SIZE,
FILTER_PATH_ENDS, FILTER_PATH_ENDS,
FILTER_PATH_STARTS, FILTER_PATH_STARTS,
FILTER_CONTENT = 512, FILTER_CONTENT = 64,
FILTER_CONTENT_CONTAINS, FILTER_CONTENT_CONTAINS,
FILTER_CONTENT_PAGE, FILTER_CONTENT_PAGE,
LIMIT = 1024
}; };
class Token class Token