looqs/shared/looqsquery.h
Albert S a6ddcef0c0 shared: LooqsQuery: Fix logic of implicit AND booleans. Add 'limit:' support
Add implicit AND booleans at the end.

This fixes a number of issues in LooqsQuery:

(1) A query like a b c p:(something) would fail, because
a b c get merged into one word. This happens at the end.

lonewords are special and do not become a token immediatly. So previous
logic to add implicit ANDs does not apply.

(2) Negations were also broken with lonewords.

(3) The TokenType enum fields were too narrow to be useful for the bitmask

Independent of that, add support for 'limit:'
2022-06-05 14:39:57 +02:00

73 γραμμές
1.3 KiB
C++

#ifndef LOOQSQUERY_H
#define LOOQSQUERY_H
#include <QString>
#include <QVector>
#include "looqsgeneralexception.h"
#include "token.h"
/* Fields that can be queried or sorted */
enum QueryField
{
FILE_PATH,
FILE_MTIME,
FILE_SIZE,
CONTENT_TEXT,
CONTENT_TEXT_PAGE
};
enum SortOrder
{
ASC,
DESC
};
struct SortCondition
{
QueryField field;
SortOrder order;
};
enum QueryType
{
NOTHING = 0,
PATH_ONLY = FILTER_PATH,
CONTENT_ONLY = FILTER_CONTENT,
COMBINED = PATH_ONLY | CONTENT_ONLY
};
class LooqsQuery
{
private:
/* Helper field to determine quertype as well as to quickly check what kind of filters etc.
* are being used in this query*/
int tokensMask = 0;
int limit = -1;
QVector<Token> tokens;
QVector<SortCondition> sortConditions;
void addToken(Token t);
public:
const QVector<Token> &getTokens() const;
const QVector<SortCondition> &getSortConditions() const;
QueryType getQueryType();
int getTokensMask() const
{
return tokensMask;
}
int getLimit() const
{
return limit;
}
void setLimit(int limit)
{
this->limit = limit;
}
bool hasContentSearch();
bool hasPathSearch();
void addSortCondition(SortCondition sc);
static bool checkParanthesis(QString query);
static LooqsQuery build(QString query, TokenType loneWordsTokenType, bool mergeLoneWords);
};
#endif // LOOQSQUERY_H