PHP code example of jarir-ahmed / uncensored-search

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

    

jarir-ahmed / uncensored-search example snippets


use JarirAhmed\UncensoredSearch\UncensoredSearch;

// Load whatever keys you have — only configured providers are used.
$search = UncensoredSearch::fromKeys([
    'serper' => 'xxxx',
    'tavily' => 'tvly-xxxx',
    // 'searchapi' => '...', 'scavio' => '...', 'firecrawl' => '...', 'scrapingbee' => '...',
]);

$results = $search->search('open source vector database');

echo $results->provider();   // "serper" (whichever one answered)
foreach ($results as $hit) {
    echo $hit->title() . "\n";
    echo $hit->url() . "\n";
    echo $hit->snippet() . "\n\n";
}

UncensoredSearch::fromKeys([...]);                 // inline array
UncensoredSearch::fromFile('uncensored_keys.txt'); // KEY=value / .env style file
UncensoredSearch::fromEnv();                        // SERPER_API_KEY, TAVILY_API_KEY, ...

// FAILOVER (default) — try providers in order, first with results wins.
// Cheapest: one provider's quota per query.
$set = $search->search('php 8.4 release date');

// AGGREGATE — query every provider, merge, dedupe by URL. Max coverage,
// spends multiple quotas per call.
$set = $search->searchAll('php 8.4 release date');
echo implode('+', $set->providers()); // e.g. "serper+tavily+firecrawl"

use JarirAhmed\UncensoredSearch\Query;

$q = Query::create('climate data')
    ->withLimit(20)
    ->withSafeSearch(true)   // re-enable filtering (providers that support it)
    ->withCountry('us')
    ->withLanguage('en');

$search->search($q);

$set = $search->search('something');

$set->count();        // int  (ResultSet is Countable + iterable)
$set->isEmpty();      // bool
$set->first();        // ?Result
$set->provider();     // ?string — who served it
$set->providers();    // string[] — all contributors (aggregate mode)
$set->elapsedMs();    // float
$set->errors();       // array<provider,message> — why others were skipped
$set->toArray();      // array of plain rows

foreach ($set as $r) {
    $r->title(); $r->url(); $r->snippet();
    $r->source();   // provider name
    $r->position(); // ?int  rank
    $r->score();    // ?float (Tavily)
    $r->raw();      // untouched provider row
}

// Restrict and reorder; tries tavily first, then serper.
$search->only(['tavily', 'serper'])->search('...');
bash
php examples/cli.php "open source vector database"
php examples/cli.php --all --limit=5 "best php testing framework"
php examples/cli.php --safe "kids science fair ideas"
php examples/cli.php --keys=/path/to/keys.txt "php 8.4"