Skip to content

Commit

Permalink
Formatting, removed deprecated code, renamed es to elasticsearch wher…
Browse files Browse the repository at this point in the history
…e possible
  • Loading branch information
Radiergummi committed May 14, 2024
1 parent a9eb07e commit e7defc3
Show file tree
Hide file tree
Showing 34 changed files with 2,586 additions and 2,594 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ If you haven't already, make Lumen work with facades by uncommenting this line i
$app->withFacades();
```

If you don't want to enable facades in Lumen, you can access the query builder using `app("es")`:
If you don't want to enable facades in Lumen, you can access the query builder using `app("elasticsearch")`:
```php
app("es")->index("my_index")->type("my_type")->get();
app("elasticsearch")->index("my_index")->type("my_type")->get();

# This is similar to:
ES::index("my_index")->type("my_type")->get();
Expand Down Expand Up @@ -327,11 +327,11 @@ Usage as a Laravel Scout driver
First, follow [Laravel Scout installation](https://laravel.com/docs/8.0/scout#installation).
All you have to do is updating the following lines in `config/scout.php`:
```php
# change the default driver to 'es'
'driver' => env('SCOUT_DRIVER', 'es'),
# change the default driver to 'elasticsearch'
'driver' => env('SCOUT_DRIVER', 'elasticsearch'),

# link `es` driver with default elasticsearch connection in config/es.php
'es' => [
# link `elasticsearch` driver with default elasticsearch connection in config/es.php
'elasticsearch' => [
'connection' => env('ELASTIC_CONNECTION', 'default'),
],
```
Expand Down
6 changes: 3 additions & 3 deletions config/scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
| using Laravel Scout. This connection is used when syncing all models
| to the search service. You should adjust this based on your needs.
|
| Supported: "es", "algolia", "null"
| Supported: "elasticsearch", "algolia", "null"
|
*/
'driver' => env('SCOUT_DRIVER', 'es'),
'driver' => env('SCOUT_DRIVER', 'elasticsearch'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -55,7 +55,7 @@
'secret' => env('ALGOLIA_SECRET', ''),
],

'es' => [
'elasticsearch' => [
'connection' => env('ELASTIC_CONNECTION', 'default'),
],
];
158 changes: 79 additions & 79 deletions src/Classes/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Bulk
public string|null $type = null;

/**
* @param Query $query
* @param Query $query
* @param int|null $autocommitAfter
*/
public function __construct(Query $query, int|null $autocommitAfter = null)
Expand All @@ -74,24 +74,30 @@ public function __construct(Query $query, int|null $autocommitAfter = null)
}

/**
* Filter by _id
*
* @param string|null $_id
* Get Bulk body
*
* @return $this
* @return array
*/
public function _id(string|null $_id = null): self
public function body(): array
{
$this->_id = $_id;
return $this->body;
}

return $this;
/**
* Add pending document for deletion
*
* @return bool
*/
public function delete(): bool
{
return $this->action('delete');
}

/**
* Add pending document abstract action
*
* @param string $actionType
* @param array $data
* @param array $data
*
* @return bool
*/
Expand All @@ -105,7 +111,7 @@ public function action(string $actionType, array $data = []): bool
],
];

if ( ! empty($data)) {
if (!empty($data)) {
$this->body['body'][] = $actionType === 'update'
? ['doc' => $data]
: $data;
Expand All @@ -126,13 +132,68 @@ public function action(string $actionType, array $data = []): bool
}

/**
* Get Bulk body
* Get the index name
*
* @return array
* @return string|null
*/
public function body(): array
protected function getIndex(): string|null
{
return $this->body;
return $this->index ?: $this->query->getIndex();
}

/**
* Get the type name
*
* @return string|null
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
protected function getType(): string|null
{
return $this->type ?: $this->query->getType();
}

/**
* Reset names
*
* @return void
*/
public function reset(): void
{
$this->index();
$this->type();
}

/**
* Set the index name
*
* @param string|null $index
*
* @return $this
*/
public function index(string|null $index = null): self
{
$this->index = $index;

return $this;
}

/**
* Set the type name
*
* @param string|null $type
*
* @return $this
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
public function type(string|null $type = null): self
{
$this->type = $type;

return $this;
}

/**
Expand All @@ -158,16 +219,6 @@ public function commit(): ?array
return $result;
}

/**
* Add pending document for deletion
*
* @return bool
*/
public function delete(): bool
{
return $this->action('delete');
}

/**
* Just an alias for _id() method
*
Expand All @@ -181,15 +232,15 @@ public function id(string|null $_id = null): self
}

/**
* Set the index name
* Filter by _id
*
* @param string|null $index
* @param string|null $_id
*
* @return $this
*/
public function index(string|null $index = null): self
public function _id(string|null $_id = null): self
{
$this->index = $index;
$this->_id = $_id;

return $this;
}
Expand All @@ -206,34 +257,6 @@ public function insert(array $data = []): bool
return $this->action('index', $data);
}

/**
* Reset names
*
* @return void
*/
public function reset(): void
{
$this->index();
$this->type();
}

/**
* Set the type name
*
* @param string|null $type
*
* @return $this
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
public function type(string|null $type = null): self
{
$this->type = $type;

return $this;
}

/**
* Add pending document for update
*
Expand All @@ -245,27 +268,4 @@ public function update(array $data = []): bool
{
return $this->action('update', $data);
}

/**
* Get the index name
*
* @return string|null
*/
protected function getIndex(): string|null
{
return $this->index ?: $this->query->getIndex();
}

/**
* Get the type name
*
* @return string|null
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
protected function getType(): string|null
{
return $this->type ?: $this->query->getType();
}
}
4 changes: 2 additions & 2 deletions src/Classes/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class Search
protected $settings;

/**
* @param Query $query
* @param string $queryString
* @param Query $query
* @param string $queryString
* @param callable|array|null $settings
*/
public function __construct(
Expand Down
Loading

0 comments on commit e7defc3

Please sign in to comment.