{"id":37262151,"url":"https://github.com/searchcraft-inc/searchcraft-client-php","last_synced_at":"2026-01-15T23:14:43.831Z","repository":{"id":297115819,"uuid":"995041792","full_name":"searchcraft-inc/searchcraft-client-php","owner":"searchcraft-inc","description":"Official PSR-compatible PHP client for the Searchcraft API","archived":false,"fork":false,"pushed_at":"2025-11-21T22:26:53.000Z","size":1227,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-21T23:21:56.499Z","etag":null,"topics":["client","database","enterprise-search","fuzzy-search","php8","psr-18","sdk","search-as-you-type","search-engine","searchcraft","site-search","typo-tolerance"],"latest_commit_sha":null,"homepage":"https://searchcraft.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/searchcraft-inc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-02T22:00:01.000Z","updated_at":"2025-11-21T21:55:58.000Z","dependencies_parsed_at":"2025-06-04T06:50:48.320Z","dependency_job_id":"09d2c97b-34bd-41eb-9c3d-ad357066cf13","html_url":"https://github.com/searchcraft-inc/searchcraft-client-php","commit_stats":null,"previous_names":["searchcraft-inc/searchcraft-client-php"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/searchcraft-inc/searchcraft-client-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchcraft-inc%2Fsearchcraft-client-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchcraft-inc%2Fsearchcraft-client-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchcraft-inc%2Fsearchcraft-client-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchcraft-inc%2Fsearchcraft-client-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/searchcraft-inc","download_url":"https://codeload.github.com/searchcraft-inc/searchcraft-client-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchcraft-inc%2Fsearchcraft-client-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","database","enterprise-search","fuzzy-search","php8","psr-18","sdk","search-as-you-type","search-engine","searchcraft","site-search","typo-tolerance"],"created_at":"2026-01-15T23:14:43.271Z","updated_at":"2026-01-15T23:14:43.818Z","avatar_url":"https://github.com/searchcraft-inc.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build faster, ship more. The next frontier in developer search tools is here. Searchcraft](./header.png)\n\n# Searchcraft API PHP Client\n\nA [PSR-compatible](https://www.php-fig.org/psr/) PHP client for the Searchcraft API.\n\n[![Test Status](https://github.com/searchcraft-inc/searchcraft-client-php/actions/workflows/tests.yml/badge.svg)](https://github.com/searchcraft-inc/searchcraft-client-php/actions/workflows/tests.yml)\n\n#### [Documentation](https://docs.searchcraft.io?utm_campaign=oss\u0026utm_source=github\u0026utm_medium=searchcraft-php-client) | [Discord](https://discord.com/invite/y3zUHkBk6e) | [FAQ](https://www.searchcraft.io/frequently-asked-questions?utm_campaign=oss\u0026utm_source=github\u0026utm_medium=searchcraft-php-client) | [Issues / Requests](https://github.com/searchcraft-inc/searchcraft-issues) | [Searchcraft Cloud](https://vektron.searchcraft.io?utm_campaign=oss\u0026utm_source=github\u0026utm_medium=searchcraft-php-client) | [Searchcraft Website](https://searchcraft.io?utm_campaign=oss\u0026utm_source=github\u0026utm_medium=searchcraft-php-client)\n\n## Installation\n\n```bash\ncomposer require searchcraft/searchcraft-php\n```\n\nYou will also need to install a PSR-18 compatible HTTP client, such as [Guzzle](https://github.com/guzzle/guzzle).\n\n```bash\ncomposer require guzzlehttp/guzzle http-interop/http-factory-guzzle:^1.0\n```\n\n## Basic Usage\n\n### Initialize the client\n\nThe client can be initialized with different types of API keys, depending on your access requirements:\n\n```php\nuse Searchcraft\\Searchcraft;\n\n// Using an admin key (full access)\n$searchcraft_full = new Searchcraft('your-admin-key');\n\n// Using a read-only key (search and read operations only)\n$searchcraft_reader = new Searchcraft('your-read-key', Searchcraft::KEY_TYPE_READ);\n\n// Using an ingest key (document operations only)\n$searchcraft_ingestion = new Searchcraft('your-ingest-key', Searchcraft::KEY_TYPE_INGEST);\n```\n\nBy default, the client connects to `http://localhost:8000`. To use a different endpoint such as a Searchcraft Cloud cluster:\n\n```php\n// Replace with your cluster endpoint\n$searchcraft = new Searchcraft(\n    'your-api-key',\n    Searchcraft::KEY_TYPE_ADMIN,\n    'https://yourcluster.io'\n);\n```\n\n### Using PSR-18 HTTP Client\n\nThe client uses [PSR-18 HTTP Client discovery](https://github.com/php-http/discovery) to find an available HTTP client. You can also provide your own:\n\n```php\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\Psr7\\HttpFactory;\n\n$httpClient = new Client();\n$requestFactory = new HttpFactory();\n$streamFactory = new HttpFactory();\n\n$searchcraft = new Searchcraft(\n    'your-api-key',\n    Searchcraft::KEY_TYPE_ADMIN,\n    'https://api.searchcraft.io/v1',\n    $httpClient,\n    $requestFactory,\n    $streamFactory\n);\n```\n\nSearchcraft PHP Client does not include a specific HTTP client in its `require` dependencies but Guzzle is recommended. You will need to install one in order to use the Searchcraft client.\n\n## Search Operations\n\nSearch operations require an admin key or read key.\n\n### Basic Search\n\n```php\n// Simple search query\n$results = $searchcraft-\u003esearch()-\u003equery('my_index', 'search term');\n\n// Search with additional parameters\n$results = $searchcraft-\u003esearch()-\u003equery('my_index', 'search term', [\n    'limit' =\u003e 20,\n    'offset' =\u003e 0,\n    'sort' =\u003e 'price:asc',\n    'mode' =\u003e 'fuzzy'\n]);\n\n// Fuzzy search (default)\n$results = $searchcraft-\u003esearch()-\u003equery('my_index', 'search term');\n\n// Explicit fuzzy search\n$results = $searchcraft-\u003esearch()-\u003equery('my_index', 'search term', ['mode' =\u003e 'fuzzy']);\n\n// Exact search\n$results = $searchcraft-\u003esearch()-\u003equery('my_index', 'search term', ['mode' =\u003e 'exact']);\n\n```\n\n### Federation Search\n\n```php\n// Search across all indexes in a federation using federatedQuery\n$searchResults = $searchcraft-\u003esearch()-\u003efederatedQuery('my_federation', 'breaking news', [\n    'limit' =\u003e 20,\n    'offset' =\u003e 0,\n    'mode' =\u003e 'fuzzy'\n]);\n\n// Federation search with additional options\n$searchResults = $searchcraft-\u003esearch()-\u003efederatedQuery('my_federation', 'search term', [\n    'limit' =\u003e 50,\n    'offset' =\u003e 10,\n    'order_by' =\u003e 'publishedAt',\n    'sort' =\u003e 'desc',\n    'occur' =\u003e 'should',\n    'mode' =\u003e 'exact'\n]);\n```\n\n## Index Operations\n\nIndex administration operations require an admin key.\n\n### List Indexes\n\n```php\n$indexes = $searchcraft-\u003eindex()-\u003elistIndexes();\n```\n\n### Get Index Details\n\n```php\n$indexDetails = $searchcraft-\u003eindex()-\u003egetIndex('products');\n```\n\n### Create Index\n\n```php\n$newIndex = $searchcraft-\u003eindex()-\u003ecreateIndex('blog', [\n    'index' =\u003e [\n        'name' =\u003e 'blog',\n        'language' =\u003e 'en',\n        'search_fields' =\u003e ['title', 'content', 'tags'],\n        'fields' =\u003e [\n            'id' =\u003e [\n                'type' =\u003e 'text',\n                'required' =\u003e true,\n                'stored' =\u003e true,\n                'indexed' =\u003e false\n            ],\n            'title' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true\n            ],\n            'content' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true\n            ],\n            'tags' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true,\n                'multi' =\u003e true\n            ],\n            'category' =\u003e [\n                'type' =\u003e 'facet',\n                'stored' =\u003e true\n            ],\n            'publishedAt' =\u003e [\n                'type' =\u003e 'datetime',\n                'fast' =\u003e true,\n                'stored' =\u003e true,\n                'indexed' =\u003e true\n            ]\n        ],\n        'weight_multipliers' =\u003e [\n            'title' =\u003e 2.0,\n            'tags' =\u003e 1.0,\n            'content' =\u003e 0.6\n        ]\n    ]\n]);\n```\n\n### Update Index\n\nNote if you are not adding, removing or changing properties of schema fields will likely want to use the `PATCH` operation instead. An update request will remove existing documents but for patchable updates your index is not emptied. See the [docs](https://docs.searchcraft.io/api/schema/?utm_campaign=oss\u0026utm_source=github\u0026utm_medium=searchcraft-php-client) for details on which properties are patchable.\n\n```php\n$updatedIndex = $searchcraft-\u003eindex()-\u003eupdateIndex('blog', [\n    'index' =\u003e [\n        'name' =\u003e 'blog',\n        'language' =\u003e 'en',\n        'search_fields' =\u003e ['title', 'content', 'tags', 'summary'],\n        'fields' =\u003e [\n            'id' =\u003e [\n                'type' =\u003e 'text',\n                'required' =\u003e true,\n                'stored' =\u003e true,\n                'indexed' =\u003e false\n            ],\n            'title' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true\n            ],\n            'content' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true\n            ],\n            'summary' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true\n            ],\n            'tags' =\u003e [\n                'type' =\u003e 'text',\n                'stored' =\u003e true,\n                'multi' =\u003e true\n            ],\n            'category' =\u003e [\n                'type' =\u003e 'facet',\n                'stored' =\u003e true\n            ],\n            'publishedAt' =\u003e [\n                'type' =\u003e 'datetime',\n                'fast' =\u003e true,\n                'stored' =\u003e true,\n                'indexed' =\u003e true\n            ]\n        ],\n        'weight_multipliers' =\u003e [\n            'title' =\u003e 2.0,\n            'content' =\u003e 1.0,\n            'summary' =\u003e 1.5\n        ]\n    ]\n]);\n```\n\n### Patch Index\n\n```php\n$patchedIndex = $searchcraft-\u003eindex()-\u003epatchIndex('blog', [\n    'search_fields' =\u003e ['title', 'content', 'tags', 'summary'],\n    'weight_multipliers' =\u003e [\n        'title' =\u003e 3.0,\n        'content' =\u003e 1.0,\n        'summary' =\u003e 1.5,\n        'tags' =\u003e 0.8\n    ],\n    'language' =\u003e 'en',\n    'time_decay_field' =\u003e 'publishedAt',\n    'auto_commit_delay' =\u003e 2,\n    'exclude_stop_words' =\u003e true\n]);\n```\n\n### Delete Index\n\n```php\n$result = $searchcraft-\u003eindex()-\u003edeleteIndex('my-index');\n```\n\n## Document Operations\n\nDocument operations require an admin key or ingest key.\n\n### Add Documents\n\n```php\n$result = $searchcraft-\u003eindex()-\u003eaddDocuments('products', [\n    [\n        'id' =\u003e '1',\n        'name' =\u003e 'Smartphone X',\n        'price' =\u003e 699.99,\n        'category' =\u003e 'Electronics',\n        'brand' =\u003e 'BrandName'\n    ],\n    [\n        'id' =\u003e '2',\n        'name' =\u003e 'Laptop Pro',\n        'price' =\u003e 1299.99,\n        'category' =\u003e 'Electronics',\n        'brand' =\u003e 'BrandName'\n    ]\n]);\n```\n\n### Update Documents\n\n```php\n$result = $searchcraft-\u003eindex()-\u003eupdateDocuments('products', [\n    [\n        'id' =\u003e '1',\n        'price' =\u003e 649.99,\n        'in_stock' =\u003e true\n    ]\n]);\n```\n\n### Get Document\n\n```php\n$document = $searchcraft-\u003eindex()-\u003egetDocument('products', '1');\n```\n\n### Delete Documents\n\n```php\n$result = $searchcraft-\u003eindex()-\u003edeleteDocuments('products', ['1', '2']);\n```\n\n## Federation Operations\n\nFederation operations allow you to manage federations that combine multiple indexes for cross-index search. Federation administration operations require an admin key, while federation search requires a read key.\n\n### List Federations\n\n```php\n// List all federations\n$federations = $searchcraft-\u003efederation()-\u003elistFederations();\n```\n\n### Get Federation Details\n\n```php\n// Get details of a specific federation\n$federation = $searchcraft-\u003efederation()-\u003egetFederation('galaxy_news_federation');\n```\n\n### Get Federations by Organization\n\n```php\n// Get all federations for a specific organization\n$organizationFederations = $searchcraft-\u003efederation()-\u003egetFederationsByOrganization('4');\n```\n\n### Create Federation\n\n```php\n// Create a new federation with weighted index configurations\n$newFederation = $searchcraft-\u003efederation()-\u003ecreateFederation([\n    'name' =\u003e '4_galaxy_news_test',\n    'friendly_name' =\u003e 'Galaxy News Test Federation',\n    'created_by' =\u003e '1',\n    'last_modified_by' =\u003e '1',\n    'organization_id' =\u003e '4',\n    'index_configurations' =\u003e [\n        [\n            'name' =\u003e 'news_articles',\n            'weight_multiplier' =\u003e 1.0\n        ],\n        [\n            'name' =\u003e 'blog_posts',\n            'weight_multiplier' =\u003e 0.8\n        ],\n        [\n            'name' =\u003e 'press_releases',\n            'weight_multiplier' =\u003e 1.5\n        ]\n    ]\n]);\n```\n\n### Update Federation\n\n```php\n// Update an existing federation\n$updatedFederation = $searchcraft-\u003efederation()-\u003eupdateFederation('galaxy_news_federation', [\n    'friendly_name' =\u003e 'Updated Galaxy News Federation',\n    'last_modified_by' =\u003e '1',\n    'organization_id' =\u003e '4',\n    'index_configurations' =\u003e [\n        [\n            'name' =\u003e 'news_articles',\n            'weight_multiplier' =\u003e 1.2\n        ],\n        [\n            'name' =\u003e 'blog_posts',\n            'weight_multiplier' =\u003e 0.9\n        ],\n        [\n            'name' =\u003e 'press_releases',\n            'weight_multiplier' =\u003e 1.8\n        ],\n        [\n            'name' =\u003e 'social_media',\n            'weight_multiplier' =\u003e 0.6\n        ]\n    ]\n]);\n```\n\n### Delete Federation\n\n```php\n// Delete a federation\n$result = $searchcraft-\u003efederation()-\u003edeleteFederation('old_federation');\n```\n\n## Error Handling\n\nAll operations should be wrapped in a try/catch block to handle errors:\n\n```php\nuse Searchcraft\\Exception\\SearchcraftException;\n\ntry {\n    $results = $searchcraft-\u003esearch()-\u003equery('products', 'smartphone');\n} catch (SearchcraftException $e) {\n    echo 'Error: ' . $e-\u003egetMessage();\n}\n```\n\n## Documentation\n\nFor view the rest of the endpoints and operations, please refer to the full [Searchcraft API documentation](https://docs.searchcraft.io?utm_campaign=oss\u0026utm_source=github\u0026utm_medium=searchcraft-php-client).\n\n## To run unit tests\n\n`./vendor/bin/pest`\n\n## License\n\n[Apache 2.0 License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsearchcraft-inc%2Fsearchcraft-client-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsearchcraft-inc%2Fsearchcraft-client-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsearchcraft-inc%2Fsearchcraft-client-php/lists"}