1 /* 2 * Copyright 2005-2008 Fabrice Colin 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #ifndef _QUERY_HISTORY_H 20 #define _QUERY_HISTORY_H 21 22 #include <string> 23 #include <vector> 24 #include <set> 25 26 #include "DocumentInfo.h" 27 #include "SQLiteBase.h" 28 29 /// Manages query history. 30 class QueryHistory : public SQLiteBase 31 { 32 public: 33 QueryHistory(const std::string &database); 34 virtual ~QueryHistory(); 35 36 /// Creates the QueryHistory table in the database. 37 static bool create(const std::string &database); 38 39 /// Inserts an URL. 40 bool insertItem(const std::string &queryName, const std::string &engineName, 41 const std::string &url, const std::string &title, const std::string &extract, float score); 42 43 /** 44 * Checks if an URL is in the query's history. 45 * If it is, it returns the current and previous scores; returns 0 if not found. 46 */ 47 float hasItem(const std::string &queryName, const std::string &engineName, const std::string &url, 48 float &previousScore); 49 50 /// Gets the list of engines the query was run on. 51 bool getEngines(const std::string &queryName, std::set<std::string> &enginesList); 52 53 /// Gets the first max items for the given query, engine pair. 54 bool getItems(const std::string &queryName, const std::string &engineName, 55 unsigned int max, std::vector<DocumentInfo> &resultsList); 56 57 /// Gets an item's extract. 58 std::string getItemExtract(const std::string &queryName, const std::string &engineName, 59 const std::string &url); 60 61 /// Finds URLs. 62 bool findUrlsLike(const std::string &url, unsigned int count, 63 std::set<std::string> &urls); 64 65 /// Gets a query's latest run times. 66 bool getLatestRuns(const std::string &queryName, const std::string &engineName, 67 unsigned int runCount, std::set<time_t> &runTimes); 68 69 /// Deletes items at least as old as the given date. 70 bool deleteItems(const std::string &queryName, const std::string &engineName, 71 time_t cutOffDate); 72 73 /// Deletes items. 74 bool deleteItems(const std::string &name, bool isQueryName); 75 76 /// Expires items older than the given date. 77 bool expireItems(time_t expiryDate); 78 79 private: 80 QueryHistory(const QueryHistory &other); 81 QueryHistory &operator=(const QueryHistory &other); 82 83 }; 84 85 #endif // _QUERY_HISTORY_H 86