<commit_before>#include <QtSql>
#include <QtWebEngineWidgets>
#include <QtWidgets>


#define HOMEPAGE    "http://google.com"
#define USER_AGENT  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)" \
                    "Chrome/55.0.0.0 Safari/537.36 Dobostorta/" GIT_VERSION

#define SHORTCUT_META           (Qt::CTRL)
#define SHORTCUT_FORWARD        {SHORTCUT_META + Qt::Key_I}
#define SHORTCUT_BACK           {SHORTCUT_META + Qt::Key_O}
#define SHORTCUT_RELOAD         {SHORTCUT_META + Qt::Key_R}
#define SHORTCUT_BAR            {SHORTCUT_META + Qt::Key_Colon}
#define SHORTCUT_BAR_ALT        {SHORTCUT_META + Qt::SHIFT + Qt::Key_Colon}
#define SHORTCUT_FIND           {SHORTCUT_META + Qt::Key_Slash}
#define SHORTCUT_ESCAPE         {SHORTCUT_META + Qt::Key_BracketLeft}
#define SHORTCUT_DOWN           {SHORTCUT_META + Qt::Key_J}
#define SHORTCUT_UP             {SHORTCUT_META + Qt::Key_K}
#define SHORTCUT_LEFT           {SHORTCUT_META + Qt::Key_H}
#define SHORTCUT_RIGHT          {SHORTCUT_META + Qt::Key_L}
#define SHORTCUT_TOP            {SHORTCUT_META + Qt::Key_G, SHORTCUT_META + Qt::Key_G}
#define SHORTCUT_BOTTOM         {SHORTCUT_META + Qt::SHIFT + Qt::Key_G}
#define SHORTCUT_NEXT           {SHORTCUT_META + Qt::Key_N}
#define SHORTCUT_PREV           {SHORTCUT_META + Qt::Key_P}
#define SHORTCUT_ZOOMIN         {SHORTCUT_META + Qt::Key_Plus}
#define SHORTCUT_ZOOMIN_ALT     {SHORTCUT_META + Qt::SHIFT + Qt::Key_Plus}
#define SHORTCUT_ZOOMOUT        {SHORTCUT_META + Qt::Key_Minus}
#define SHORTCUT_ZOOMRESET      {SHORTCUT_META + Qt::Key_0}
#define SHORTCUT_NEW_WINDOW     {SHORTCUT_META + Qt::SHIFT + Qt::Key_N}
#define SHORTCUT_NEW_INCOGNITO  {SHORTCUT_META + Qt::SHIFT + Qt::Key_P}

#define SCROLL_STEP_X  20
#define SCROLL_STEP_Y  20
#define ZOOM_STEP      0.1


enum QueryType {
    URLWithScheme,
    URLWithoutScheme,
    SearchWithScheme,
    SearchWithoutScheme,
    InSiteSearch
};

QueryType guessQueryType(const QString &str) {
    if (str.startsWith("search:"))
        return SearchWithScheme;
    else if (str.startsWith("find:"))
        return InSiteSearch;
    else if (QRegExp("^[a-zA-Z0-9]+:").indexIn(str) != -1)
        return URLWithScheme;
    else if (QRegExp("^[^/]+(\\.[^/]+|:[0-9]+)").indexIn(str) != -1)
        return URLWithoutScheme;
    else
        return SearchWithoutScheme;
}


QString expandFilePath(const QString &path) {
    if (path.startsWith("~/"))
        return QFileInfo(QDir::home(), path.right(path.length() - 2)).absoluteFilePath();
    else
        return QFileInfo(QDir::current(), path).absoluteFilePath();
}


class TortaDatabase {
    QSqlDatabase db;
    QSqlQuery add;
    QSqlQuery search;
    QSqlQuery forward;

public:
    TortaDatabase() : db(QSqlDatabase::addDatabase("QSQLITE")), add(db), search(db), forward(db) {
        db.setDatabaseName(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
                           + "/history");
        db.open();

        db.exec("CREATE TABLE IF NOT EXISTS history                        \
                   (timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP UNIQUE,  \
                    scheme TEXT NOT NULL, address TEXT NOT NULL)");
        db.exec("CREATE INDEX IF NOT EXISTS history_index ON history(timestamp);");

        add.prepare("INSERT INTO history (scheme, address) VALUES (:scheme, :address)");
        add.setForwardOnly(true);

        search.prepare("SELECT scheme||':'||address AS uri FROM history WHERE address LIKE :query  \
                          GROUP BY uri ORDER BY COUNT(timestamp) DESC, MIN(timestamp)");
        search.setForwardOnly(true);

        forward.prepare("SELECT scheme, address FROM history                                       \
                           WHERE (scheme = 'search' AND address LIKE :search_query)                \<commit_msg>Added limit of suggestion<commit_after>#include <QtSql>
#include <QtWebEngineWidgets>
#include <QtWidgets>


#define HOMEPAGE    "http://google.com"
#define USER_AGENT  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)" \
                    "Chrome/55.0.0.0 Safari/537.36 Dobostorta/" GIT_VERSION

#define SHORTCUT_META           (Qt::CTRL)
#define SHORTCUT_FORWARD        {SHORTCUT_META + Qt::Key_I}
#define SHORTCUT_BACK           {SHORTCUT_META + Qt::Key_O}
#define SHORTCUT_RELOAD         {SHORTCUT_META + Qt::Key_R}
#define SHORTCUT_BAR            {SHORTCUT_META + Qt::Key_Colon}
#define SHORTCUT_BAR_ALT        {SHORTCUT_META + Qt::SHIFT + Qt::Key_Colon}
#define SHORTCUT_FIND           {SHORTCUT_META + Qt::Key_Slash}
#define SHORTCUT_ESCAPE         {SHORTCUT_META + Qt::Key_BracketLeft}
#define SHORTCUT_DOWN           {SHORTCUT_META + Qt::Key_J}
#define SHORTCUT_UP             {SHORTCUT_META + Qt::Key_K}
#define SHORTCUT_LEFT           {SHORTCUT_META + Qt::Key_H}
#define SHORTCUT_RIGHT          {SHORTCUT_META + Qt::Key_L}
#define SHORTCUT_TOP            {SHORTCUT_META + Qt::Key_G, SHORTCUT_META + Qt::Key_G}
#define SHORTCUT_BOTTOM         {SHORTCUT_META + Qt::SHIFT + Qt::Key_G}
#define SHORTCUT_NEXT           {SHORTCUT_META + Qt::Key_N}
#define SHORTCUT_PREV           {SHORTCUT_META + Qt::Key_P}
#define SHORTCUT_ZOOMIN         {SHORTCUT_META + Qt::Key_Plus}
#define SHORTCUT_ZOOMIN_ALT     {SHORTCUT_META + Qt::SHIFT + Qt::Key_Plus}
#define SHORTCUT_ZOOMOUT        {SHORTCUT_META + Qt::Key_Minus}
#define SHORTCUT_ZOOMRESET      {SHORTCUT_META + Qt::Key_0}
#define SHORTCUT_NEW_WINDOW     {SHORTCUT_META + Qt::SHIFT + Qt::Key_N}
#define SHORTCUT_NEW_INCOGNITO  {SHORTCUT_META + Qt::SHIFT + Qt::Key_P}

#define SCROLL_STEP_X  20
#define SCROLL_STEP_Y  20
#define ZOOM_STEP      0.1


enum QueryType {
    URLWithScheme,
    URLWithoutScheme,
    SearchWithScheme,
    SearchWithoutScheme,
    InSiteSearch
};

QueryType guessQueryType(const QString &str) {
    if (str.startsWith("search:"))
        return SearchWithScheme;
    else if (str.startsWith("find:"))
        return InSiteSearch;
    else if (QRegExp("^[a-zA-Z0-9]+:").indexIn(str) != -1)
        return URLWithScheme;
    else if (QRegExp("^[^/]+(\\.[^/]+|:[0-9]+)").indexIn(str) != -1)
        return URLWithoutScheme;
    else
        return SearchWithoutScheme;
}


QString expandFilePath(const QString &path) {
    if (path.startsWith("~/"))
        return QFileInfo(QDir::home(), path.right(path.length() - 2)).absoluteFilePath();
    else
        return QFileInfo(QDir::current(), path).absoluteFilePath();
}


class TortaDatabase {
    QSqlDatabase db;
    QSqlQuery add;
    QSqlQuery search;
    QSqlQuery forward;

public:
    TortaDatabase() : db(QSqlDatabase::addDatabase("QSQLITE")), add(db), search(db), forward(db) {
        db.setDatabaseName(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
                           + "/history");
        db.open();

        db.exec("CREATE TABLE IF NOT EXISTS history                        \
                   (timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP UNIQUE,  \
                    scheme TEXT NOT NULL, address TEXT NOT NULL)");
        db.exec("CREATE INDEX IF NOT EXISTS history_index ON history(timestamp);");

        add.prepare("INSERT INTO history (scheme, address) VALUES (:scheme, :address)");
        add.setForwardOnly(true);

        search.prepare("SELECT scheme||':'||address AS uri FROM history WHERE address LIKE :query  \
                          GROUP BY uri ORDER BY COUNT(timestamp) DESC, MIN(timestamp) LIMIT 500");
        search.setForwardOnly(true);

        forward.prepare("SELECT scheme, address FROM history                                       \
                           WHERE (scheme = 'search' AND address LIKE :search_query)                \
{'fraction_non_alphanumeric': 0.11593449441122954, 'fraction_numerical': 0.010007798284377437, 'mean_word_length': 2.914038657171923, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '69404', 'n_tokens_mistral': 2762, 'n_tokens_neox': 2651, 'n_words': 527}