TelegramSearch/src/search.h

42 lines
1.2 KiB
C
Raw Normal View History

2021-04-07 11:42:35 +02:00
#pragma once
#include <string>
#include <list>
2021-04-07 17:52:32 +02:00
#include <vector>
#include <set>
2021-04-07 11:42:35 +02:00
#include <map>
#include <cstdint>
#include <nlohmann/json_fwd.hpp>
using json = nlohmann::json;
2021-04-11 01:47:55 +02:00
#include "filter.h"
#include "message.h"
2021-04-07 11:42:35 +02:00
class Search {
public:
Search();
2021-04-07 17:00:19 +02:00
//copy chatnames from orig, and message list either from orig, or - if set - from list
Search(const Search& orig, std::list<const Message*>* list = nullptr);
2021-04-07 11:42:35 +02:00
~Search();
void addFile(const std::string& file);
2021-04-07 17:52:32 +02:00
void finalize(); //stop adding files and finalize deduplication, could be called twice, but then a deduplication is not guaranteed
2021-04-07 11:42:35 +02:00
2021-04-11 01:47:55 +02:00
std::list<const Message*> search(const Filter& filter) const;
2021-04-07 20:07:11 +02:00
const std::string& getChatname(int64_t id) const;
std::string getShortChatname(int64_t id) const;
2021-04-07 13:56:18 +02:00
uint32_t getChatCount() const;
uint64_t getMessageCount() const;
2021-04-07 11:42:35 +02:00
private:
void searchRegex(const std::string& text, bool ignoreCase, std::list<const Message*>& out) const;
2021-04-11 01:47:55 +02:00
void runsearch(const Filter& filter, std::list<const Message*>& out) const;
2021-04-07 11:42:35 +02:00
2021-04-07 20:07:11 +02:00
void loadMessages(const json& j, int64_t chatid);
2021-04-07 11:42:35 +02:00
2021-04-07 17:52:32 +02:00
std::vector<Message> msgs;
std::set<Message> deduplicate; //intermediate store, for reading files and deduplicate them
2021-04-07 20:07:11 +02:00
std::map<int64_t, std::string> chatnames;
2021-04-07 11:42:35 +02:00
};