CONTENIDO API - Search Object

This object starts a indexed fulltext search

TODO: The way to set the search options could be done much more better! The computation of the set of searchable articles should not be treated in this class. It is better to compute the array of searchable articles from the outside and to pass the array of searchable articles as parameter. Avoid foreach loops.

Use object with

$options = array('db' => 'regexp', // use db function regexp 'combine' => 'or'); // combine searchwords with or

The range of searchable articles is by default the complete content which is online and not protected.

With option 'searchable_articles' you can define your own set of searchable articles. If parameter 'searchable_articles' is set the options 'cat_tree', 'categories', 'articles', 'exclude', 'artspecs', 'protected', 'dontshowofflinearticles' don't have any effect.

$options = array('db' => 'regexp', // use db function regexp 'combine' => 'or', // combine searchwords with or 'searchable_articles' => array(5, 6, 9, 13));

One can define the range of searchable articles by setting the parameter 'exclude' to false which means the range of categories defined by parameter 'cat_tree' or 'categories' and the range of articles defined by parameter 'articles' is included.

$options = array('db' => 'regexp', // use db function regexp 'combine' => 'or', // combine searchwords with or 'exclude' => false, // => searchrange specified in 'cat_tree', 'categories' and 'articles' is included 'cat_tree' => array(12), // tree with root 12 included 'categories' => array(100,111), // categories 100, 111 included 'articles' => array(33), // article 33 included 'artspecs' => array(2, 3), // array of article specifications => search only articles with these artspecs 'res_per_page' => 2, // results per page 'protected' => true); // => do not search articles or articles in categories which are offline or protected 'dontshowofflinearticles' => false); // => search offline articles or articles in categories which are offline

You can build the complement of the range of searchable articles by setting the parameter 'exclude' to true which means the range of categories defined by parameter 'cat_tree' or 'categories' and the range of articles defined by parameter 'articles' is excluded from search.

$options = array('db' => 'regexp', // use db function regexp 'combine' => 'or', // combine searchwords with or 'exclude' => true, // => searchrange specified in 'cat_tree', 'categories' and 'articles' is excluded 'cat_tree' => array(12), // tree with root 12 excluded 'categories' => array(100,111), // categories 100, 111 excluded 'articles' => array(33), // article 33 excluded 'artspecs' => array(2, 3), // array of article specifications => search only articles with these artspecs 'res_per_page' => 2, // results per page 'protected' => true); // => do not search articles or articles in categories which are offline or protected 'dontshowofflinearticles' => false); // => search offline articles or articles in categories which are offline

$search = new Search($options);

$cms_options = array("htmlhead", "html", "head", "text", "imgdescr", "link", "linkdescr"); search only in these cms-types $search->setCmsOptions($cms_options);

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

The search result structure has following form Array ( [20] => Array ( [CMS_HTML] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [keyword] => Array ( [0] => content [1] => contenido [2] => wwwcontenidoorg ) [search] => Array ( [0] => con [1] => con [2] => con ) [occurence] => Array ( [0] => 1 [1] => 5 [2] => 1 ) [similarity] => 60 ) )

The keys of the array are the article ID's found by search.

Searching 'con' matches keywords 'content', 'contenido' and 'wwwcontenidoorg' in article with ID 20 in content type CMS_HTML[1]. The search term occurs 7 times. The maximum similarity between searchterm and matching keyword is 60%.

with $oSearchResults = new cSearchResult($search_result, 10); one can rank and display the results

version 1.0.1
author Willi Man
copyright four for business AG

 Methods

Constructor

__construct(array $options, \cDb $db) : void
deprecated [2012-07-24] class was renamed to cSearch

Parameters

$options

array

$options['db'] 'regexp' => DB search with REGEXP; 'like' => DB search with LIKE; 'exact' => exact match; $options['combine'] 'and', 'or' Combination of search words with AND, OR $options['exclude'] 'true' => searchrange specified in 'cat_tree', 'categories' and 'articles' is excluded; 'false' => searchrange specified in 'cat_tree', 'categories' and 'articles' is included $options['cat_tree'] e.g. array(8) => The complete tree with root 8 is in/excluded from search $options['categories'] e.g. array(10, 12) => Categories 10, 12 in/excluded $options['articles'] e.g. array(23) => Article 33 in/excluded $options['artspecs'] => e.g. array(2, 3) => search only articles with certain article specifications $options['protected'] 'true' => do not search articles which are offline (locked) or articles in catgeories which are offline (protected) $options['dontshowofflinearticles'] 'false' => search offline articles or articles in categories which are offline $options['searchable_articles'] array of article ID's which should be searchable

$db

\cDb

Optional database instance

Add all article specifications matching name of article specification (client dependent but language independent)

addArticleSpecificationsByName(string $sArtSpecName) : void
Inherited
inherited_from \cSearch::addArticleSpecificationsByName()

Parameters

$sArtSpecName

string

Fetch all article specifications which are online,

getArticleSpecifications() : array
Inherited
inherited_from \cSearch::getArticleSpecifications()

Returns

arrayArray of article specification Ids

Returns list of searchable article ids.

getSearchableArticles(array $search_range) : array
Inherited
inherited_from \cSearch::getSearchableArticles()

Parameters

$search_range

array

Returns

arrayArticles in specified search range

Returns the category tree array.

getSubTree(int $cat_start) : array
Inherited
inherited_from \cSearch::getSubTree()

Parameters

$cat_start

int

Root of a category tree

Returns

arrayCategory Tree

indexed fulltext search

searchIndex(string $searchwords, string $searchwords_exclude) : void
Inherited
inherited_from \cSearch::searchIndex()

Parameters

$searchwords

string

The search words

$searchwords_exclude

string

The words, which should be excluded from search

Set article specification

setArticleSpecification(int $iArtspecID) : void
Inherited
inherited_from \cSearch::setArticleSpecification()

Parameters

$iArtspecID

int

setCmsOptions()

setCmsOptions($cms_options) : void
Inherited
inherited_from \cSearch::setCmsOptions()

Parameters

$cms_options

The cms-types (htmlhead, html, ...) which should explicitly be searched

Setter for debug

setDebug(bool $bDebug) 
Inherited
inherited_from \cSearchBaseAbstract::setDebug()
inherited_from \cSearch::setDebug()

Parameters

$bDebug

bool

stripWords()

stripWords($searchwords) : Array
Inherited
inherited_from \cSearch::stripWords()

Parameters

$searchwords

The search-words

Returns

Arrayof stripped search-words

Main debug function, prints dumps parameter if debugging is enabled

_debug(string $msg, mixed $var) 
Inherited
inherited_from \cSearchBaseAbstract::_debug()
inherited_from \cSearch::_debug()

Parameters

$msg

string

Some text

$var

mixed

The variable to dump

 Properties

 

$_articleSpecs : array
Inherited
inherited_from \cSearch::$$_articleSpecs
 

$_cmsType : array
Inherited
inherited_from \cSearch::$$_cmsType
 

$_cmsTypeSuffix : array
Inherited
inherited_from \cSearch::$$_cmsTypeSuffix
 

$_dontshowofflinearticles : boolean
Inherited
inherited_from \cSearch::$$_dontshowofflinearticles
 

$_exclude : boolean
Inherited
inherited_from \cSearch::$$_exclude
 

$_index : object
Inherited
inherited_from \cSearch::$$_index
 

$_protected : boolean
Inherited
inherited_from \cSearch::$$_protected
 

$_searchCombination : string
Inherited
inherited_from \cSearch::$$_searchCombination
 

$_searchOption : string
Inherited
inherited_from \cSearch::$$_searchOption
 

$_searchResult : array
Inherited

..

inherited_from \cSearch::$$_searchResult
 

$_searchWords : array
Inherited
inherited_from \cSearch::$$_searchWords
 

$_searchWordsExclude : array
Inherited
inherited_from \cSearch::$$_searchWordsExclude
 

$_searchableArts : array
Inherited
inherited_from \cSearch::$$_searchableArts
 

$bDebug : bool
Inherited
inherited_from \cSearchBaseAbstract::$$bDebug
inherited_from \cSearch::$$bDebug
 

$cfg : array
Inherited
inherited_from \cSearchBaseAbstract::$$cfg
inherited_from \cSearch::$$cfg
 

$client : int
Inherited
inherited_from \cSearchBaseAbstract::$$client
inherited_from \cSearch::$$client
 

$lang : int
Inherited
inherited_from \cSearchBaseAbstract::$$lang
inherited_from \cSearch::$$lang
 

$oDB : \cDb
Inherited
inherited_from \cSearchBaseAbstract::$$oDB
inherited_from \cSearch::$$oDB