Optimize::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Solr Client Symfony package.
7
 *
8
 * (c) ingatlan.com Zrt. <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace iCom\SolrClient\Query\Command;
15
16
use iCom\SolrClient\JsonHelper;
17
use iCom\SolrClient\Query\Command;
18
19
/**
20
 * @see https://lucene.apache.org/solr/guide/8_3/uploading-data-with-index-handlers.html#commit-and-optimize-during-updates
21
 *
22
 * @psalm-immutable
23
 */
24
final class Optimize implements Command
25
{
26
    use JsonHelper;
27
28
    /**
29
     * @psalm-var array{maxSegments: ?int, waitSearcher: ?bool}
30
     */
31
    private array $options = [
32
        'waitSearcher' => null,
33
        'maxSegments' => null,
34
    ];
35
36
    /**
37
     * @psalm-pure
38
     */
39
    public static function create(): self
40
    {
41
        return new self();
42
    }
43
44
    public function enableWaitSearcher(): self
45
    {
46
        $commit = clone $this;
47
        $commit->options['waitSearcher'] = true;
48
49
        return $commit;
50
    }
51
52
    public function disableWaitSearcher(): self
53
    {
54
        $commit = clone $this;
55
        $commit->options['waitSearcher'] = false;
56
57
        return $commit;
58
    }
59
60
    public function maxSegments(int $maxSegments): self
61
    {
62
        $commit = clone $this;
63
        $commit->options['maxSegments'] = $maxSegments;
64
65
        return $commit;
66
    }
67
68
    public function toJson(): string
69
    {
70
        return self::jsonEncode(array_filter($this->options, static function ($option): bool { return null !== $option; }), JSON_FORCE_OBJECT);
71
    }
72
73
    public function getName(): string
74
    {
75
        return 'optimize';
76
    }
77
}
78