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
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (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 GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef FULLTEXTSEARCHMODEL_H
22 #define FULLTEXTSEARCHMODEL_H
23 
24 #include <QAbstractListModel>
25 #include "../util/hash.h"
26 #include "../net/protocol.h"
27 #include "../mcontroller.h"
28 #include <QVariantMap> // is actually typedef
29 
31 class CA ;
32 class Profile ;
33 class ProfileComment ;
34 class QTextDocument ; // for parsing html
35 
36 
45 class SearchModel: public QAbstractListModel {
46  Q_OBJECT
47 public:
51  typedef struct SearchResultItemStruct {
55  QString iDisplayName ;
57  bool operator==(const struct SearchResultItemStruct& a) const ;
59 
61  MController& aController) ;
62  ~SearchModel() ;
76  void setSearchString(const QString& aSearch,
77  bool aSearchAds,
78  bool aSearchProfiles,
79  bool aSearchComments,
80  bool aNetworkSeacrh = false ) ;
85  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const ;
90  virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const ;
95  QList<SearchModel::SearchResultItem> performSearch(const QString& aForString,
96  bool aSearchAds,
97  bool aSearchProfiles,
98  bool aSearchComments) ;
99 
105  void appendNetworkSearchResults(const QList<SearchModel::SearchResultItem>& aResults,
106  quint32 aSearchId,
107  const Hash& aFromPeer) ;
108 
121  static QVariant serializeSearchResults(const QList<SearchModel::SearchResultItem>& aResults,
122  quint32 aSearchId ) ;
123 
133  static bool deSerializeSearchResults(const QVariantMap& aResultJson,
134  QList<SearchModel::SearchResultItem>* aResults,
135  quint32* aSearchId ) ;
140  bool isFTSSupported () const {
141  return iIsFTSSupported ;
142  }
144  static bool queryIfFTSSupported() ;
146  static void createFTSTables() ;
152  void indexClassifiedAd(const CA& aCa) ;
153 
159  void indexProfileComment(const ProfileComment& aProfileComment) ;
160 
167  void indexProfile(const Profile& aProfile,
168  bool aWasUpdate = false ) ;
172  void getSearchCriteria(QString* aSearchStrPtr,
173  bool* aSearchAdsPtr,
174  bool* aSearchProfilesPtr,
175  bool* aSearchCommentsPtr,
176  Hash* aSearchIdPtr ) const ;
177 signals:
179  const QString& aExplanation) ;
180 private: // data
182  QString iSearchString ;
183  const bool iIsFTSSupported ;
184  QList<SearchResultItem> iDisplayedResults ;
187  bool iSearchAds ;
190 } ;
191 #endif
static void createFTSTables()
Carrier-class for comments of a profile.
Definition: profilecomment.h:38
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:45
void appendNetworkSearchResults(const QList< SearchModel::SearchResultItem > &aResults, quint32 aSearchId, const Hash &aFromPeer)
static bool queryIfFTSSupported()
bool iSearchProfiles
Definition: searchmodel.h:188
ProtocolItemType iItemType
Definition: searchmodel.h:52
SearchModel(MModelProtocolInterface &aModel, MController &aController)
Hash iFoundFromNode
Definition: searchmodel.h:54
bool iSearchAds
Definition: searchmodel.h:187
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:52
QString iSearchString
Definition: searchmodel.h:182
void indexClassifiedAd(const CA &aCa)
void indexProfile(const Profile &aProfile, bool aWasUpdate=false)
QString iDisplayName
Definition: searchmodel.h:55
ProtocolItemType
Definition: protocol.h:150
struct SearchModel::SearchResultItemStruct SearchResultItem
void indexProfileComment(const ProfileComment &aProfileComment)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
const bool iIsFTSSupported
Definition: searchmodel.h:183
void error(MController::CAErrorSituation aError, const QString &aExplanation)
Carrier-class for classified ad.
Definition: ca.h:35
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:45
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:43
bool operator==(const struct SearchResultItemStruct &a) const
QList< SearchResultItem > iDisplayedResults
Definition: searchmodel.h:184
Definition: searchmodel.h:51
MController & iController
Definition: searchmodel.h:185
void getSearchCriteria(QString *aSearchStrPtr, bool *aSearchAdsPtr, bool *aSearchProfilesPtr, bool *aSearchCommentsPtr, Hash *aSearchIdPtr) const
Hash iSearchId
Definition: searchmodel.h:186
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:37
Hash iItemHash
Definition: searchmodel.h:53
MModelProtocolInterface & iModel
Definition: searchmodel.h:181
static QVariant serializeSearchResults(const QList< SearchModel::SearchResultItem > &aResults, quint32 aSearchId)
bool iSearchComments
Definition: searchmodel.h:189
bool isFTSSupported() const
Definition: searchmodel.h:140