Passed
Push — master ( eff61e...76df74 )
by Gordon
02:24
created

Index::setTokenizer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 24/3/2561
7
 * Time: 20:27 น.
8
 */
9
10
namespace Suilven\FreeTextSearch;
11
12
use Suilven\FreeTextSearch\Types\LanguageTypes;
13
use Suilven\FreeTextSearch\Types\TokenizerTypes;
14
15
class Index
16
{
17
    /** @var string|null the name of the class to index, with namespace */
18
    private $clazz = null;
19
20
    /** @var array<string> names of fields */
21
    private $fields = [];
22
23
    /** @var array<string> names of stored fields */
24
    private $storedFields = [];
25
26
    /** @var array<string> names of tokens */
27
    private $tokens = [];
28
29
    /** @var array<string> names of has one fields */
30
    private $hasOneFields = [];
31
32
    /** @var array<string,array<string,string>> names of has many fields */
33
    private $hasManyFields = [];
34
35
    /** @var array<string> names of highlighted fields */
36
    private $highlightedFields = [];
37
38
    /** @var string the name of the index */
39
    private $name;
40
41
    /** @var string the tokenizer flag */
42
    private $tokenizer = TokenizerTypes::NONE;
43
44
    // @TODO allow for multiple languages?
45
46
    /** @var string the language code */
47
    private $language = LanguageTypes::ENGLISH;
48
49
    public function getName(): string
50
    {
51
        return $this->name;
52
    }
53
54
55
    public function setName(string $name): void
56
    {
57
        $this->name = $name;
58
    }
59
60
61
    public function setClass(?string $clazz): void
62
    {
63
        $this->clazz = $clazz;
64
    }
65
66
67
    public function getClass(): ?string
68
    {
69
        return $this->clazz;
70
    }
71
72
73
    /** @return array<string> */
74
    public function getFields(): array
75
    {
76
        return $this->fields;
77
    }
78
79
80
    /** @return array<string> */
81
    public function getStoredFields(): array
82
    {
83
        return $this->storedFields;
84
    }
85
86
87
    /** @return array<string> */
88
    public function getHighlightedFields(): array
89
    {
90
        return $this->highlightedFields;
91
    }
92
93
94
    /** @return array<string> */
95
    public function getHasOneFields(): array
96
    {
97
        return $this->hasOneFields;
98
    }
99
100
101
    /** @return array<string,array<string,string>> */
102
    public function getHasManyFields(): array
103
    {
104
        return $this->hasManyFields;
105
    }
106
107
108
    /** @return array<string> */
109
    public function getTokens(): array
110
    {
111
        return $this->tokens;
112
    }
113
114
115
    public function getTokenizer(): string
116
    {
117
        return $this->tokenizer;
118
    }
119
120
121
    public function getLanguage(): string
122
    {
123
        return $this->language;
124
    }
125
126
127
    /**
128
     * Add a full text fieldname to the index
129
     *
130
     * @param string $fieldName the name of the field to index
131
     */
132
    public function addField(string $fieldName): void
133
    {
134
        $this->fields[] = $fieldName;
135
    }
136
137
138
    /**
139
     * Register a field to be used for the purposes of highlighting
140
     *
141
     * @param string $fieldName the name of the field to index
142
     */
143
    public function addHighlightedField(string $fieldName): void
144
    {
145
        $this->highlightedFields[] = $fieldName;
146
    }
147
148
149
    /**
150
     * Add a stored field to the index. This is not indexed for free text search, but it used for convenience when
151
     * rendering search results. e.g. the thumbnail URL for a third party image service
152
     *
153
     * @param string $fieldName the name of the field to index
154
     */
155
    public function addStoredField(string $fieldName): void
156
    {
157
        $this->storedFields[] = $fieldName;
158
    }
159
160
161
    /**
162
     * Add a has one field to the index
163
     *
164
     * @param string $fieldName the name of the has one field to index
165
     */
166
    public function addHasOneField(string $fieldName): void
167
    {
168
        $this->hasOneFields[] = $fieldName;
169
    }
170
171
172
    /**
173
     * Add a has many to the index
174
     *
175
     * @param string $name the name of the has many field to index
176
     * @param array<string,string> $relationshipNameAndValueField
177
     */
178
    public function addHasManyField(string $name, array $relationshipNameAndValueField): void
179
    {
180
        $this->hasManyFields[$name] = $relationshipNameAndValueField ;
181
    }
182
183
184
    /**
185
     * Add a token to the index - not full text searchable but filterable and facetable
186
     *
187
     * @param string $token the name of the field to index
188
     */
189
    public function addToken(string $token): void
190
    {
191
        $this->tokens[] = $token;
192
    }
193
194
195
    public function setTokenizer(string $newTokenizer): void
196
    {
197
        $this->tokenizer = $newTokenizer;
198
    }
199
}
200