Classified ads
Classes | Public Types | Signals | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SearchModel Class Reference

Model-class for performing text-based searches on objects in db This datamodel part is dual-use ; it inherits listmodel so that it may be used as underlaying data-container for list views. It may also be used as engine of network searches that happen invisibly to user e.g. those queries do not modify the content shown to UI via QAbstractListModel. More...

#include <searchmodel.h>

Inheritance diagram for SearchModel:
Inheritance graph
[legend]
Collaboration diagram for SearchModel:
Collaboration graph
[legend]

Classes

struct  SearchResultItemStruct
 

Public Types

typedef struct SearchModel::SearchResultItemStruct SearchResultItem
 

Signals

void error (MController::CAErrorSituation aError, const QString &aExplanation)
 

Public Member Functions

 SearchModel (MModelProtocolInterface &aModel, MController &aController)
 
 ~SearchModel ()
 
void setSearchString (const QString &aSearch, bool aSearchAds, bool aSearchProfiles, bool aSearchComments, bool aNetworkSeacrh=false)
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
QList< SearchModel::SearchResultItemperformSearch (const QString &aForString, bool aSearchAds, bool aSearchProfiles, bool aSearchComments)
 
void appendNetworkSearchResults (const QList< SearchModel::SearchResultItem > &aResults, quint32 aSearchId, const Hash &aFromPeer)
 
bool isFTSSupported () const
 
void indexClassifiedAd (const CA &aCa)
 
void indexProfileComment (const ProfileComment &aProfileComment)
 
void indexProfile (const Profile &aProfile, bool aWasUpdate=false)
 
void getSearchCriteria (QString *aSearchStrPtr, bool *aSearchAdsPtr, bool *aSearchProfilesPtr, bool *aSearchCommentsPtr, Hash *aSearchIdPtr) const
 

Static Public Member Functions

static QVariant serializeSearchResults (const QList< SearchModel::SearchResultItem > &aResults, quint32 aSearchId)
 
static bool deSerializeSearchResults (const QVariantMap &aResultJson, QList< SearchModel::SearchResultItem > *aResults, quint32 *aSearchId)
 
static bool queryIfFTSSupported ()
 
static void createFTSTables ()
 

Private Attributes

MModelProtocolInterfaceiModel
 
QString iSearchString
 
const bool iIsFTSSupported
 
QList< SearchResultItemiDisplayedResults
 
MControlleriController
 
Hash iSearchId
 
bool iSearchAds
 
bool iSearchProfiles
 
bool iSearchComments
 

Detailed Description

Model-class for performing text-based searches on objects in db This datamodel part is dual-use ; it inherits listmodel so that it may be used as underlaying data-container for list views. It may also be used as engine of network searches that happen invisibly to user e.g. those queries do not modify the content shown to UI via QAbstractListModel.

Member Typedef Documentation

Data structure for search results.

Constructor & Destructor Documentation

SearchModel::SearchModel ( MModelProtocolInterface aModel,
MController aController 
)
SearchModel::~SearchModel ( )

Member Function Documentation

void SearchModel::appendNetworkSearchResults ( const QList< SearchModel::SearchResultItem > &  aResults,
quint32  aSearchId,
const Hash aFromPeer 
)

Method called from protocol parser in purpose of appending search results from remote node into datamodel. Model is locked during this call

static void SearchModel::createFTSTables ( )
static

method for creating db tables related to FTS

virtual QVariant SearchModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

re-implemented from QAbstractListModel

Returns
data to display in list
static bool SearchModel::deSerializeSearchResults ( const QVariantMap &  aResultJson,
QList< SearchModel::SearchResultItem > *  aResults,
quint32 *  aSearchId 
)
static

opposite to serializeSearchResults

Parameters
aResultJsonjson object containing search results.
aResultsarray where contents of aResultJson will be appended
aSearchIdpointer to unsigned that will contain search identifier from aResultJson
Returns
true on success
void SearchModel::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
signal
void SearchModel::getSearchCriteria ( QString *  aSearchStrPtr,
bool *  aSearchAdsPtr,
bool *  aSearchProfilesPtr,
bool *  aSearchCommentsPtr,
Hash aSearchIdPtr 
) const

method for obtaining the search criteria inside

void SearchModel::indexClassifiedAd ( const CA aCa)

method for adding a classified ad into index

Parameters
aCais the classified ad to add to index
Returns
none
void SearchModel::indexProfile ( const Profile aProfile,
bool  aWasUpdate = false 
)

method for adding a profile into index

Parameters
aProfileis the profile to add to index
aWasUpdateif the profile was updated instead of inserted
Returns
none
void SearchModel::indexProfileComment ( const ProfileComment aProfileComment)

method for adding a profile-comment into index

Parameters
aProfileCommentis the comment to add to index
Returns
none
bool SearchModel::isFTSSupported ( ) const
inline

method for querying if search is supported at all

Returns
true if search is supported
QList<SearchModel::SearchResultItem> SearchModel::performSearch ( const QString &  aForString,
bool  aSearchAds,
bool  aSearchProfiles,
bool  aSearchComments 
)

method for actually searching the index. datamodel must be locked when this is called

static bool SearchModel::queryIfFTSSupported ( )
static

method for checking if database has support for full text search

virtual int SearchModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

re-implemented from QAbstractListModel

Returns
number of rows in list
static QVariant SearchModel::serializeSearchResults ( const QList< SearchModel::SearchResultItem > &  aResults,
quint32  aSearchId 
)
static

Method for serializing search results to be sent to peering node. Usually items sent over to peering nodes like profiles or comments are classes and they will (de)serialize themselves. Search resultset is list of structures so lets have just serialization methods here in model, these are called from protocol formatter/parser.

Parameters
aResultsactual results of search
aSearchIdid from peering node
Returns
JSon-obj as QVariant
void SearchModel::setSearchString ( const QString &  aSearch,
bool  aSearchAds,
bool  aSearchProfiles,
bool  aSearchComments,
bool  aNetworkSeacrh = false 
)

Method that performs search from local UI. This will change model contens as is shown via QAbstractListModel inheritance

aSearch is the string to offer to FTS implementation aSearchAds if true, classified ads are to be searched aSearchProfiles if true, profiles are to be searched aSearchComments if true, profile comments are to be searched. aNetworkSeacrh if true no local search is performed, and datamodel is emptied with idea that search results from remote nodes will populate the model

Member Data Documentation

MController& SearchModel::iController
private
QList<SearchResultItem> SearchModel::iDisplayedResults
private
const bool SearchModel::iIsFTSSupported
private
MModelProtocolInterface& SearchModel::iModel
private
bool SearchModel::iSearchAds
private
bool SearchModel::iSearchComments
private
Hash SearchModel::iSearchId
private

searches may be lengthty: this connects results

bool SearchModel::iSearchProfiles
private
QString SearchModel::iSearchString
private

The documentation for this class was generated from the following file: