Class cSearch
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
- cSearchBaseAbstract
- cSearch
Copyright: four for business AG <www.4fb.de>
License: http://www.contenido.org/license/LIZENZ.txt
Author: Willi Man
Located at classes/search/class.search.php
public
|
|
public
boolean
|
|
public
|
|
public
array
|
|
public
array
|
|
public
array
|
|
public
array
|
|
public
|
|
public
boolean
|
#
addArticleSpecificationsByName( string $sArtSpecName )
Add all article specifications matching name of article specification (client dependent but language independent) |
_debug()
|
protected
object
|
$_index
Instance of class Index |
|
protected
array
|
$_searchWords
the search words |
#
array()
|
protected
array
|
$_searchWordsExclude
the words which should be excluded from search |
#
array()
|
protected
string
|
$_searchOption
type of db search like => 'sql like', regexp => 'sql regexp' |
|
protected
string
|
$_searchCombination
logical combination of searchwords (and, or) |
|
protected
array
|
$_searchableArts
array of searchable articles |
#
array()
|
protected
array
|
$_articleSpecs
article specifications |
#
array()
|
protected
boolean
|
$_protected
If $protected = true => do not search articles which are offline or articles in catgeories which are offline (protected) unless the user has access to them |
|
protected
boolean
|
$_dontshowofflinearticles
If $dontshowofflinearticles = false => search offline articles or articles in categories which are offline |
|
protected
boolean
|
$_exclude
If $exclude = true => the specified search range is excluded from search, otherwise included |
|
protected
array
|
$_searchResult
Array of article id's with information about cms-types, occurence of keyword/searchword, similarity . |
#
array()
|
$cfg,
$client,
$lang,
$oDB
|