Giter Club home page Giter Club logo

app-search-php's Introduction

⚠️ This client is deprecated ⚠️

As of Enterprise Search version 7.13.0, we are directing users to the new Enterprise Search PHP Client and deprecating this client.

This client will be compatible with all Enterprise Search 7.x releases, but will not be compatible with 8.x releases. Our development effort on this project will be limited to bug fixes. All future enhancements will be focused on the Enterprise Search PHP Client.

Thank you! - Elastic

Elastic App Search Logo

CircleCI buidl

A first-party PHP client for building excellent, relevant search experiences with Elastic App Search.

Contents


Getting started 🐣

Using this client assumes that you have already an instance of Elastic App Search up and running.

You can find more information about Elastic App Search at : https://www.elastic.co/app-search.

You can install the client in your project by using composer:

composer require elastic/app-search

Versioning

This client is versioned and released alongside App Search.

To guarantee compatibility, use the most recent version of this library within the major version of the corresponding App Search implementation.

For example, for App Search 7.3, use 7.3 of this library or above, but not 8.0.

If you are using the SaaS version available on swiftype.com of App Search, you should use the version 7.5.x of the client.

Usage

Configuring the client

Basic client instantiation

To instantiate a new client you can use \Elastic\AppSearch\Client\ClientBuilder:

  $apiEndpoint   = 'http://localhost:3002/';
  $apiKey        = 'private-XXXXXXXXXXXX';
  $clientBuilder = \Elastic\AppSearch\Client\ClientBuilder::create($apiEndpoint, $apiKey);

  $client = $clientBuilder->build();

Notes:

  • The resulting client will be of type \Elastic\AppSearch\Client\Client

  • You can find the API endpoint and your API key URL in the credentials sections of the App Search dashboard.

  • You can use any type of API Key (private, public or admin). The client will throw an exception if you try to execute an action that is not authorized for the key used.

Basic usage

Retrieve or create an engine

Most methods of the API require that you have access to an Engine.

To check if an Engine exists and retrieve its configuration, you can use the Client::getEngine method :

  $engine = $client->getEngine('my-engine');

If the Engine does not exists yet, you can create it by using the Client::createEngine method :

  $engine = $client->createEngine('my-engine', 'en');

The second parameter ($language) is optional. Set it to null to apply the universal language.

Read more about language support.

Index some documents

You can use the Client::indexDocuments method to index some documents into the Engine:

    $documents = [
      ['id' => 'first-document', 'name' => 'Document name', 'description' => 'Document description'],
      ['id' => 'other-document', 'name' => 'Other document name', 'description' => 'Other description'],
    ];

    $indexingResults = $client->indexDocuments('my-engine', $documents);

The $indexingResults array will contain the result of the indexation of each documents. You should always check the content of the result.

Read more about document indexing.

Search

You can use the Client::search method to search in your Engine:

    $searchParams = [
      'page'  => ['current' => 1, 'size' => 10]
    ];

    $searchResponse = $client->search('my-engine', 'search text', $searchParams);

If you want to match all documents you can use and empty search query '' as second parameter ($queryText).

The $searchRequestParams parameter is optional and can be used to use advanced search features. Allowed params are :

Param name Documentation URL
page https://swiftype.com/documentation/app-search/api/search#paging
filters https://swiftype.com/documentation/app-search/api/search/filters
facets https://swiftype.com/documentation/app-search/api/search/facets
sort https://swiftype.com/documentation/app-search/api/search/sorting
boosts https://swiftype.com/documentation/app-search/api/search/boosts
search_fields https://swiftype.com/documentation/app-search/api/search/search-fields
result_fields https://swiftype.com/documentation/app-search/api/search/result-fields
group https://swiftype.com/documentation/app-search/api/search/grouping

The search response will contains at least a meta field and a results field as shown in this example:

[
    'meta' => [
      'warnings' => [],
      'page' => [
        'current' => 1,
        'total_pages' => 1,
        'total_results' => 1,
        'size' => 10
      ],
      'request_id' => 'feff7cf2359a6f6da84586969ef0ca89'
    ],
    'results' => [
      [
        'id' => ['raw' => 'first-document'],
        'name' => ['raw' => 'Document name'],
        'description' => ['raw' => ['Document description']
      ]
    ]
  ]
]

Clients methods

Method Description Documentation
createEngine Creates a new engine.

Parameters :
- $name (required)
- $language
Endpoint Documentation
createMetaEngine Creates a new meta engine.

Parameters :
- $name (required)
- $sourceEngines (required)
Endpoint Documentation
addMetaEngineSource Add a source engine to an existing meta engine.

Parameters :
- $engineName (required)
- $sourceEngines (required)
Endpoint Documentation
createCuration Create a new curation.

Parameters :
- $engineName (required)
- $queries (required)
- $promotedDocIds
- $hiddenDocIds
Endpoint Documentation
createSynonymSet Create a new synonym set.

Parameters :
- $engineName (required)
- $synonyms (required)
Endpoint Documentation
deleteCuration Delete a curation by id.

Parameters :
- $engineName (required)
- $curationId (required)
Endpoint Documentation
deleteDocuments Delete documents by id.

Parameters :
- $engineName (required)
- $documentIds (required)
Endpoint Documentation
deleteEngine Delete an engine by name.

Parameters :
- $engineName (required)
Endpoint Documentation
deleteMetaEngineSource Delete a source engine from a meta engine.

Parameters :
- $engineName (required)
- $sourceEngines (required)
Endpoint Documentation
deleteSynonymSet Delete a synonym set by id.

Parameters :
- $engineName (required)
- $synonymSetId (required)
Endpoint Documentation
getApiLogs The API Log displays API request and response data at the Engine level.

Parameters :
- $engineName (required)
- $fromDate (required)
- $toDate (required)
- $currentPage
- $pageSize
- $query
- $httpStatusFilter
- $httpMethodFilter
- $sortDirection
Endpoint Documentation
getCountAnalytics Returns the number of clicks and total number of queries over a period.

Parameters :
- $engineName (required)
- $filters
- $interval
Endpoint Documentation
getCuration Retrieve a curation by id.

Parameters :
- $engineName (required)
- $curationId (required)
Endpoint Documentation
getDocuments Retrieves one or more documents by id.

Parameters :
- $engineName (required)
- $documentIds (required)
Endpoint Documentation
getEngine Retrieves an engine by name.

Parameters :
- $engineName (required)
Endpoint Documentation
getSchema Retrieve current schema for then engine.

Parameters :
- $engineName (required)
Endpoint Documentation
getSearchSettings Retrive current search settings for the engine.

Parameters :
- $engineName (required)
Endpoint Documentation
getSynonymSet Retrieve a synonym set by id.

Parameters :
- $engineName (required)
- $synonymSetId (required)
Endpoint Documentation
getTopClicksAnalytics Returns the number of clicks received by a document in descending order.

Parameters :
- $engineName (required)
- $query
- $pageSize
- $filters
Endpoint Documentation
getTopQueriesAnalytics Returns queries anlaytics by usage count.

Parameters :
- $engineName (required)
- $pageSize
- $filters
Endpoint Documentation
indexDocuments Create or update documents.

Parameters :
- $engineName (required)
- $documents (required)
Endpoint Documentation
listCurations Retrieve available curations for the engine.

Parameters :
- $engineName (required)
- $currentPage
- $pageSize
Endpoint Documentation
listDocuments List all available documents with optional pagination support.

Parameters :
- $engineName (required)
- $currentPage
- $pageSize
Endpoint Documentation
listEngines Retrieves all engines with optional pagination support.

Parameters :
- $currentPage
- $pageSize
Endpoint Documentation
listSynonymSets Retrieve available synonym sets for the engine.

Parameters :
- $engineName (required)
- $currentPage
- $pageSize
Endpoint Documentation
logClickthrough Send data about clicked results.

Parameters :
- $engineName (required)
- $queryText (required)
- $documentId (required)
- $requestId
- $tags
Endpoint Documentation
multiSearch Run several search in the same request.

Parameters :
- $engineName (required)
- $queries (required)
Endpoint Documentation
querySuggestion Provide relevant query suggestions for incomplete queries.

Parameters :
- $engineName (required)
- $query (required)
- $fields
- $size
Endpoint Documentation
resetSearchSettings Reset search settings for the engine.

Parameters :
- $engineName (required)
Endpoint Documentation
search Allows you to search over, facet and filter your data.

Parameters :
- $engineName (required)
- $queryText (required)
- $searchRequestParams
Endpoint Documentation
updateCuration Update an existing curation.

Parameters :
- $engineName (required)
- $curationId (required)
- $queries (required)
- $promotedDocIds
- $hiddenDocIds
Endpoint Documentation
updateDocuments Partial update of documents.

Parameters :
- $engineName (required)
- $documents (required)
Endpoint Documentation
updateSchema Update schema for the current engine.

Parameters :
- $engineName (required)
- $schema (required)
Endpoint Documentation
updateSearchSettings Update search settings for the engine.

Parameters :
- $engineName (required)
- $searchSettings (required)
Endpoint Documentation

Development

Code for the endpoints is generated automatically using a custom version of OpenAPI Generator.

To regenerate endpoints, use the docker laucher packaged in vendor/bin:

./vendor/bin/elastic-openapi-codegen.sh

The custom generator will be built and launched using the following Open API spec file : resources/api/api-spec.yml.

You can then commit and PR the modified api-spec file and your endpoints code files.

The client class and readme may be changed in some cases. Do not forget to include them in your commit!

FAQ 🔮

Where do I report issues with the client?

If something is not working as expected, please open an issue.

Where can I find the full API documentation ?

Your best bet is to read the documentation.

Where else can I go to get help?

You can checkout the Elastic community discuss forums.

Contribute 🚀

We welcome contributors to the project. Before you begin, a couple notes...

License 📗

Apache 2.0 © Elastic

Thank you to all the contributors!

app-search-php's People

Contributors

afoucret avatar andsel avatar goodroot avatar jasonstoltz avatar kaioken avatar miiimooo avatar richkuz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

app-search-php's Issues

Add meta engine support

  • OpenAPI codegen update
  • Update OpenAPI spec & generate new endpoint
  • Test against App Search 7.6 (manual test only since a platinum license is required for this feature).

Flaky document test in PHP client CI integration

One time, I observed a failure in the PHP CI test, DocumentApiTest::testDeleteDocuments(). sleeping for 1 second isn't consistently long enough.

It's possible that similar flaky results could occur in other tests in this class that rely on sleep.

We could increase the sleep time from 1 to 10, for example.

Or, we could write the tests in a way that poll for n seconds (e.g. 10) until the expected condition is met.

How to free disk space for enterprise search ?

Hi, I'm currently facing an issue and I don't really know how to fix it. Recently, my script for updating my engines is returning errors while I'm trying to delete/update documents on my engines. I saw into logs the current errors messages that keeps repeating itself everytime a new action is ran :

Exception: Exception while performing Work::Cron::RefreshFritoPieContentSources.perform()!: Swiftype::ES::ReadOnlyModeWriteError: index [.ent-search-db-lock] blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block];

It looks like App search is putting my indexes in readonly due to a small amount of disk space.

I've seen online that there are some command lines :
curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}

but these are for ElasticSearch, so I don't know if I can use it here as App-search uses ElasticSearch too...

Thank you

Fix CI for release 7.7.0

The default username has changed from app_search to enterprise_search from release 7.7.0.

TODO:

  • The CI config need to be fixed to reflect this change.

PHP 5.5 support

Does the App Search client have parts which makes it unusable for PHP 5.5? If not, would it be possible to add PHP 5.5 support to composer?

The reason for this request is that Ubuntu servers which still run PHP 5 often supports PHP 5.5.9, but not PHP 5.6 while connecting to App Search through this package can still come in handy.

I could create a pull request if this request is supported.

No method to update Synonym sets

The documentation specifies an endpoint to update a synonym set. But that endpoint is missing on the client.

This seems to have been brought up already in #18 but the PR got closed for some reason.

Are there any plans to add it?

PHP 8 support

Hi there, it would be really usefull that this SDK supports PHP 8

Http Proxy

Currently, as far as I have seen there is no way to set an HTTP proxy. If there already is a way we should document that!

I would be open to adding this functionality, but we should discuss how the API should look.
Any Ideas? I think a setProxy and getProxy method on the ClientBuilder should work

PHP 8 Support

Hi!
I am wondering if php 8 support is planned in near future? It is the last library in our project which stops us to get the latest php version.

Kind regards,
Artur Faller

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.