Classified ads
searchmodel.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef FULLTEXTSEARCHMODEL_H
21 #define FULLTEXTSEARCHMODEL_H
22 
23 #include <QAbstractListModel>
24 #include "../util/hash.h"
25 #include "../net/protocol.h"
26 #include "../mcontroller.h"
27 #include <QVariantMap> // is actually typedef
28 
30 class CA ;
31 class Profile ;
32 class ProfileComment ;
33 class QTextDocument ; // for parsing html
34 
35 
44 class SearchModel: public QAbstractListModel {
45  Q_OBJECT
46 public:
50  typedef struct SearchResultItemStruct {
54  QString iDisplayName ;
56  bool operator==(const struct SearchResultItemStruct& a) const ;
58 
60  MController& aController) ;
61  ~SearchModel() ;
75  void setSearchString(const QString& aSearch,
76  bool aSearchAds,
77  bool aSearchProfiles,
78  bool aSearchComments,
79  bool aNetworkSeacrh = false ) ;
84  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const ;
89  virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const ;
94  QList<SearchModel::SearchResultItem> performSearch(const QString& aForString,
95  bool aSearchAds,
96  bool aSearchProfiles,
97  bool aSearchComments) ;
98 
104  void appendNetworkSearchResults(const QList<SearchModel::SearchResultItem>& aResults,
105  quint32 aSearchId,
106  const Hash& aFromPeer) ;
107 
120  static QVariant serializeSearchResults(const QList<SearchModel::SearchResultItem>& aResults,
121  quint32 aSearchId ) ;
122 
132  static bool deSerializeSearchResults(const QVariantMap& aResultJson,
133  QList<SearchModel::SearchResultItem>* aResults,
134  quint32* aSearchId ) ;
139  bool isFTSSupported () const { return iIsFTSSupported ; }
141  static bool queryIfFTSSupported() ;
143  static void createFTSTables() ;
149  void indexClassifiedAd(const CA& aCa) ;
150 
156  void indexProfileComment(const ProfileComment& aProfileComment) ;
157 
164  void indexProfile(const Profile& aProfile,
165  bool aWasUpdate = false ) ;
169  void getSearchCriteria(QString* aSearchStrPtr,
170  bool* aSearchAdsPtr,
171  bool* aSearchProfilesPtr,
172  bool* aSearchCommentsPtr,
173  Hash* aSearchIdPtr ) const ;
174 signals:
176  const QString& aExplanation) ;
177 private: // data
179  QString iSearchString ;
180  const bool iIsFTSSupported ;
181  QTextDocument *iHtmlParser ;
182  QList<SearchResultItem> iDisplayedResults ;
185  bool iSearchAds ;
188 } ;
189 #endif
static void createFTSTables()
Carrier-class for comments of a profile.
Definition: profilecomment.h:37
void setSearchString(const QString &aSearch, bool aSearchAds, bool aSearchProfiles, bool aSearchComments, bool aNetworkSeacrh=false)
static bool deSerializeSearchResults(const QVariantMap &aResultJson, QList< SearchModel::SearchResultItem > *aResults, quint32 *aSearchId)
Model-class for performing text-based searches on objects in db This datamodel part is dual-use ; it ...
Definition: searchmodel.h:44
void appendNetworkSearchResults(const QList< SearchModel::SearchResultItem > &aResults, quint32 aSearchId, const Hash &aFromPeer)
static bool queryIfFTSSupported()
bool iSearchProfiles
Definition: searchmodel.h:186
ProtocolItemType iItemType
Definition: searchmodel.h:51
SearchModel(MModelProtocolInterface &aModel, MController &aController)
Hash iFoundFromNode
Definition: searchmodel.h:53
bool iSearchAds
Definition: searchmodel.h:185
Hash is class that carries 160-bit digest.
Definition: hash.h:37
CAErrorSituation
Definition: mcontroller.h:48
QString iSearchString
Definition: searchmodel.h:179
void indexClassifiedAd(const CA &aCa)
void indexProfile(const Profile &aProfile, bool aWasUpdate=false)
QString iDisplayName
Definition: searchmodel.h:54
ProtocolItemType
Definition: protocol.h:124
struct SearchModel::SearchResultItemStruct SearchResultItem
QTextDocument * iHtmlParser
Definition: searchmodel.h:181
void indexProfileComment(const ProfileComment &aProfileComment)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
const bool iIsFTSSupported
Definition: searchmodel.h:180
void error(MController::CAErrorSituation aError, const QString &aExplanation)
Carrier-class for classified ad.
Definition: ca.h:34
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:44
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:39
bool operator==(const struct SearchResultItemStruct &a) const
QList< SearchResultItem > iDisplayedResults
Definition: searchmodel.h:182
Definition: searchmodel.h:50
MController & iController
Definition: searchmodel.h:183
void getSearchCriteria(QString *aSearchStrPtr, bool *aSearchAdsPtr, bool *aSearchProfilesPtr, bool *aSearchCommentsPtr, Hash *aSearchIdPtr) const
Hash iSearchId
Definition: searchmodel.h:184
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QList< SearchModel::SearchResultItem > performSearch(const QString &aForString, bool aSearchAds, bool aSearchProfiles, bool aSearchComments)
Carrier-class for user-profile data.
Definition: profile.h:36
Hash iItemHash
Definition: searchmodel.h:52
MModelProtocolInterface & iModel
Definition: searchmodel.h:178
static QVariant serializeSearchResults(const QList< SearchModel::SearchResultItem > &aResults, quint32 aSearchId)
bool iSearchComments
Definition: searchmodel.h:187
bool isFTSSupported() const
Definition: searchmodel.h:139