Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
search Class Reference

Full text search tool (mysql DBMS) More...

Public Member Functions

 __construct ($table, $opts=null)
 Constructs a search instance.
 getSearchResults ($selected_fields, $required_clauses, $weight_clauses)
 Return the search results.
 makeQuery ($selected_fields, $required_clauses, $weight_clauses)
 Creation of the search query.

Private Member Functions

 clearSearchString ($search_string)
 Clear the search string.
 getKeywords ($search_string)
 Gets keywords from a search string.

Private Attributes

 $_registry
 the registry singleton instance
 $_table
 the database table

Detailed Description

Full text search tool (mysql DBMS)

This class is used to perform full text seraches optionally indicating different weights for different search fields.

In order to work correctly the database engine must have defined the following function which is a case insensitive replace function. here is the SQL code necessary to create the replace_ci function:

   DELIMITER $$
   DROP FUNCTION IF EXISTS `replace_ci`$$
   CREATE FUNCTION `replace_ci` ( str TEXT,needle CHAR(255),str_rep CHAR(255)) 
   RETURNS TEXT
   DETERMINISTIC
   BEGIN
   DECLARE return_str TEXT;
   SELECT replace(lower(str),lower(needle),str_rep) INTO return_str;
   RETURN return_str;
   END$$
   DELIMITER ;
Author:
abidibo abidi.nosp@m.bo@g.nosp@m.mail..nosp@m.com
Version:
0.99
Date:
2011-2012

Definition at line 39 of file search.class.php.


Constructor & Destructor Documentation

search::__construct ( table,
opts = null 
)

Constructs a search instance.

Parameters:
string$tabletable name
mixed$optsassociative array of options:
  • highlight_range: int default 120. Number of characters which surrounds search keyword in the search result
Returns:
void

Definition at line 60 of file search.class.php.

+ Here is the call graph for this function:


Member Function Documentation

search::clearSearchString ( search_string) [private]

Clear the search string.

Removes words with no meaning

Parameters:
string$search_stringsearch string
Returns:
the cleaned search string

Definition at line 76 of file search.class.php.

+ Here is the caller graph for this function:

search::getKeywords ( search_string) [private]

Gets keywords from a search string.

Parameters:
string$search_stringsearch string
Returns:
array keywords list

Definition at line 97 of file search.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

search::getSearchResults ( selected_fields,
required_clauses,
weight_clauses 
)

Return the search results.

The returned text is an array whose elements are associative arrays with the following keys:

  • relevance relevance of the result (due to field weights)
  • occurences keywords occurences
  • **<selected_field_name>** search result:
    if the selected field has the option 'highlight' returns the highlighted text (the first occurrence of a keyword surrounded by two highlight ranges) if found or an empty string.
    If the option highlight is false returns the content stored in the database.
Parameters:
array$selected_fieldsfields to select. Each array element may be the field name or an array:
  • highlight: whether to highlight search keywords in the result or not
  • field: the field name
array$required_clausesassociative array of required clauses in the form array('field_name'=>'field_clause')
'field_clause' may be directly the field value to search for or an associative array specifying the search type (inside, start, end or field) and the value:
  • inside: bool. Matches fields which contain value
  • start: bool. Matches fields which starts with value
  • end: bool. Matches fields which ends with value
  • field: bool. matches fields equal to value
  • value: mixed. field value
array$weight_clausesassociative array of weighted clauses in the form array('field_name'=>'field_clause')
'field_clause' is an associative array:
  • value: the string to search for (will be divided into keywords)
  • inside bool: Wheather to match also words which contains a keyword
  • weight int: field weight
Returns:
array of search results

Definition at line 214 of file search.class.php.

+ Here is the call graph for this function:

search::makeQuery ( selected_fields,
required_clauses,
weight_clauses 
)

Creation of the search query.

Parameters:
array$selected_fieldsfields to select. Each array element may be the field name or an array with the field name as value of the key 'field'.
array$required_clausesassociative array of required clauses in the form array('field_name'=>'field_clause')
'field_clause' may be directly the field value to search for or an associative array specifying the search type (inside, start, end or field) and the value:
  • inside: bool. Matches fields which contain value
  • start: bool. Matches fields which starts with value
  • end: bool. Matches fields which ends with value
  • field: bool. matches fields equal to value
  • value: mixed. field value
array$weight_clausesassociative array of weighted clauses in the form array('field_name'=>'field_clause')
'field_clause' is an associative array:
  • value: the string to search for (will be divided into keywords)
  • inside bool: Wheather to match also words which contains a keyword
  • weight int: field weight
Returns:
the search query string

Definition at line 128 of file search.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


Field Documentation

search::$_registry [private]

the registry singleton instance

Definition at line 44 of file search.class.php.

search::$_table [private]

the database table

Definition at line 49 of file search.class.php.


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