PHP code example of robotomize / fujes

1. Go to this page and download the library: Download robotomize/fujes 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/ */

    

robotomize / fujes example snippets




use robotomize\Fujes\SearchFactory;

/**
*
* I want to find some planes
*/
print SearchFactory::find(
    'http://api.travelpayouts.com/data/planes.json',
    'Tu'
)->fetchOne() . PHP_EOL;
print SearchFactory::find(
    'http://api.travelpayouts.com/data/planes.json',
    'Boing 7'
)->fetchOne() . PHP_EOL;
print SearchFactory::find(
    'http://api.travelpayouts.com/data/planes.json',
    'An24'
)->fetchOne() . PHP_EOL;



    /**
     * I want to find some airports
     */
    print SearchFactory::find(
            'http://api.travelpayouts.com/data/airports.json ',
            'Sheremetievo',
            1,
            false
        )->fetchOne()['name'] . PHP_EOL;
    print SearchFactory::find(
            'http://api.travelpayouts.com/data/airports.json ',
            'Domogedov',
            1,
            false
        )->fetchOne()['en'] . PHP_EOL;
    print SearchFactory::find(
            'http://api.travelpayouts.com/data/airports.json ',
            'Yugnosahalinsk',
            1,
            false
        )->fetchOne()['en'] . PHP_EOL;
    print SearchFactory::find(
            'http://api.travelpayouts.com/data/airports.json ',
            'Puklovo',
            1,
            false
        )->fetchOne()['en'] . PHP_EOL;



use robotomize\Fujes\SearchFacade;
use robotomize\Fujes\SearchFactory;
// With factory
print SearchFactory::createSearchEngine(
    '/path/to/jsonurl',
    'What are searching for string',
    1,
    true,
    false,
    1,  
    'master'
)->fetchOne() . PHP_EOL;  

print SearchFactory::createSearchEngine(
    '/path/to/jsonurl',
    'What are searching for string',
    1,
    true,
    true,
    1,  
    'master'
)->fetchFew(3) . PHP_EOL;



php -q src/example.php



use robotomize\Fujes\SearchFacade;
use robotomize\Fujes\SearchFactory;

/**
 * Helper options. Search into biographical-directory-footnotes.json.
 * Match string Christensen
 * Output encode to json
 */
$options = [
    'json_file_name' => __DIR__ . '/data/biographical-directory-footnotes.json',
    'search_string' => 'Christensen',
    'depth_into_array' => '1',
    'output_json' => true,
    'multiple_result' => false,
    'search_quality' => 1,
    'version' => 'dev'
];

$searchObject = new SearchFacade(
    $options['json_file_name'],
    $options['search_string'],
    $options['depth_into_array'],
    $options['output_json'],
    $options['multiple_result'],
    $options['search_quality'],
    $options['version']
);

print $searchObject->fetchOne();
/**
 * Output this
 *
 * {"item":"Donna Christian-Green, St. Croix ","note":"[5125:
 * Biographical information under Donna Marie Christian Christensen. ]",
 * "line":56939}
 */



/**
 * Get exception
 */
try {
    print $searchObject->fetchFew(3) . PHP_EOL;
} catch (\Exception $ex) {
    print $ex->getMessage() . PHP_EOL;
    /**
    * Output this exception
    * multipleResult flag off, use $this->setMultipleResult(true)
    * and call this function again
    */
}



$searchObject->setMultipleResult(true);

/**
 * And this work
 */
print $searchObject->fetchFew(3) . PHP_EOL;



/**
 * The following example, you can use the factory.
 */
print SearchFactory::createSearchEngine(
    __DIR__ . '/../src/data/cities.json',
    'vladvostk',
    2,
    false,
    false,
    1,
    'dev'
)->fetchOne()['name'] . PHP_EOL;

print SearchFactory::createSearchEngine(
    __DIR__ . '/../src/data/cities.json',
    'Mosco',
    1,
    true,
    false,
    1,
    'dev'
)->fetchOne() . PHP_EOL;



print SearchFactory::createSearchEngine(
        __DIR__ . '/data/biographical-directory-footnotes.json',
        'linkoln',
        1,
        true,
        true,
        1,
        'dev'
    )->fetchFew(6) . PHP_EOL;