arthur2weber/query-craft
Composer 安装命令:
composer require arthur2weber/query-craft
包简介
Craft elegant DSL queries with fluent, Eloquent-inspired syntax for Elasticsearch, MongoDB, and GraphQL. Build powerful search queries with familiar Laravel-like syntax.
关键字:
README 文档
README
Elegant Elasticsearch DSL Query Builder for PHP
Craft complex Elasticsearch queries with Laravel-inspired fluent syntax. Zero dependencies, maximum productivity.
🚀 Quick Start
composer require arthur2weber/query-craft
<?php use Arthur2weber\QueryCraft\ElasticQuery; // Simple search with filters $query = new ElasticQuery(); $dslQuery = $query ->search('PHP Elasticsearch', ['title^3', 'content']) ->filter('status', 'published') ->range('created_at', 'gte', '2024-01-01') ->sort('_score', 'desc') ->size(10) ->build(); // Ready for Elasticsearch PHP Client $response = $client->search([ 'index' => 'articles', 'body' => $dslQuery ]);
✨ Why QueryCraft?
- 🎯 Familiar Syntax - Laravel-like methods for instant productivity
- ⚡ Zero Dependencies - Pure PHP, no framework requirements
- 🔧 Complete DSL Support - Full Elasticsearch 7.x+ compatibility
- 📊 Advanced Features - Aggregations, geo-queries, nested objects
- 🛡️ Developer Experience - Verbose mode, error translation, performance warnings
- 📚 Rich Documentation - 50+ examples and comprehensive guides
- 💎 Eloquent-Friendly - Zero learning curve for Laravel developers
🚀 For Laravel Developers
If you know Eloquent, you already know QueryCraft!
Use the exact same methods you love:
// ✅ Your familiar Eloquent syntax $usersQuery = User::where('status', 'active') ->whereIn('role', ['admin', 'editor']) ->whereBetween('created_at', [$start, $end]) ->orderByDesc('created_at') ->paginate(15) ->toSql(); // ✅ Identical QueryCraft syntax $usersQuery = (new ElasticQuery()) ->where('status', 'active') ->whereIn('role', ['admin', 'editor']) ->whereBetween('created_at', [$start, $end]) ->orderByDesc('created_at') ->paginate(15) ->build();
Everything works exactly as expected:
where(),whereIn(),whereNotIn(),whereBetween()orderBy(),orderByDesc(),latest(),oldest()paginate(),limit(),offset(),take(),skip()when(),unless()- conditional queriescount(),avg(),sum(),max(),min()- aggregations
Plus powerful Elasticsearch features:
- Full-text search with
search()andmatch() - Geographic queries with
geoDistance()andgeoBoundingBox() - Advanced aggregations and faceted search
- Fuzzy search and auto-complete
🔥 Core Features
🔍 Search & Query Methods
// Text search with boost ->search('PHP Laravel', ['title^3', 'content', 'tags^2']) ->match('title', 'Elasticsearch tutorial') ->matchPhrase('content', 'exact phrase search') ->queryString('title:PHP AND status:published') // Term & filters ->filter('status', 'published') ->terms('category', ['php', 'elasticsearch']) ->range('price', 'gte', 100) ->exists('featured_image') // Advanced search ->fuzzy('title', 'elesticsearch', 2) // 2 typos allowed ->wildcard('filename', '*.php') ->regexp('code', '[a-z]+@[a-z]+')
📊 Aggregations & Analytics
// Terms aggregation (categories) ->aggregation('categories', [ 'terms' => ['field' => 'category.keyword', 'size' => 10] ]) // Date histogram (time series) ->aggregation('monthly_posts', [ 'date_histogram' => [ 'field' => 'created_at', 'calendar_interval' => 'month' ] ]) // Nested aggregations with statistics ->aggregation('categories', [ 'terms' => [ 'field' => 'category.keyword', 'aggs' => [ 'avg_price' => ['avg' => ['field' => 'price']], 'max_views' => ['max' => ['field' => 'views']] ] ] ])
🌍 Geographic Search
// Find restaurants within 5km ->geoDistance('location', '40.7128,-74.0060', '5km') // Bounding box search ->geoBoundingBox('location', [ 'top_left' => '40.8,-74.1', 'bottom_right' => '40.6,-73.9' ]) // Sort by distance ->sort([ '_geo_distance' => [ 'location' => '40.7128,-74.0060', 'order' => 'asc' ] ])
🛡️ Developer Experience
// Enable debugging $query->verbose(); // Get detailed logs $logs = $query->getVerboseLog(); // Performance warnings $warnings = $query->getPerformanceWarnings(); // Human-readable error translation $readable = $query->translateError($elasticsearchError);
🚀 Quick Examples
Laravel Migration (Zero Learning Curve!)
// Before (Eloquent) $posts = Post::where('status', 'published') ->whereIn('category', ['tech', 'programming']) ->orderByDesc('created_at') ->paginate(15); // After (QueryCraft) - Identical syntax! $posts = (new ElasticQuery()) ->where('status', 'published') ->whereIn('category', ['tech', 'programming']) ->orderByDesc('created_at') ->paginate(15); // Enhanced with full-text search $posts = (new ElasticQuery()) ->search('Laravel tutorial', ['title^3', 'content']) // ✨ New superpower ->where('status', 'published') ->whereIn('category', ['tech', 'programming']) ->orderByDesc('_score') // ✨ Sort by relevance ->paginate(15);
Basic Search
// Simple product search with filters $query = new ElasticQuery(); $result = $query ->search('iPhone 13', ['title^3', 'description']) ->filter('status', 'active') ->filter('in_stock', true) ->range('price', 'lte', 1000) ->sort(['_score' => 'desc', 'price' => 'asc']) ->size(20) ->build();
E-commerce with Facets
// Product search with category aggregations $query = new ElasticQuery(); $result = $query ->search($searchTerm, ['name^3', 'brand^2', 'description']) ->filter('status', 'active') ->range('price', 'gte', $minPrice) ->aggregation('brands', [ 'terms' => ['field' => 'brand.keyword', 'size' => 10] ]) ->aggregation('categories', [ 'terms' => ['field' => 'category.keyword', 'size' => 5] ]) ->sort('_score', 'desc') ->build();
Geographic Search
// Find nearby restaurants $query = new ElasticQuery(); $result = $query ->match('type', 'restaurant') ->geoDistance('location', '40.7128,-74.0060', '2km') ->filter('rating', '>=', 4.0) ->sort([ '_geo_distance' => [ 'location' => '40.7128,-74.0060', 'order' => 'asc' ] ]) ->build();
📚 Documentation
- 📖 Complete Wiki - Comprehensive usage guide with examples
- ⚡ Quick Reference - All methods and patterns
- 🔧 Developer Experience - Debugging and optimization
- 📊 Testing Guide - Test suite and quality metrics
- 📈 Test Coverage Summary - Detailed test statistics and coverage
- 🗺️ Roadmap - Future development plans
🧪 Testing
# Quick tests (recommended for development) ./tt # All tests ./tt all # Specific categories ./tt core search filters utilities # Alternative methods php t.php make test
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Run tests:
./tt all - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
📄 License
This project is licensed under the MIT License.
🔗 Links
- GitHub Repository: arthur2weber/query-craft
- Packagist: arthur2weber/query-craft
- Issues: Report bugs or request features
Made with ❤️ for the PHP community
arthur2weber/query-craft 适用场景与选型建议
arthur2weber/query-craft 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 08 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mongodb」 「php」 「DSL」 「search」 「elasticsearch」 「query-builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arthur2weber/query-craft 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arthur2weber/query-craft 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arthur2weber/query-craft 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates Symfony2 documents, forms and CRUD
Feature complete, object oriented, composable, extendable Elasticsearch query DSL builder for PHP.
Elasticsearch DSL library
Expression executor, which allow to implement domain-specific language
DSL for writing sniffs for PHP_CodeSniffer
A package to allow laravel/passport use with mongodb/laravel-mongodb
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-21