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

◆ SearchResultItem

Data structure for search results.

Constructor & Destructor Documentation

◆ SearchModel()

SearchModel::SearchModel ( MModelProtocolInterface aModel,
MController aController 
)

◆ ~SearchModel()

SearchModel::~SearchModel ( )

Member Function Documentation

◆ appendNetworkSearchResults()

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

◆ createFTSTables()

static void SearchModel::createFTSTables ( )
static

method for creating db tables related to FTS

◆ data()

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

re-implemented from QAbstractListModel

Returns
data to display in list

◆ deSerializeSearchResults()

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

◆ error

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

◆ getSearchCriteria()

void SearchModel::getSearchCriteria ( QString *  aSearchStrPtr,
bool *  aSearchAdsPtr,
bool *  aSearchProfilesPtr,
bool *  aSearchCommentsPtr,
Hash aSearchIdPtr 
) const

method for obtaining the search criteria inside

◆ indexClassifiedAd()

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

◆ indexProfile()

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

◆ indexProfileComment()

void SearchModel::indexProfileComment ( const ProfileComment aProfileComment)

method for adding a profile-comment into index

Parameters
aProfileCommentis the comment to add to index
Returns
none

◆ isFTSSupported()

bool SearchModel::isFTSSupported ( ) const
inline

method for querying if search is supported at all

Returns
true if search is supported

◆ performSearch()

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

◆ queryIfFTSSupported()

static bool SearchModel::queryIfFTSSupported ( )
static

method for checking if database has support for full text search

◆ rowCount()

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

re-implemented from QAbstractListModel

Returns
number of rows in list

◆ serializeSearchResults()

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

◆ setSearchString()

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

◆ iController

MController& SearchModel::iController
private

◆ iDisplayedResults

QList<SearchResultItem> SearchModel::iDisplayedResults
private

◆ iIsFTSSupported

const bool SearchModel::iIsFTSSupported
private

◆ iModel

MModelProtocolInterface& SearchModel::iModel
private

◆ iSearchAds

bool SearchModel::iSearchAds
private

◆ iSearchComments

bool SearchModel::iSearchComments
private

◆ iSearchId

Hash SearchModel::iSearchId
private

searches may be lengthty: this connects results

◆ iSearchProfiles

bool SearchModel::iSearchProfiles
private

◆ iSearchString

QString SearchModel::iSearchString
private

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