PHP code example of sierratecnologia / finder
1. Go to this page and download the library: Download sierratecnologia/finder 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/ */
sierratecnologia / finder example snippets
return [
// Configurações do Finder
'default_driver' => env('FINDER_DRIVER', 'eloquent'),
'drivers' => [
'eloquent' => [
'enabled' => true,
],
'filesystem' => [
'enabled' => true,
'paths' => [
storage_path('app'),
],
],
],
'spider' => [
'max_depth' => 5,
'timeout' => 30,
'user_agent' => 'SierraTecnologia-Finder/1.0',
],
];
"autoload": {
"psr-4": {
"Finder\\": "src/"
}
}
use Finder\Services\FinderService;
$finder = app(FinderService::class);
use Finder\Pipelines\SearchPipeline;
$results = app(SearchPipeline::class)
->pipe(new FilterPipe())
->pipe(new RankPipe())
->process($query);
use Finder\Services\Finders\PersonService;
$personFinder = app(PersonService::class);
// Buscar pessoas com filtros
$results = $personFinder->search([
'name' => 'João',
'city' => 'Rio de Janeiro',
'age_min' => 18,
'age_max' => 65,
]);
use Finder\Spider\Directory;
$spider = new Directory();
$spider->crawl('/path/to/directory', [
'recursive' => true,
'extensions' => ['php', 'js', 'json'],
'max_depth' => 5,
]);
use Finder\Models\Computer\ComputerFile;
// Indexar arquivo
ComputerFile::create([
'path' => '/path/to/file.pdf',
'size' => filesize('/path/to/file.pdf'),
'mime_type' => 'application/pdf',
'hash' => hash_file('sha256', '/path/to/file.pdf'),
]);
use Finder\Http\Actions\PostGetByIdAction;
Route::get('/api/posts/{id}', PostGetByIdAction::class);
use Finder\Entities\FileEntity;
use Finder\Entities\DirectoryEntity;
$file = new FileEntity('/path/to/file.txt');
echo $file->getSize();
echo $file->getMimeType();
echo $file->getHash();
$directory = new DirectoryEntity('/path/to/directory');
foreach ($directory->getFiles() as $file) {
echo $file->getPath();
}
use Finder\Services\FinderService;
class ProductController extends Controller
{
protected $finder;
public function __construct(FinderService $config)
{
$this->finder = $finder;
}
public function search(Request $request)
{
// Buscar produtos com filtros dinâmicos
$products = Product::query()
->when($request->category, function($query, $category) {
return $query->where('category_id', $category);
})
->when($request->min_price, function($query, $minPrice) {
return $query->where('price', '>=', $minPrice);
})
->when($request->max_price, function($query, $maxPrice) {
return $query->where('price', '<=', $maxPrice);
})
->when($request->search, function($query, $search) {
return $query->where('name', 'like', "%{$search}%")
->orWhere('description', 'like', "%{$search}%");
})
->orderBy('created_at', 'desc')
->paginate(20);
return response()->json($products);
}
}
use Finder\Spider\SpiderLinuxCommand;
use Finder\Contracts\Spider\Spider;
class CustomSpider implements Spider
{
public function crawl($target, array $options = [])
{
$files = [];
// Lógica personalizada de rastreamento
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($target)
);
foreach ($iterator as $file) {
if ($file->isFile()) {
$files[] = [
'path' => $file->getPathname(),
'size' => $file->getSize(),
'modified' => $file->getMTime(),
];
}
}
return $files;
}
}
use Illuminate\Support\Facades\Cache;
use Finder\Services\Finders\PersonService;
class PersonSearchService
{
public function search($filters)
{
$cacheKey = 'person_search_' . md5(json_encode($filters));
return Cache::remember($cacheKey, 3600, function() use ($filters) {
$personFinder = app(PersonService::class);
return $personFinder->search($filters);
});
}
}
use Illuminate\Support\Facades\Cache;
$results = Cache::tags(['finder', 'products'])
->remember('products_search_' . $query, 1800, function() use ($query) {
return Product::search($query)->get();
});
$results = Product::with(['category', 'images', 'tags'])
->whereIn('id', $productIds)
->get();
Product::chunk(1000, function($products) {
foreach ($products as $product) {
// Processar em lotes
$this->indexProduct($product);
}
});
use Stalker\Services\TrackerService;
$tracker = app(TrackerService::class);
$tracker->track('finder.search', [
'query' => $searchQuery,
'results' => count($results),
]);
use Casa\Services\ConfigService;
$config = app(ConfigService::class);
$finderSettings = $config->get('modules.finder');
use Operador\Jobs\IndexFilesJob;
dispatch(new IndexFilesJob($directory));
use MediaManager\Services\FileService;
$fileService = app(FileService::class);
$file = $fileService->upload($request->file('document'));
namespace Tests\Feature;
use Tests\TestCase;
use Finder\Services\FinderService;
class FinderTest extends TestCase
{
public function test_can_search_products()
{
$finder = app(FinderService::class);
$results = $finder->search('test product');
$this->assertNotEmpty($results);
}
}
namespace App\Finders;
use Finder\Services\Finders\FinderAbstractService;
class ElasticsearchFinder extends FinderAbstractService
{
protected $client;
public function __construct()
{
$this->client = app('elasticsearch');
}
public function search(array $params)
{
return $this->client->search([
'index' => 'products',
'body' => [
'query' => [
'match' => [
'name' => $params['query'] ?? ''
]
]
]
]);
}
}
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind('finder.elasticsearch', function() {
return new \App\Finders\ElasticsearchFinder();
});
}
namespace App\Indexers;
class ProductIndexer
{
public function index($product)
{
return [
'id' => $product->id,
'name' => $product->name,
'description' => strip_tags($product->description),
'price' => $product->price,
'category' => $product->category->name,
'tags' => $product->tags->pluck('name')->toArray(),
'indexed_at' => now(),
];
}
}
namespace App\Spider\Extensions;
use Finder\Contracts\Spider\ExtensionManager;
class VideoExtension implements ExtensionManager
{
public function supports($file)
{
return in_array($file->getExtension(), ['mp4', 'avi', 'mov']);
}
public function process($file)
{
// Extrair metadata de vídeo
return [
'duration' => $this->getDuration($file),
'resolution' => $this->getResolution($file),
'codec' => $this->getCodec($file),
];
}
}
// Bom
public function __construct(Spider $spider) {}
// Evite
public function __construct(SpiderLinuxCommand $spider) {}
namespace App\Finders\V2;
class CustomFinder extends FinderAbstractService
{
const VERSION = '2.0.0';
}
/**
* Custom finder implementation for Algolia
*
* @version 1.0.0
* @author Your Team
* @see https://docs.yourcompany.com/finders/algolia
*/
class AlgoliaFinder extends FinderAbstractService
{
// ...
}
use Finder\Services\FinderService;
use Illuminate\Support\Facades\Cache;
class ProductSearchService
{
public function search($query, $filters = [])
{
$cacheKey = 'search_' . md5($query . serialize($filters));
return Cache::tags(['products', 'search'])
->remember($cacheKey, 3600, function() use ($query, $filters) {
return Product::search($query)
->when($filters['category'] ?? null, function($q, $cat) {
return $q->where('category_id', $cat);
})
->when($filters['price_range'] ?? null, function($q, $range) {
return $q->whereBetween('price', $range);
})
->paginate(50);
});
}
}
use Finder\Spider\Directory;
use Finder\Models\Computer\ComputerFile;
class DocumentIndexer
{
public function indexDirectory($path)
{
$spider = new Directory();
$files = $spider->crawl($path, [
'extensions' => ['pdf', 'doc', 'docx', 'txt'],
'recursive' => true,
]);
foreach ($files as $file) {
ComputerFile::updateOrCreate(
['path' => $file['path']],
[
'size' => $file['size'],
'hash' => hash_file('sha256', $file['path']),
'mime_type' => mime_content_type($file['path']),
'indexed_at' => now(),
]
);
}
}
}
use Finder\Http\Actions\PostPaginateAction;
class NewsAggregator
{
public function getLatestNews($sources = [])
{
return Post::query()
->when($sources, function($q, $sources) {
return $q->whereIn('source_id', $sources);
})
->with(['author', 'tags', 'media'])
->where('published_at', '<=', now())
->where('status', 'published')
->orderBy('published_at', 'desc')
->paginate(20);
}
}
bash
# Publicar configuração
php artisan vendor:publish --tag=sitec-config
# Publicar views (opcional)
php artisan vendor:publish --tag=sitec-views
# Publicar traduções (opcional)
php artisan vendor:publish --tag=sitec-lang
bash
# Rastrear diretório de arquivos
php artisan finder:spider:directory /path/to/directory
bash
# Preparar fotos para importação
php artisan finder:prepare:photos
# Exportar dados em Excel
php artisan finder:prepare:excel
# Exportar dados gerais
php artisan finder:prepare:export
bash
# Sincronizar tokens
php artisan finder:sync:tokens
# Sincronizar pessoas
php artisan finder:sync:persons
bash
# Verificar integridade de storage
php artisan finder:verify:storage
# Verificar dados sociais
php artisan finder:verify:social