Search Class
MeNeedz's robust Search Class supports the following features:
- Performing search based on config
- Scrolling through search results
- Caching of search results
- Automatically updating cached search results after search has reached a certain age
Setting Search Preferences
There are 2 different preferences available to tailor how your search should work. You can either set them manually as described here, or automatically via preferences stored in your config file, described below:
Preferences are set by passing an array of preference values to the search init function. Here is an example of how you might set some preferences:
$config['max_age'] = 300;
$this->search->init($config);
Note: All preferences have default values that will be used if you do not set them.
Setting Search Preferences in a Config File
If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the search.php, add the $config array in that file. Then save the file at config/search.php and it will be used automatically. You will NOT need to use the $this->search->init() function if you save your preferences in a config file.
Search Preferences
The following is a list of all the preferences that can be set when performing a search.
| Preference | Default Value | Options | Description |
|---|---|---|---|
| max_age | 300 | Numeric value | The maximum age of a search in seconds. |
| db_config | See below | Array of settings for database usage | An array with all settings that are needed to use the database to cache the search results. |
| search_config | Empty array | Array of configs for different searches (See below) | An array with all settings that are needed to perform a search. |
db_config
A more detailed explanation on the database preferences neededsearch_config
A more detailed explanation on the search config neededSetting up the database
Search Function Reference
$this->search->perform()
Perform a search:
$search = $this->search->perform('test_search', 0, 25);
1. parameter: name of the search as set in your config2. parameter: offset
3. parameter: row count
Returns an array with the search id, the total number of results and the ids according to your offset, row count and the where parameters used to perform the search on succes and FALSE on failure.
$this->search->scroll()
Scroll search results:
$this->search->scroll(8, 0, 25);
1. parameter: id of the searc2. parameter: offset
3. parameter: row count
Returns an array with the search id, the total number of results and the ids according to your offset, row count and the where parameters used to perform the search on succes and FALSE on failure.