A powerful Laravel package for integrating SearchJet's AI-powered search capabilities into your Laravel applications. SearchJet provides lightning-fast, typo-tolerant search with advanced features like semantic search, analytics, and AI content generation.
- Lightning Fast Search: Sub-150ms search results with instant autocomplete
- AI-Powered: Semantic understanding with typo tolerance and synonyms
- Easy Integration: Drop-in search solution with Laravel's Eloquent models
- Advanced Analytics: Track search behavior and optimize content strategy
- Laravel Native: Built specifically for Laravel with familiar patterns
- Caching Support: Built-in caching for improved performance
- Rate Limiting: Protection against API abuse
- Artisan Commands: Easy-to-use CLI tools for indexing and management
You can install the package via Composer:
composer require searchjet/laravel-searchjet
Publish the configuration file:
php artisan vendor:publish --tag=searchjet-config
Run the installation command:
php artisan searchjet:install
Add your SearchJet credentials to your .env
file:
SEARCHJET_API_KEY=your_api_key_here
SEARCHJET_BASE_URL=https://api.searchjetengine.com
SEARCHJET_SITE_ID=your_site_id_here
Add the Searchable
trait to your Eloquent models:
use SearchJet\Laravel\Traits\Searchable;
class Product extends Model
{
use Searchable;
// Optional: Customize the index name
public function searchJetIndex(): string
{
return 'products_v2';
}
// Optional: Customize the document structure
public function toSearchJetDocument(): array
{
return [
'id' => $this->id,
'title' => $this->name,
'description' => $this->description,
'price' => $this->price,
'category' => $this->category->name,
'tags' => $this->tags->pluck('name'),
];
}
}
Index all products:
php artisan searchjet:index products --model=App\\Models\\Product
Or index programmatically:
// Index a single model
$product->searchJetAddToIndex();
// Index all models
Product::all()->each(function ($product) {
$product->searchJetAddToIndex();
});
Search using the model:
// Simple search
$results = Product::searchJet('laptop');
// Advanced search with options
$results = Product::searchJet('laptop', [
'limit' => 10,
'filter' => 'price > 100',
'sort' => ['price:asc'],
'facets' => ['category', 'brand'],
]);
// Get results as collection
$products = Product::searchJetGet('laptop');
// Get first result
$product = Product::searchJetFirst('laptop');
// Count results
$count = Product::searchJetCount('laptop');
// Paginated results
$paginated = Product::searchJetPaginate('laptop', 1, 20);
use SearchJet\Laravel\Facades\SearchJet;
// Search directly
$results = SearchJet::search('products')->query('laptop');
// Index management
SearchJet::index('products')->addDocument($document);
SearchJet::index('products')->addDocuments($documents);
// Analytics
$analytics = SearchJet::analytics()->getAnalytics();
php artisan searchjet:install
Sets up the package configuration and displays setup instructions.
# Index from a model
php artisan searchjet:index products --model=App\\Models\\Product
# Clear and reindex
php artisan searchjet:index products --model=App\\Models\\Product --clear
# Custom batch size
php artisan searchjet:index products --model=App\\Models\\Product --batch-size=500
# Basic search
php artisan searchjet:search "laptop" --index=products
# Advanced search
php artisan searchjet:search "laptop" --index=products --limit=20 --filter="price > 100"
Track search analytics:
use SearchJet\Laravel\Facades\SearchJet;
// Get analytics
$analytics = SearchJet::analytics()->getAnalytics();
// Get popular queries
$popular = SearchJet::analytics()->getPopularQueries('products');
// Get zero-result queries
$zeroResults = SearchJet::analytics()->getZeroResultQueries('products');
// Track clicks
SearchJet::analytics()->trackClick([
'query' => 'laptop',
'document_id' => '123',
'position' => 1,
'timestamp' => now()->toISOString(),
]);
class Product extends Model
{
use Searchable;
public function getSearchJetRankingRules(): array
{
return [
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness'
];
}
public function getSearchJetSearchableAttributes(): array
{
return ['title', 'description', 'tags'];
}
public function getSearchJetFilterableAttributes(): array
{
return ['category', 'price', 'brand'];
}
public function getSearchJetSortableAttributes(): array
{
return ['price', 'created_at', 'rating'];
}
}
Caching is enabled by default. Configure in config/searchjet.php
:
'cache' => [
'enabled' => true,
'ttl' => 300, // 5 minutes
'prefix' => 'searchjet:',
],
Rate limiting is enabled by default:
'rate_limiting' => [
'enabled' => true,
'max_requests_per_minute' => 100,
],
$results = Product::searchJet('laptop', [
'limit' => 20, // Number of results
'offset' => 0, // Skip results
'attributes_to_retrieve' => ['*'], // Fields to return
'attributes_to_highlight' => ['title'], // Fields to highlight
'attributes_to_crop' => ['description'], // Fields to crop
'crop_length' => 200, // Crop length
'highlight_pre_tag' => '<mark>', // Highlight start tag
'highlight_post_tag' => '</mark>', // Highlight end tag
]);
// Simple filter
$results = Product::searchJet('laptop', [
'filter' => 'price > 100'
]);
// Complex filter
$results = Product::searchJet('laptop', [
'filter' => 'price > 100 AND category = "electronics"'
]);
// Single sort
$results = Product::searchJet('laptop', [
'sort' => ['price:asc']
]);
// Multiple sorts
$results = Product::searchJet('laptop', [
'sort' => ['price:asc', 'rating:desc']
]);
$results = Product::searchJet('laptop', [
'facets' => ['category', 'brand', 'price']
]);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email security@searchjetengine.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Made with β€οΈ by the SearchJet team