Contenido API - SearchResult Object

This object ranks and displays the result of the indexed fulltext search. If you are not comfortable with this API feel free to use your own methods to display the search results. The search result is basically an array with article ID's.

If $search_result = $search->searchIndex($searchword, $searchwordex);

use object with

$oSearchResults = new SearchResult($search_result, 10);

$oSearchResults->setReplacement('', ''); // html-tags to emphasize the located searchwords

$num_res = $oSearchResults->getNumberOfResults(); $num_pages = $oSearchResults->getNumberOfPages(); $res_page = $oSearchResults->getSearchResultPage(1); // first result page foreach ($res_page as $key => $val) { $headline = $oSearchResults->getSearchContent($key, 'HTMLHEAD'); $first_headline = $headline[0]; $text = $oSearchResults->getSearchContent($key, 'HTML'); $first_text = $text[0]; $similarity = $oSearchResults->getSimilarity($key); $iOccurrence = $oSearchResults->getOccurrence($key); }

version 1.0.0
author Willi Man
copyright four for business AG <www.4fb.de>

 Methods

Compute ranking factor for each search result and order the search results by ranking factor NOTE: The ranking factor is the sum of occurences of matching searchterms weighted by similarity (in %) between searchword and matching word in the article.

SearchResult(array $search_result, int $result_per_page, \DB_Contenido $oDB, bool $bDebug) 

TODO: One can think of more sophisticated ranking strategies. One could use the content type information for example because a matching word in the headline (CMS_HEADLINE[1]) could be weighted more than a matching word in the text (CMS_HTML[1]).

Parameters

$search_result

array

List of article ids

$result_per_page

int

Number of items per page

$oDB

\DB_Contenido

Optional db instance

$bDebug

bool

Optional flag to enable debugging

getArtCat()

getArtCat($artid) : \Category

todo Is not job of search, should be outsourced!

Parameters

$artid

Returns

\CategoryId

getContent()

getContent($art_id, \$art_id $cms_type, $id) : \Content

Parameters

$art_id

$cms_type

\$art_id

$id

Returns

\Contentof an article, specified by it's content type

Returns number of result pages

getNumberOfPages() : int

Returns

int

Returns number of results

getNumberOfResults() : int

Returns

int

getOccurrence()

getOccurrence(\$art_id $art_id) : \Number

Parameters

$art_id

\$art_id

Id of an article

Returns

\Numberof matching searchwords found in article

getSearchContent()

getSearchContent(\$cms_type $art_id, \$art_id $cms_type, $cms_nr) : \Content

Parameters

$art_id

\$cms_type

Content type

$cms_type

\$art_id

Id of an article

$cms_nr

Returns

\Contentof an article in search result, specified by its type

Returns articles in page.

getSearchResultPage(int $page_id) : array

Parameters

$page_id

int

Returns

arrayArtices in page $page_id

getSimilarity()

getSimilarity(\$art_id $art_id) : \Similarity

Parameters

$art_id

\$art_id

Id of an article

Returns

\Similaritybetween searchword and matching word in article

Setter for debug

setDebug(bool $bDebug) 
Inherited

inherited_from \SearchBaseAbstract::setDebug()

Parameters

$bDebug

bool

setOrderedSearchResult()

setOrderedSearchResult($ranked_search, $result_per_page) : void

Parameters

$ranked_search

$result_per_page

setReplacement()

setReplacement(string $rep1, string $rep2) : void

Parameters

$rep1

string

The opening html-tag to emphasize the searchword e.g. ''

$rep2

string

The closing html-tag e.g. ''

Initialises some properties

__construct(\DB_Contenido $oDB, bool $bDebug) 
Inherited

inherited_from \SearchBaseAbstract::__construct()

Parameters

$oDB

\DB_Contenido

Optional database instance

$bDebug

bool

Optional, flag to enable debugging

Main debug function, prints dumps parameter if debugging is enabled

_debug(string $msg, mixed $var) 
Inherited

inherited_from \SearchBaseAbstract::_debug()

Parameters

$msg

string

Some text

$var

mixed

The variable to dump

 Properties

 

Instance of class Index

$index : object

 

Array of result-pages with array's of article id's

$ordered_search_result : array

 

Number of result pages

$pages : int

 

Array of article id's with ranking information

$rank_structure : array

 

Array of html-tags to emphasize the searchwords

$replacement : array

 

Current result page

$result_page : int

 

Results per page to display

$result_per_page : int

 

Number of results

$results : int

 

Array of article id's with information about cms-types, occurence of keyword/searchword, similarity ...

$search_result : array

 

Flag to enable debug

$bDebug : bool
Inherited

inherited_from \SearchBaseAbstract::$$bDebug
 

Contenido configuration data

$cfg : array
Inherited

inherited_from \SearchBaseAbstract::$$cfg
 

Client id

$client : int
Inherited

inherited_from \SearchBaseAbstract::$$client
 

Language id of a client

$lang : int
Inherited

inherited_from \SearchBaseAbstract::$$lang
 

Contenido database object

$oDB : \DB_Contenido
Inherited

inherited_from \SearchBaseAbstract::$$oDB