Skip to content

maidulcu/laravel-searchjetengine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SearchJet Laravel Package

Latest Version on Packagist Total Downloads License

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.

πŸš€ Features

  • 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

πŸ“¦ Installation

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

βš™οΈ Configuration

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

πŸ”§ Basic Usage

Making Models Searchable

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'),
        ];
    }
}

Indexing Documents

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();
});

Searching

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);

Using the Facade

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();

πŸ› οΈ Artisan Commands

Install Command

php artisan searchjet:install

Sets up the package configuration and displays setup instructions.

Index Command

# 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

Search Command

# Basic search
php artisan searchjet:search "laptop" --index=products

# Advanced search
php artisan searchjet:search "laptop" --index=products --limit=20 --filter="price > 100"

πŸ“Š Analytics

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(),
]);

🎯 Advanced Features

Custom Search Configuration

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

Caching is enabled by default. Configure in config/searchjet.php:

'cache' => [
    'enabled' => true,
    'ttl' => 300, // 5 minutes
    'prefix' => 'searchjet:',
],

Rate Limiting

Rate limiting is enabled by default:

'rate_limiting' => [
    'enabled' => true,
    'max_requests_per_minute' => 100,
],

πŸ” Search Options

Basic Search Options

$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
]);

Filtering

// Simple filter
$results = Product::searchJet('laptop', [
    'filter' => 'price > 100'
]);

// Complex filter
$results = Product::searchJet('laptop', [
    'filter' => 'price > 100 AND category = "electronics"'
]);

Sorting

// Single sort
$results = Product::searchJet('laptop', [
    'sort' => ['price:asc']
]);

// Multiple sorts
$results = Product::searchJet('laptop', [
    'sort' => ['price:asc', 'rating:desc']
]);

Faceting

$results = Product::searchJet('laptop', [
    'facets' => ['category', 'brand', 'price']
]);

πŸ§ͺ Testing

composer test

πŸ“ Changelog

Please see CHANGELOG for more information on what has changed recently.

🀝 Contributing

Please see CONTRIBUTING for details.

πŸ”’ Security

If you discover any security related issues, please email security@searchjetengine.com instead of using the issue tracker.

πŸ“„ License

The MIT License (MIT). Please see License File for more information.

πŸ†˜ Support

πŸ™ Credits


Made with ❀️ by the SearchJet team

About

Laravel package for easy SearchJet integration - AI-powered search made simple

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages