Initial commit
This commit is contained in:
58
app/Http/Controllers/SearchIndexController.php
Normal file
58
app/Http/Controllers/SearchIndexController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Elastic\Elasticsearch\ClientBuilder;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class SearchIndexController extends Controller
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = ClientBuilder::create()->build();
|
||||
}
|
||||
|
||||
|
||||
public function indexStopwords($indexName)
|
||||
{
|
||||
$stopwords = timebank_config('elasticsearch.stopwords');
|
||||
|
||||
$settings = [
|
||||
'analysis' => [
|
||||
'analyzer' => [
|
||||
'my_custom_analyzer' => [
|
||||
'type' => 'standard',
|
||||
'stopwords' => $stopwords
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// Create the index
|
||||
$params = [
|
||||
'index' => $indexName,
|
||||
'body' => [
|
||||
'settings' => $settings,
|
||||
// other index settings...
|
||||
]
|
||||
];
|
||||
|
||||
$response = $this->client->indices()->create($params);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
public function deleteIndex($indexName)
|
||||
{
|
||||
$client = ClientBuilder::create()->build();
|
||||
$params = ['index' => $indexName,
|
||||
'alias' => $indexName];
|
||||
$response = $client->indices()->delete($params);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user