sjaakmoes/elasticsearch-langdetect-php

Langdetect namespace for Elasticsearch-PHP

1.0.0 2015-09-30 09:03 UTC

This package is not auto-updated.

Last update: 2024-04-17 08:35:09 UTC


README

This module adds endpoints to the Elasticsearch-PHP library when you are using the elasticsearch-langdetect plugin.

Installation

This module can be installed with Composer. Add the elasticsearch-langdetect-php package to your composer.json file:

{
    "require": {
        "sjaakmoes/elasticsearch-langdetect-php": "~1.0"
    }
}

After the module is installed through composer, we need to inject this module into the Elasticsearch-PHP library:

$params = [
    'host'              => ['localhost:9200'],
    'customNamespaces'  => [
        'langdetect'    => 'Langdetect\LangdetectNamespace'
    ]
];
$client = new Elasticsearch\Client($params);

Use

Language detection:

// Detect
$params = [
    'content'   => 'This is a sample text.'
];
$response = $client->langdetect()->detect($params);

The $response holds an array which looks like:

Array
(
    [profile] => /langdetect/
    [languages] => Array
        (
            [0] => Array
                (
                    [language] => en
                    [probability] => 0.9999959428847
                )

        )

)