ou Annuler
JayPS Search, a fulltext search engine based on behaviours
By JayPS , 25 November 2013


Months ago, I've started to write a search engine for Novius OS to easily index and query any models in your project.

After several beta versions, I've recently published a version 1.0. I'm now using it daily on many production websites, with several thousands of indexed objects.

License: MIT

Source code:

Everything works with a behaviour. All you have to do is to add it to the models you want to query.
When you save your objects, keywords are extracted from specified fields and saved in the database.
You can later query them using the find() method of the orm, and mix keywords search with others.


To use the search with find(), simply provide an array of keywords. '*' acts as a joker at the end.

$pages = NosPageModel_Page::find('all', array(
    'where' => array(
        array('keywords', 'chimpa* monkey'),
        'page_published' => 1,
        'page_context'   => NosNos::main_controller()->getPage()->page_context,
    'rows_limit' => 10,
    'order_by' => array('jayps_search_score', 'page_title'),


You can add the behaviour directly in your model file, or in your bootstrap.php using events. Your can possibility add an "indexation date" field in your database.

Event::register_function('config|jayps_search::config', function(&$config) {
    $config['observed_models']['noviusos_page::model/page'] = array(
        'primary_key' => 'page_id',
        'config_behaviour' => array(
            'fields' => array('page_title', 'wysiwygs->content'),
    $config['observed_models']['myapp::model/mymodel'] = array(
        'primary_key' => 'mode_id',
        'config_behaviour' => array(
            'fields' => array('mode_title', 'mode_description'),
            'field_date_indexation' => 'mode_date_indexation'

Event::register_function('front.start', function() {
    // init all relations

Index objects:

Object are automatically reindex when you save them (save() triggers the interval __index() method of the behaviour)

Your can reindex objects. Example:
    $pages = NosPageModel_Page::find('all', array(
        'limit' => 50,
    foreach ($pages as $page) {

I hope it can help you


2 users liked this article.