Conditions | 18 |
Paths | 742 |
Total Lines | 146 |
Code Lines | 79 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types = 1); |
||
28 | public function createIndex(string $indexName): void |
||
29 | { |
||
30 | $fields = $this->getFields($indexName); |
||
31 | $storedFields = $this->getStoredFields($indexName); |
||
32 | $specs = $this->getFieldSpecs($indexName); |
||
33 | |||
34 | \error_log('SPECS'); |
||
35 | \print_r($specs); |
||
36 | |||
37 | $columns = []; |
||
38 | foreach ($fields as $field) { |
||
39 | /* |
||
40 | if ($field === 'Link') { |
||
41 | error_log('Skipping link field'); |
||
42 | continue; |
||
43 | } |
||
44 | */ |
||
45 | |||
46 | // this will be the most common |
||
47 | $indexType = 'text'; |
||
48 | $options = []; |
||
49 | |||
50 | if (isset($specs[$field])) { |
||
51 | $fieldType = $specs[$field]; |
||
52 | |||
53 | // @todo configure index to strip HTML |
||
54 | switch ($fieldType) { |
||
55 | case FieldTypes::FOREIGN_KEY: |
||
56 | // @todo this perhaps needs to be a token |
||
57 | // See https://docs.manticoresearch.com/3.4.0/html/indexing/data_types.html |
||
58 | |||
59 | // @todo also how to mark strings for tokenizing? |
||
60 | $indexType = 'bigint'; |
||
61 | |||
62 | break; |
||
63 | case FieldTypes::INTEGER: |
||
64 | $indexType = 'integer'; |
||
65 | |||
66 | break; |
||
67 | case FieldTypes::FLOAT: |
||
68 | $indexType = 'float'; |
||
69 | |||
70 | break; |
||
71 | case FieldTypes::TIME: |
||
72 | $indexType = 'timestamp'; |
||
73 | |||
74 | break; |
||
75 | case FieldTypes::BOOLEAN: |
||
76 | // @todo is there a better type? |
||
77 | $indexType = 'integer'; |
||
78 | |||
79 | break; |
||
80 | } |
||
81 | |||
82 | if ($indexType === 'text') { |
||
83 | $options = ['indexed', 'stored']; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | |||
88 | // override for Link, do not index it. The storing of the Link URL is to save on database hierarchy |
||
89 | // traversal when rendering search results |
||
90 | //if ($field === 'Link' || \in_array($field, $storedFields, true)) { |
||
91 | if ($field === 'Link') { |
||
92 | $indexType = 'text'; |
||
93 | $options = ['stored']; |
||
94 | } |
||
95 | |||
96 | if (\in_array($field, $storedFields, true)) { |
||
97 | $options = ['stored']; |
||
98 | } |
||
99 | $columns[$field] = ['type' => $indexType, 'options' => $options]; |
||
100 | } |
||
101 | |||
102 | |||
103 | // @todo Add has one |
||
104 | |||
105 | $indexes = new Indexes(); |
||
106 | $index = $indexes->getIndex($indexName); |
||
107 | $mvaFields = $index->getHasManyFields(); |
||
108 | |||
109 | \error_log(\print_r($mvaFields, true)); |
||
110 | |||
111 | foreach (\array_keys($mvaFields) as $mvaColumnName) { |
||
112 | $columns[$mvaColumnName] = ['type' => 'multi']; |
||
113 | } |
||
114 | |||
115 | $client = new Client(); |
||
116 | $manticoreClient = $client->getConnection(); |
||
117 | |||
118 | $settings = [ |
||
119 | 'rt_mem_limit' => '256M', |
||
120 | 'dict' => 'keywords', |
||
121 | 'min_infix_len' => 2, |
||
122 | 'html_strip' => 1, |
||
123 | 'bigram_index' => 'all', |
||
124 | ]; |
||
125 | |||
126 | $manticoreTokenizer = null; |
||
127 | |||
128 | // @todo this may need refactored |
||
129 | $manticoreLanguage = $index->getLanguage(); |
||
130 | |||
131 | $tokenizer = $index->getTokenizer(); |
||
132 | if ($tokenizer !== TokenizerTypes::NONE) { |
||
133 | switch ($tokenizer) { |
||
134 | case TokenizerTypes::PORTER: |
||
135 | $manticoreTokenizer = 'porter'; |
||
136 | |||
137 | break; |
||
138 | case TokenizerTypes::SNOWBALL: |
||
139 | $manticoreTokenizer = 'snowball'; |
||
140 | |||
141 | break; |
||
142 | case TokenizerTypes::METAPHONE: |
||
143 | $manticoreTokenizer = 'metaphone'; |
||
144 | |||
145 | break; |
||
146 | case TokenizerTypes::SOUNDEX: |
||
147 | $manticoreTokenizer = 'soundex'; |
||
148 | |||
149 | break; |
||
150 | case TokenizerTypes::LEMMATIZER: |
||
151 | $manticoreTokenizer = 'lemmatizer'; |
||
152 | $settings['lemmatizer_base'] = '/usr/local/share'; |
||
153 | |||
154 | break; |
||
155 | } |
||
156 | |||
157 | $settings['morphology'] = $this->getMorphology($manticoreTokenizer, $manticoreLanguage); |
||
158 | } |
||
159 | |||
160 | |||
161 | // drop index, and updating an existing one does not effect change |
||
162 | $manticoreClient->indices()->drop(['index' => $indexName, 'body'=>['silent'=>true]]); |
||
163 | |||
164 | |||
165 | $manticoreIndex = new \Manticoresearch\Index($manticoreClient, $indexName); |
||
166 | |||
167 | \error_log('----- payload -----'); |
||
168 | \error_log(\print_r($columns, true)); |
||
169 | |||
170 | $manticoreIndex->create( |
||
171 | $columns, |
||
172 | $settings, |
||
173 | true |
||
174 | ); |
||
215 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths