PHP code example of eliasfernandez / phphinder-bundle
1. Go to this page and download the library: Download eliasfernandez/phphinder-bundle 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/ */
eliasfernandez / phphinder-bundle example snippets
class Book
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[PHPhinder\Property(Schema::IS_UNIQUE | Schema::IS_INDEXED | Schema::IS_REQUIRED| Schema::IS_STORED)]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[PHPhinder\Property(Schema::IS_INDEXED | Schema::IS_STORED | Schema::IS_REQUIRED | Schema::IS_FULLTEXT)]
private ?string $title = null;
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $authors = [];
#[ORM\Column(type: Types::TEXT)]
#[PHPhinder\Property(Schema::IS_INDEXED)]
private ?string $description = null;
...
#[PHPhinder\Property(Schema::IS_INDEXED | Schema::IS_REQUIRED, name: 'authors')]
public function getAuthorsCsv(): string
{
return implode(', ', $this->authors);
}}
private SearchEngine $searchEngine;
public function __construct(private StorageFactory $storageFactory, private SchemaGenerator $schemaGenerator)
{
$this->searchEngine = new SearchEngine(
$this->storageFactory->createStorage(
$this->schemaGenerator->generate(Book::class)
)
);
}
#[Route('/search', name: 'app_search', methods: ['GET', 'POST'])]
public function index(Request $request): Response
{
$query = $request->query->get('q', '');
$results = [];
if ($query) {
$results = $this->searchEngine->search($query);
}
return $this->render('search/index.html.twig', [
'query' => $query,
'results' => $results,
]);
}