1
<?php
2

3
/*
4
 * This file is part of the Solarium package.
5
 *
6
 * For the full copyright and license information, please view the COPYING
7
 * file that was distributed with this source code.
8
 */
9

10
namespace Solarium\Component\Facet;
11

12
use Solarium\Component\FacetSetInterface;
13

14
/**
15
 * Facet interval.
16
 *
17
 * @see https://lucene.apache.org/solr/guide/faceting.html#interval-faceting
18
 */
19
class Interval extends AbstractFacet
20
{
21
    /**
22
     * Get the facet type.
23
     *
24
     * @return string
25
     */
26 12
    public function getType(): string
27
    {
28 12
        return FacetSetInterface::FACET_INTERVAL;
29
    }
30

31
    /**
32
     * Set the field name.
33
     *
34
     * @param string $field
35
     *
36
     * @return self Provides fluent interface
37
     */
38 12
    public function setField(string $field): self
39
    {
40 12
        $this->setOption('field', $field);
41

42 12
        return $this;
43
    }
44

45
    /**
46
     * Get the field name.
47
     *
48
     * @return string|null
49
     */
50 12
    public function getField(): ?string
51
    {
52 12
        return $this->getOption('field');
53
    }
54

55
    /**
56
     * Set set counts.
57
     *
58
     * Use one of the constants as value.
59
     * If you want to use multiple values supply an array or comma separated string
60
     *
61
     * @param string|array $set
62
     *
63
     * @return self Provides fluent interface
64
     */
65 12
    public function setSet($set): self
66
    {
67 12
        if (\is_string($set)) {
68 12
            $set = explode(',', $set);
69 12
            $set = array_map('trim', $set);
70
        }
71

72 12
        $this->setOption('set', $set);
73

74 12
        return $this;
75
    }
76

77
    /**
78
     * Get set counts.
79
     *
80
     * @return array
81
     */
82 12
    public function getSet(): array
83
    {
84 12
        $set = $this->getOption('set');
85 12
        if (null === $set) {
86 12
            $set = [];
87
        }
88

89 12
        return $set;
90
    }
91

92
    /**
93
     * Initialize options.
94
     *
95
     * Several options need some extra checks or setup work, for these options
96
     * the setters are called.
97
     */
98 12
    protected function init()
99
    {
100 12
        foreach ($this->options as $name => $value) {
101
            switch ($name) {
102 12
                case 'set':
103 12
                    $this->setSet($value);
104 12
                    break;
105
            }
106
        }
107
    }
108
}

Read our documentation on viewing source code .

Loading