prestoworld/search-engine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prestoworld/search-engine

Composer 安装命令:

composer require prestoworld/search-engine

包简介

🚀 High-Performance Search Infrastructure for PrestoWorld CMS

README 文档

README

Latest Version License PHP Version

🚀 High-Performance Search Infrastructure for PrestoWorld CMS

The PrestoWorld Search Engine is the foundational search layer for the PrestoWorld ecosystem. Engineered for speed, precision, and scalability, this module replaces traditional database lookup methods with a sophisticated indexing and retrieval system designed specifically for the modern web.

✨ Why PrestoWorld Search?

In a data-driven world, finding content should be instantaneous and intelligent. The PrestoWorld Search Engine moves beyond simple pattern matching to provide a robust architectural framework that understands your data.

  • 🔧 Flexible Adapter System: Switch between TNTSearch, Typesense, Meilisearch, or custom engines without code changes
  • ⚡ Lightning Performance: Optimized indexing algorithms that deliver results in milliseconds, even with massive datasets
  • 🎯 Advanced Query Builder: Fluent interface for complex searches with filters, sorting, and faceted navigation
  • 🔍 Full-Text Search: Deep data indexing with fuzzy matching, highlighting, and relevance scoring
  • 📊 Real-time Analytics: Built-in performance monitoring and search analytics
  • 🎨 UI Integration: Automatic form generation and faceted navigation components
  • 🛡️ Production Ready: Comprehensive error handling, caching, and security features

🚀 Quick Start

Installation

composer require prestoworld/search-engine

Basic Setup

  1. Configure Environment Add settings to .env:
SEARCH_ENGINE=meilisearch
MEILISEARCH_URL=http://localhost:7700
  1. Index Your Data
php witals search:index posts --source="App\Models\Post"

Your First Search

use Prestoworld\SearchEngine\SearchManager;
use Prestoworld\SearchEngine\QueryBuilder\SearchQueryBuilder;

// Simple search using manager
$searchManager = app(SearchManager::class);
$results = $searchManager->search('articles', 'search query');

// Advanced search with Query Builder
$results = SearchQueryBuilder::for('products')
    ->query('laptop')
    ->where('status', 'active')
    ->paginate(12);

🎯 Key Features

🔧 Multi-Adapter Support

Switch between search engines instantly:

$searchManager = app(SearchManager::class);

// Use TNTSearch for file-based search
$searchManager->switchAdapter('tntsearch');

// Use Typesense for typo-tolerant search
$searchManager->switchAdapter('typesense');

// Use Meilisearch for lightning-fast search
$searchManager->switchAdapter('meilisearch');

🔍 Advanced Query Builder

Build complex searches with a fluent interface:

$results = SearchQueryBuilder::for('products')
    ->query('smartphone')
    ->where('category', 'electronics')
    ->whereIn('brand', ['Apple', 'Samsung'])
    ->whereBetween('price', 500, 1500)
    ->whereLike('features', 'camera')
    ->orderBy('rating', 'desc')
    ->orderBy('price', 'asc')
    ->limit(20)
    ->get();

🎛️ Comprehensive Filtering

Advanced filtering system with multiple filter types:

$filters = FilterManager::fromRequest()
    ->text('title')                    // Text search
    ->select('category')                // Dropdown selection
    ->multiSelect('tags')               // Multiple selections
    ->range('price', 100, 1000)        // Price range
    ->dateRange('created_at')           // Date range
    ->boolean('featured')               // Yes/No filter
    ->exists('image');                  // Has image or not

📊 Faceted Search & Aggregations

Build sophisticated faceted navigation:

$facets = FacetManager::for('products')
    ->facet('category', ['label' => 'Categories'])
    ->facet('brand', ['label' => 'Brands'])
    ->rangeFacet('price', [
        ['from' => 0, 'to' => 50, 'label' => 'Under $50'],
        ['from' => 50, 'to' => 100, 'label' => '$50-$100'],
        ['from' => 100, 'label' => 'Over $100']
    ])
    ->getFacets('laptop');

🎨 Form Integration

Auto-generate search forms with all features:

$form = SearchForm::create('/search')
    ->queryField('q')
    ->textFilter('title')
    ->selectFilter('category', $categories)
    ->rangeFilter('price')
    ->sortSelect([
        'relevance' => 'Relevance',
        'price_asc' => 'Price: Low to High'
    ]);

echo $form->render();

📖 Documentation

📚 Essential Reading

🔧 Configuration

Search Engines

Engine Best For Performance Features
TNTSearch Small datasets (<100K docs) ⚡⚡ File-based, PHP-native
Typesense User-facing search ⚡⚡⚡ Typo-tolerant, fast
Meilisearch High-performance needs ⚡⚡⚡⚡ Lightning-fast, real-time

Environment Variables

# General
SEARCH_ENGINE=meilisearch
SEARCH_CACHE_ENABLED=true
SEARCH_BATCH_SIZE=1000

# TNTSearch
SEARCH_STORAGE_PATH=/app/storage/search

# Typesense
TYPESENSE_API_KEY=xyz
TYPESENSE_HOST=localhost
TYPESENSE_PORT=8108

# Meilisearch
MEILISEARCH_URL=http://localhost:7700
MEILISEARCH_API_KEY=xyz

🛠️ Real-World Examples

E-commerce Product Search

class ProductSearchController extends Controller
{
    public function search(Request $request)
    {
        // Build complex product search
        $results = SearchQueryBuilder::for('products')
            ->query($request->get('q'))
            ->where('status', 'active')
            ->where('stock', '>', 0)
            ->applyFilters($request)
            ->applySorting($request)
            ->paginate(12);

        // Get faceted navigation
        $facets = FacetManager::for('products')
            ->fromRequest()
            ->facet('category')
            ->facet('brand')
            ->rangeFacet('price')
            ->getFacets($request->get('q', '*'));

        return view('products.search', [
            'products' => $results,
            'facets' => $facets,
            'form' => $this->getSearchForm(),
        ]);
    }
}

Blog Article Search

class BlogController extends Controller
{
    public function search(Request $request)
    {
        $results = SearchQueryBuilder::for('articles')
            ->query($request->get('q'))
            ->where('status', 'published')
            ->where('published_at', '<=', now())
            ->highlightFields(['title', 'content'])
            ->orderBy('published_at', 'desc')
            ->paginate(10);

        return view('blog.search', [
            'articles' => $results,
            'query' => $request->get('q'),
        ]);
    }
}

⚡ Performance Features

Benchmarking

Compare performance across adapters:

# Benchmark all adapters
php artisan search:benchmark articles "search query" --iterations=100

# Programmatic benchmarking
$results = Search::benchmark('articles', 'query', 100);
foreach ($results as $adapter => $data) {
    echo "{$adapter}: {$data['average_time']}ms avg\n";
}

Caching

Built-in caching for popular searches:

// Automatic caching
$results = Search::search('products', 'popular query', [
    'cache_ttl' => 3600 // 1 hour
]);

// Manual caching
Cache::remember("search:{$query}", 3600, function () use ($query) {
    return Search::search('products', $query);
});

Batch Operations

Efficient bulk indexing:

// Process in batches
$documents = Product::all()->chunk(1000);
foreach ($documents as $batch) {
    Search::index('products', $batch->toArray());
}

🔧 Advanced Features

Custom Adapters

Create your own search engine adapter:

class ElasticsearchAdapter implements SearchEngineInterface
{
    public function search(string $index, string $query, array $options = []): array
    {
        // Your Elasticsearch implementation
    }
    
    // Implement other required methods...
}

// Register and use
Search::registerAdapter('elasticsearch', ElasticsearchAdapter::class);
Search::switchAdapter('elasticsearch');

Search Analytics

Built-in analytics and monitoring:

// Log searches automatically
Search::search('products', $query, [
    'log_search' => true,
    'user_id' => auth()->id()
]);

// Get analytics
$analytics = new SearchAnalytics();
$popularQueries = $analytics->getPopularQueries(10);
$noResultQueries = $analytics->getNoResultQueries();

Security Features

Input validation and rate limiting:

// Automatic input sanitization
$results = Search::search('products', $query, [
    'validate_input' => true,
    'max_query_length' => 1000
]);

// Rate limiting
if (!SearchRateLimiter::check($userId)) {
    return response()->json(['error' => 'Rate limit exceeded'], 429);
}

🎯 Use Cases

🛒 E-commerce

  • Product catalog search with filters
  • Price range and category filtering
  • Brand and attribute faceting
  • Real-time inventory integration

📰 Content Management

  • Article and blog search
  • Full-text content indexing
  • Author and category filtering
  • Related content recommendations

🏢 Enterprise Search

  • Document repository search
  • Knowledge base integration
  • Permission-based filtering
  • Advanced query syntax

📱 Mobile Applications

  • Fast API responses
  • Offline search capabilities
  • Geospatial search
  • Personalized results

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/prestoworld/search-engine.git
cd search-engine
composer install
composer test

Running Tests

# Run all tests
composer test

# Run specific test suite
composer test:unit
composer test:integration
composer test:performance

📄 License

PrestoWorld Search Engine is open-sourced software licensed under the MIT license.

🆘 Support

🗺️ Roadmap

v1.1 (Planned)

  • GraphQL integration
  • Advanced analytics dashboard
  • Machine learning relevance tuning
  • Multi-tenant support

v1.2 (Future)

  • Distributed search clusters
  • Real-time collaboration features
  • Advanced A/B testing
  • Voice search integration

PrestoWorld Search EngineEmpowering Digital Experiences with Unmatched Search Performance

⭐ Star us on GitHub!

GitHub stars

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固