Passed
Push — master ( 3dc1a3...8beebe )
by Gordon
05:38 queued 03:19
created

Index::addHighlightedField()   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
class Index
13
{
14
    /** @var string|null the name of the class to index, with namespace */
15
    private $clazz = null;
16
17
    /** @var array<string> names of fields */
18
    private $fields = [];
19
20
    /** @var array<string> names of stored fields */
21
    private $storedFields = [];
22
23
    /** @var array<string> names of tokens */
24
    private $tokens = [];
25
26
    /** @var array<string> names of has one fields */
27
    private $hasOneFields = [];
28
29
    /** @var array<string,array<string,string>> names of has many fields */
30
    private $hasManyFields = [];
31
32
    /** @var array<string> names of highlighted fields */
33
    private $highlightedFields = [];
34
35
    /** @var string the name of the index */
36
    private $name;
37
38
    public function getName(): string
39
    {
40
        return $this->name;
41
    }
42
43
44
    public function setName(string $name): void
45
    {
46
        $this->name = $name;
47
    }
48
49
50
    public function setClass(?string $clazz): void
51
    {
52
        $this->clazz = $clazz;
53
    }
54
55
56
    public function getClass(): ?string
57
    {
58
        return $this->clazz;
59
    }
60
61
62
    /** @return array<string> */
63
    public function getFields(): array
64
    {
65
        return $this->fields;
66
    }
67
68
69
    /** @return array<string> */
70
    public function getStoredFields(): array
71
    {
72
        return $this->storedFields;
73
    }
74
75
76
    /** @return array<string> */
77
    public function getHighlightedFields(): array
78
    {
79
        return $this->highlightedFields;
80
    }
81
82
83
    /** @return array<string> */
84
    public function getHasOneFields(): array
85
    {
86
        return $this->hasOneFields;
87
    }
88
89
90
    /** @return array<string,array<string,string>> */
91
    public function getHasManyFields(): array
92
    {
93
        return $this->hasManyFields;
94
    }
95
96
97
    /** @return array<string> */
98
    public function getTokens(): array
99
    {
100
        return $this->tokens;
101
    }
102
103
104
    /**
105
     * Add a full text fieldname to the index
106
     *
107
     * @param string $fieldName the name of the field to index
108
     */
109
    public function addField(string $fieldName): void
110
    {
111
        $this->fields[] = $fieldName;
112
    }
113
114
115
    /**
116
     * Register a field to be used for the purposes of highlighting
117
     *
118
     * @param string $fieldName the name of the field to index
119
     */
120
    public function addHighlightedField(string $fieldName): void
121
    {
122
        $this->highlightedFields[] = $fieldName;
123
    }
124
125
126
    /**
127
     * Add a stored field to the index. This is not indexed for free text search, but it used for convenience when
128
     * rendering search results. e.g. the thumbnail URL for a third party image service
129
     *
130
     * @param string $fieldName the name of the field to index
131
     */
132
    public function addStoredField(string $fieldName): void
133
    {
134
        $this->storedFields[] = $fieldName;
135
    }
136
137
138
    /**
139
     * Add a has one field to the index
140
     *
141
     * @param string $fieldName the name of the has one field to index
142
     */
143
    public function addHasOneField(string $fieldName): void
144
    {
145
        $this->hasOneFields[] = $fieldName;
146
    }
147
148
149
    /**
150
     * Add a has many to the index
151
     *
152
     * @param string $name the name of the has many field to index
153
     * @param array<string,string> $relationshipNameAndValueField
154
     */
155
    public function addHasManyField(string $name, array $relationshipNameAndValueField): void
156
    {
157
        $this->hasManyFields[$name] = $relationshipNameAndValueField ;
158
    }
159
160
161
    /**
162
     * Add a token to the index - not full text searchable but filterable and facetable
163
     *
164
     * @param string $token the name of the field to index
165
     */
166
    public function addToken(string $token): void
167
    {
168
        $this->tokens[] = $token;
169
    }
170
}
171