Changes between Version 16 and Version 17 of adeiSEARCH
- Timestamp:
- 09/14/09 04:15:24 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
adeiSEARCH
v16 v17 43 43 The ''Search'' function of search engine may implement the search in arbitrary way. However, there is a standard procedure defined for search of textual data. It intended to standardize handling of search modifiers and simplify coding of new search engines for many standard cases. 44 44 The default implementation of engine ''Search'' function is using following procedure: 45 * '' GetList'' function is called to get complete associative list of available elements. In this list the key is an element identificator and value contains the presented above associative array describing the item. Besides the described standard properties, this array should contain45 * ''!GetList'' function is called to get complete associative list of available elements. In this list the key is an element identificator and value contains the presented above associative array describing the item. Besides the described standard properties, this array should contain 46 46 Of course, the ''rating'' and ''certain'' fields are not set yet. So, we have the following list of properties: 47 47 * ''title'' - title 51 51 * ''name'' - record short name (used for matching) 52 52 * arbitrary number of other properties used by custom matching functions 53 * Each item of the received string is matched against search terms using '' CheckString'' function. This function returns the match rating (''0'' means there is no match)53 * Each item of the received string is matched against search terms using ''!CheckString'' function. This function returns the match rating (''0'' means there is no match) 54 54 * The items for which the non-zero rating is returned are checked against filters and added to the search results 55 * Finally, the duplicating results are filtered using '' Accept'' function of ''SEARCHResults'' object. The comparisons between results are carried out using compare function returned by ''GetCmpFunction'' function of search engine. The default function just compares ''title'' members of the associative arrays describing compared items.55 * Finally, the duplicating results are filtered using ''!Accept'' function of ''!SEARCHResults'' object. The comparisons between results are carried out using compare function returned by ''!GetCmpFunction'' function of search engine. The default function just compares ''title'' members of the associative arrays describing compared items. 56 56 57 The default '' CheckString'' function is working in following way:58 * The search string is split in phrases and for each phrase '' CheckPhrase'' function is called (see [wiki:adeiSEARCH/String] for splitting algorithm)59 * Depending on the used module, the '' CheckPhrase'' function is expected to construct from the associative array a string value to match against search terms. The default behavior is to use ''name'' member of associative array. If the ''name'' member is empty or non-existing, the match fails.60 * The constructed string value is passed to the '' CheckTitlePhrase'' function.61 * '' CheckTitlePhrase'' function checks if passed string is fitting to the current search phrase and returns the rating.57 The default ''!CheckString'' function is working in following way: 58 * The search string is split in phrases and for each phrase ''!CheckPhrase'' function is called (see [wiki:adeiSEARCH/String] for splitting algorithm) 59 * Depending on the used module, the ''!CheckPhrase'' function is expected to construct from the associative array a string value to match against search terms. The default behavior is to use ''name'' member of associative array. If the ''name'' member is empty or non-existing, the match fails. 60 * The constructed string value is passed to the ''!CheckTitlePhrase'' function. 61 * ''!CheckTitlePhrase'' function checks if passed string is fitting to the current search phrase and returns the rating. 62 62 * Finally the rating computed for all search phrases are reconciled in overall rating using rules described in the [wiki:adeiSEARCH/String] 63 63 72 72 * The class implementing ''!SEARCHEngine'' interface and extending ''!SEARCHEngine'' base class should be implemented 73 73 * This class should provide a list of supported modules in the ''modules'' member of class. It is associative array where the key is module id and the value is module title. 74 * It should define either custom ''Search'' function or provide '' GetList'' function to be used in conjunction with the default approach described above.74 * It should define either custom ''Search'' function or provide ''!GetList'' function to be used in conjunction with the default approach described above. 75 75 * The implemented class should be stored under ''classes/search'' directory (the file name should be lower-cased class name with ''.php'' extension). 76 76 * The search engine should be enabled in the configuration. A new element should be appended into the $SEARCH_ENGINE associative array. The key is a class name and the value is default initialization parameters. 77 77 78 78 === Standard Engine === 79 '' GetList'' function should return an array containing a descriptions of all all available items (through which we would search). This description is an associative array described in sections above. It should contain the following members:79 ''!GetList'' function should return an array containing a descriptions of all all available items (through which we would search). This description is an associative array described in sections above. It should contain the following members: 80 80 * ''title'' - the title used to describe record in the search results 81 81 * ''description'' - the longer description of the record, HTML content is allowed 83 83 * ''name'' or arbitrary number of other properties used by the search engine for record matching 84 84 85 For example, the following array could be returned by the '' GetList'' function:85 For example, the following array could be returned by the ''!GetList'' function: 86 86 {{{ 87 87 array( 98 98 }}} 99 99 100 Of course, all other functions described in the ''Default Implementation'' section could be overridden as well. For example, if the engine is intended to support more than one search module, it needs to override '' CheckPhrase'' function. The default implementation constructs the match string just by taking ''name'' member of associative array. This string is, then, matched against search phrases. However, if multiple modules are used, for each module the algorithm for construction of match string should be specified. The ''CheckPhrase'' function in this case should construct a match string depending on the search module specified and pass it to the default ''CheckTitlePhrase'' function (or perform string matching by itself).100 Of course, all other functions described in the ''Default Implementation'' section could be overridden as well. For example, if the engine is intended to support more than one search module, it needs to override ''!CheckPhrase'' function. The default implementation constructs the match string just by taking ''name'' member of associative array. This string is, then, matched against search phrases. However, if multiple modules are used, for each module the algorithm for construction of match string should be specified. The ''!CheckPhrase'' function in this case should construct a match string depending on the search module specified and pass it to the default ''!CheckTitlePhrase'' function (or perform string matching by itself). 101 101 102 102 === Custom Engine === 103 The custom search engine needs to provide '' Search'' function. It should create the ''SEARCHResults'' object and fill it with results using ''Append'' function call. Then return the object or ''false'' if nothing is found.103 The custom search engine needs to provide ''!Search'' function. It should create the ''!SEARCHResults'' object and fill it with results using ''!Append'' function call. Then return the object or ''false'' if nothing is found. 104 104 Just a simple example: 105 105 {{{ 119 119 }}} 120 120 121 The special search engines intended to return custom XHTML content should use following approach instead (the XHTML strings are passed to the '' Append'' function instead of the associative arrays describing found items):121 The special search engines intended to return custom XHTML content should use following approach instead (the XHTML strings are passed to the ''!Append'' function instead of the associative arrays describing found items): 122 122 {{{ 123 123 $result = new SEARCHResults(NULL, $this, $module, ""); 134 134 }}} 135 135 136 If such filter is found, the '' INTERVALSearchFilter'' object (defined in the ''classes/search/intervalfilter.php'') is constructed. This object will get the filter value (''June 2005'') as a single parameter to its constructor. And it should implement a single function: ''FilterResult'' which should return ''true'' if the current record should be filtered out or ''false'' otherwise. The ''FilterResult'' receives two parameters:136 If such filter is found, the ''!INTERVALSearchFilter'' object (defined in the ''classes/search/intervalfilter.php'') is constructed. This object will get the filter value (''June 2005'') as a single parameter to its constructor. And it should implement a single function: ''!FilterResult'' which should return ''true'' if the current record should be filtered out or ''false'' otherwise. The ''!FilterResult'' receives two parameters: 137 137 * associative array with associative array describing the current item 138 138 * current rating of match 139 Both these parameters can be altered by '' FilterResult'' function.139 Both these parameters can be altered by ''!FilterResult'' function. 140 140 141 '''Example'''. Lets consider standard ''item'' search used in conjunction with ''interval'' filter. The search will provide multiple records describing found item (i.e. the associative array with information will contain standard properties: ''db_server'', ''db_name'', ''db_group'', and ''db_mask''). The ''interval'' filter is intended to limit the display interval. Therefore, when the '' FilterResult'' function is called, it will add the ''window'' property to the associative array limiting display window to ''June 2005''.141 '''Example'''. Lets consider standard ''item'' search used in conjunction with ''interval'' filter. The search will provide multiple records describing found item (i.e. the associative array with information will contain standard properties: ''db_server'', ''db_name'', ''db_group'', and ''db_mask''). The ''interval'' filter is intended to limit the display interval. Therefore, when the ''!FilterResult'' function is called, it will add the ''window'' property to the associative array limiting display window to ''June 2005''. 142 142 143 If multiple filters are specified they are executed sequentially until any filter will not reject the current item by returning ''true'' from '' FilterResult'' function.143 If multiple filters are specified they are executed sequentially until any filter will not reject the current item by returning ''true'' from ''!FilterResult'' function. 144 144 145 145 To implement a new filter it is necessary: 146 146 * Choose a not used name, for example: ''site'' 147 * Implement '' SITESearchFilter'' class extending ''BASESearchFilter'' (site is capitalized for class name)148 * Implement '' FilterResult(&$info, &$rating)'' function which returns ''true'' if the value should be filtered out or ''false'' otherwise. The filter value is accessible using ''$this->value''.147 * Implement ''!SITESearchFilter'' class extending ''!BASESearchFilter'' (site is capitalized for class name) 148 * Implement ''!FilterResult(&$info, &$rating)'' function which returns ''true'' if the value should be filtered out or ''false'' otherwise. The filter value is accessible using ''$this->value''. 149 149 * Place the implemented class in the ''classes/search/sitefilter.php'' (the lowercase filter name is used for the file name) 150 150