Download the PHP package searchcraft/searchcraft-php without Composer
On this page you can find all versions of the php package searchcraft/searchcraft-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download searchcraft/searchcraft-php
More information about searchcraft/searchcraft-php
Files in searchcraft/searchcraft-php
Package searchcraft-php
Short Description Searchcraft API PHP Client
License Apache-2.0
Informations about the package searchcraft-php
Searchcraft API PHP Client
A PSR-compatible PHP client for the Searchcraft API.
Documentation | Discord | FAQ | Issues / Requests | Searchcraft Cloud | Searchcraft Website
Installation
You will also need to install a PSR-18 compatible HTTP client, such as Guzzle.
Basic Usage
Initialize the client
The client can be initialized with different types of API keys, depending on your access requirements:
By default, the client connects to http://localhost:8000. To use a different endpoint such as a Searchcraft Cloud cluster:
Using PSR-18 HTTP Client
The client uses PSR-18 HTTP Client discovery to find an available HTTP client. You can also provide your own:
Searchcraft 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.
Search Operations
Search operations require an admin key or read key.
Basic Search
time_taken on the response is reported in seconds. limit defaults to 20
and is rejected client-side above 200.
Scoping a Search to Specific Fields
fields restricts a query to particular fields instead of the index's
configured search_fields. Pass a field name, a list of names, or a map of
name to boost. The engine honors it for fuzzy and term clauses.
Boolean Occurrence
occur sets how the clause participates in matching. It is placed beside the
mode key inside the query object for you.
occur and fields both describe a single clause, so they apply to string
queries only. Passing either alongside an array query throws a
SearchcraftException — set them inside the clause itself in that case.
Additional Search Options
Complex Queries
Pass an array instead of a string to build a multi-clause query. It is
forwarded to the engine verbatim, which is how you reach the query kinds that
have no string shorthand. Each clause takes an occur of should, must, or
mustnot, and a fields selector belongs inside the clause rather than in the
options array.
Federation Search
Index Operations
Index administration operations require an admin key.
List Indexes
Get Index Details
Create Index
Update Index
Note 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 for details on which properties are patchable.
updateIndex is a whole-schema replacement, so anything you leave out reverts
to its default. It is also the only way to change fields or to clear
search_fields, weight_multipliers or language — patchIndex cannot do
either.
Patch Index
fields is not patchable — the engine carries the existing schema over
verbatim and silently ignores a fields key here. search_fields,
weight_multipliers and language cannot be cleared either, since the engine
reads an empty value as "leave unchanged". Use updateIndex for both.
time_decay_field can be cleared by passing an empty string.
Index Statistics
Delete Index
Document Operations
Document operations require an admin key or ingest key.
Add Documents
Update Documents
Get Document
Delete Documents
Stopword Operations
Stopwords are excluded from indexing and from queries when the index has
exclude_stop_words enabled.
Federation Operations
Federation 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.
List Federations
Get Federation Details
Get Federations by Organization
List a Federation's Indexes
Federation Statistics
Create Federation
Update Federation
Delete Federation
AI Capabilities
Requires Searchcraft Engine 0.10.0 or later.
Check AI Capabilities for an Index
Streaming AI Search Summaries
The index must have ai_enabled: true and a valid ai.search_summary
configuration. The engine streams Server-Sent Events: one metadata
event, any number of delta events with content chunks, and a final
done event. searchSummary() returns every parsed event, and you may
optionally pass a callback to react to events as they arrive.
Authentication Operations
Get Keys for an Index
Check a Key's Permissions
The engine stores key permissions as a bitmask rather than a fixed set of
levels. Combine the Searchcraft\Permissions constants with the bitwise OR
operator. A key that simply lacks the permission is answered with a 403, which
is reported as false rather than raised as an exception.
Individual bits: SEARCH, MODIFY_SYNONYMS, MODIFY_STOP_WORDS,
MODIFY_DOCUMENTS, MODIFY_INDEX, MODIFY_AUTH, LLM_RAG_SUMMARIES,
LLM_EXPANDED_KEYWORD_SEARCH, READ_ANALYTICS.
Presets come in two kinds. Levels say what a key can change: PRESET_READ
(1), PRESET_INGEST (15), PRESET_ADMIN (63), PRESET_SUPER_USER (511).
Add-ons are features a key can use on top of its level: PRESET_AI (64) and
PRESET_ANALYTICS (256). Combine them with |.
Measure Operations
The Measure API is primarily used by SDKs and CMS integrations to capture search usage metrics and retrieve dashboard aggregates.
Check Whether Analytics Are Enabled
Track a Single Event
Track a Batch of Events
Dashboard Metrics
date_start and date_end are Unix timestamps in seconds. granularity is
one of minutes, hours, days, weeks, months, or years.
Compatibility
| Client version | Searchcraft Engine |
|---|---|
| 0.8.2 | 0.11.x |
| 0.8.0 - 0.8.1 | 0.10.x |
| 0.7.x | 0.7.9 - 0.9.x |
Error Handling
All operations should be wrapped in a try/catch block to handle errors:
Documentation
For view the rest of the endpoints and operations, please refer to the full Searchcraft API documentation.
To run unit tests
./vendor/bin/pest
License
Apache 2.0 License
All versions of searchcraft-php with dependencies
ext-json Version *
php-http/discovery Version ^1.7
psr/http-client Version ^1.0