<commit_before>JayPS Search
======

A very simple search engine for Novius OS, based on Behaviours.

Licensed under [MIT License](http://opensource.org/licenses/MIT)

Current version: 1.1

**Get started**

* Configure which models will be searchable in your bootstrap.php (see below).
 For examples, see [JayPS Search Test](https://github.com/jay3/jayps_search_test)
* Add new items or save existing ones
* Start searching using find('all', array('where' => array(array('keywords', 'keyword1 keyword2'))))

**Example with Nos\Page and Nos\Monkey**
[Nos\Monkey](https://github.com/novius-os/noviusos_monkey)

Configure which models will be searchable for example in your bootstrap.php:

    \Event::register_function('config|jayps_search::config', function(&$config) {
        $config['observed_models']['noviusos_monkey::model/monkey'] = array(
            'primary_key' => 'monk_id',
            'config_behaviour' => array(
                'fields' => array('monk_name', 'monk_summary', 'wysiwygs->content'),
            ),
        );

        $config['observed_models']['noviusos_page::model/page'] = array(
            'primary_key' => 'page_id',
            'config_behaviour' => array(
                'fields' => array('page_title', 'wysiwygs->content', 'page_meta_title', 'page_meta_description', 'page_meta_keywords'),
            ),
        );

        $config['observed_models']['noviusos_news::model/post'] = array(
            'primary_key' => 'post_id',
            'config_behaviour' => array(
                'fields' => array('post_title', 'wysiwygs->content'),
            ),
        );
    });

    \JayPS\Search\Orm_Behaviour_Searchable::init();
    \Event::register_function('front.start', function() {
        // add models you want to use in your search and that are used in your template before your search enhancer
        // for example: noviusos_page::model/page

        //\JayPS\Search\Orm_Behaviour_Searchable::init_relations('noviusos_page::model/page');
        //\JayPS\Search\Orm_Behaviour_Searchable::init_relations('noviusos_news::model/post');

        \JayPS\Search\Orm_Behaviour_Searchable::init_relations();
    });

The config of the behaviour and the app can define score improvement as follow :
        $config['observed_models']['noviusos_monkey::model/monkey'] = array(
            'primary_key' => 'monk_id',
            'config_behaviour' => array(
                'fields' => array(
                    'monk_name', // as this is the title, general config already defines a boost
                    'monk_summary' => 1, //
                    'wysiwygs->content' => array(
                        'boost' => 0, // changes nothing, default value is 0
                        'is_html' => true // will remove html markup.
                    )
                ),
            ),
        );
        $config['observed_models']['noviusos_news::model/post'] = array(
            'primary_key' => 'post_id',
            'config_behaviour' => array(
                'fields' => array(
                    'post_title' => 2, // override general boost
                    'wysiwygs->content' => array(
                        'boost' => 1 // gives a score for all words in the content, regardless of their nature
                        'is_html' => array(
                            'h1' => 1 // provides another boost for words un h1 markup
                        )
                    )
                ),
            ),
        );



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

    \JayPS\Search\Orm_Behaviour_Searchable::init_relations();

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

    $news = \Nos\BlogNews\News\Model_Post::find('all', array(
        'where' => array(
            array('keywords', 'chimpa* monkey'),
            'post_published' => 1,
            'post_context'   => \Nos\Nos::main_controller()->getPage()->page_context,
        ),
        'rows_limit' => 10,
        'order_by'   => array('jayps_search_score', 'post_title'),
    ));

    $monkeys = \Nos\Monkey\Model_Monkey::find('all', array(
        'where' => array(
            array('keywords', 'chimpa* monkey'),
            'monk_published' => 1,
            'monk_context'   => \Nos\Nos::main_controller()->getPage()->page_context,
        ),
        'rows_limit' => 200,
        'order_by' => array('jayps_search_score', 'monk_name'),
    ));<commit_msg>Syntax highlighting<commit_after>JayPS Search
======

A very simple search engine for Novius OS, based on Behaviours.

Licensed under [MIT License](http://opensource.org/licenses/MIT)

Current version: 1.1

**Get started**

* Configure which models will be searchable in your bootstrap.php (see below).
 For examples, see [JayPS Search Test](https://github.com/jay3/jayps_search_test)
* Add new items or save existing ones
* Start searching using find('all', array('where' => array(array('keywords', 'keyword1 keyword2'))))

**Example with Nos\Page and Nos\Monkey**
[Nos\Monkey](https://github.com/novius-os/noviusos_monkey)

Configure which models will be searchable for example in your bootstrap.php:
```php
    \Event::register_function('config|jayps_search::config', function(&$config) {
        $config['observed_models']['noviusos_monkey::model/monkey'] = array(
            'primary_key' => 'monk_id',
            'config_behaviour' => array(
                'fields' => array('monk_name', 'monk_summary', 'wysiwygs->content'),
            ),
        );

        $config['observed_models']['noviusos_page::model/page'] = array(
            'primary_key' => 'page_id',
            'config_behaviour' => array(
                'fields' => array('page_title', 'wysiwygs->content', 'page_meta_title', 'page_meta_description', 'page_meta_keywords'),
            ),
        );

        $config['observed_models']['noviusos_news::model/post'] = array(
            'primary_key' => 'post_id',
            'config_behaviour' => array(
                'fields' => array('post_title', 'wysiwygs->content'),
            ),
        );
    });

    \JayPS\Search\Orm_Behaviour_Searchable::init();
    \Event::register_function('front.start', function() {
        // add models you want to use in your search and that are used in your template before your search enhancer
        // for example: noviusos_page::model/page

        //\JayPS\Search\Orm_Behaviour_Searchable::init_relations('noviusos_page::model/page');
        //\JayPS\Search\Orm_Behaviour_Searchable::init_relations('noviusos_news::model/post');

        \JayPS\Search\Orm_Behaviour_Searchable::init_relations();
    });
```

The config of the behaviour and the app can define score improvement as follow :

```php
    $config['observed_models']['noviusos_monkey::model/monkey'] = array(
        'primary_key' => 'monk_id',
        'config_behaviour' => array(
            'fields' => array(
                'monk_name', // as this is the title, general config already defines a boost
                'monk_summary' => 1, //
                'wysiwygs->content' => array(
                    'boost' => 0, // changes nothing, default value is 0
                    'is_html' => true // will remove html markup.
                )
            ),
        ),
    );
    $config['observed_models']['noviusos_news::model/post'] = array(
        'primary_key' => 'post_id',
        'config_behaviour' => array(
            'fields' => array(
                'post_title' => 2, // override general boost
                'wysiwygs->content' => array(
                    'boost' => 1 // gives a score for all words in the content, regardless of their nature
                    'is_html' => array(
                        'h1' => 1 // provides another boost for words un h1 markup
                    )
                )
            ),
        ),
    );
```

To use the search with find(), simply provide an array of keywords. '*' acts as a joker at the end.
```php
    \JayPS\Search\Orm_Behaviour_Searchable::init_relations();

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

    $news = \Nos\BlogNews\News\Model_Post::find('all', array(
        'where' => array(
            array('keywords', 'chimpa* monkey'),
            'post_published' => 1,
            'post_context'   => \Nos\Nos::main_controller()->getPage()->page_context,
        ),
        'rows_limit' => 10,
        'order_by'   => array('jayps_search_score', 'post_title'),
    ));

    $monkeys = \Nos\Monkey\Model_Monkey::find('all', array(
        'where' => array(
            array('keywords', 'chimpa* monkey'),
            'monk_published' => 1,
            'monk_context'   => \Nos\Nos::main_controller()->getPage()->page_context,
        ),
        'rows_limit' => 200,
        'order_by' => array('jayps_search_score', 'monk_name'),
    ));
```
{'fraction_non_alphanumeric': 0.14742639271340818, 'fraction_numerical': 0.00487184918449481, 'mean_word_length': 2.330864197530864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 105, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '548706', 'n_tokens_mistral': 2947, 'n_tokens_neox': 2728, 'n_words': 600}