PHP code example of saosangmo / php-search

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

    

saosangmo / php-search example snippets


use saosangmo\Search\Engine;

$engine = new Engine();

$doc = [
    "id" => 1,
    "type" => "product",
    "name" => "this is my first blog post !",
    "description" => "I am very happy to post this first post in my blog !",
    "categories" => [
        "party",
        "misc."
    ],
    "date" => "2018/01/01"
];
$engine->update($doc);
$doc = [
    "id" => 2,
    "type" => "example-post",
    "title" => "This is the second blog post",
    "content" => "a second one for fun",
    "date" => "2018/01/05",
    "categories" => [
        "misc."
    ],
    "comments" => [
        [
            "author" => "someone",
            "date" => "2018/01/05",
            "message" => "Another one ?!"
        ]
    ]
];
$engine->update($doc);

$response = $engine->search('second post');
var_dump($response);

$response = $engine->search('post');
var_dump($response);



use saosangmo\Search\AdminPanel;

// include the composer autoload file, modify the path if needed
orized');

// instantiate the panel and then run it
$admin = new AdminPanel();
echo $admin->run();