PHP code example of stanislav-web / phalcon-searcher

1. Go to this page and download the library: Download stanislav-web/phalcon-searcher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stanislav-web / phalcon-searcher example snippets


"    "stanislav-web/phalcon-searcher": "dev-master",
}

    $loader->registerNamespaces([
        'Searcher\Searcher' => 'path to src'
    ]);

    $this->di['searcher'] = function() {
        return new \Searcher\Searcher();
    };

 
    use \Searcher\Searcher;
     
    // create object instance
    $searcher = new Searcher();
    
    // Prepare models and fields to participate in search
    $searcher->setFields([
        '\Models\Auto'    =>    [
            'mark',
            'model'
        ],
        '\Models\Distributor'    =>    [
            'name',
            'description'
        ]
    ])
    ->setQuery('FerRari');
    
    $result = $searcher->run();

 
    use \Searcher\Searcher;
     
    // create object instance
    $searcher = new Searcher();
    
    // Prepare models and fields to participate in search
    $searcher->setFields([
        '\Models\Auto'    =>    [
            'mark',
            'model'
        ],
        '\Models\Distributor'    =>    [
            'name',
            'description'
        ]
    ])
    ->setMin(3)                                         //  minimum char to query
    ->setMax(15)                                        //  maximum char to query
    ->setExact(true)                                    //  strict mode search 
    ->setOrder(['\Models\Auto' => ['id' => 'DESC']])    //  ORDER BY \Models\Auto.id DESC
    ->setGroup(['\Models\Distributor' => ['id']])       //  GROUP BY \Models\Auto.id
    ->setThreshold(100)                                 //  LIMIT 100
    ->setQuery('FerRari');
    
    $result = $searcher->run();
    

 
    use \Searcher\Searcher;
     
    // create object instance
    $searcher = new Searcher();
    
    // Prepare models and fields to participate in search
    $searcher->setFields([
        '\Models\Auto'    =>    [
            'mark',
            'model'
        ],
        '\Models\Distributor'    =>    [
            'name',
            'description'
        ]
    ])
    ->setExact(true) // strict mode search 
    ->setOrder([
                    '\Models\Auto' => ['id' => 'DESC']
                    '\Models\Distributor' => ['description' =>  'ASC']
              ])                                                //  ORDER BY \Models\Auto.id DESC, \Models\Distributor.description ASC
    ->setGroup([
                '\Models\Auto' => ['id', 'mark']
                '\Models\Distributor' => ['id', 'description']
              ])                                                //  GROUP BY \Models\Auto.id, \Models\Auto.mark, \Models\Distributor.id, \Models\Distributor.description 
    
    ->setThreshold([0,100])                                     //    OFFSET 0, LIMIT 100
    ->setQuery('FerRari');
    
    $result = $searcher->run();
    

 
    use \Searcher\Searcher;
     
    // create object instance
    $searcher = new Searcher();
    
    // Prepare models and fields to participate in search
    $searcher->setFields([
        '\Models\Auto'    =>    [
            'mark',
            'model'
        ],
        '\Models\Distributor'    =>    [
            'name',
            'description'
        ]
    ])
    ->setQuery('FerRari');
    
    $result = $searcher->run('json'); // available array, serialize, json, Resultset as default
    
    // OR
    
    /**
     * @param $result 
     */
    $result = $searcher->run('array', function($result) {
        
        //... any modifiers 
        return $result;
             
    }); // available, array, serialize, json, Resultset as default


php build/phpunit.phar --configuration phpunit.xml.dist --coverage-text
python
php composer.phar update
php composer.phar install