Conditions | 11 |
Paths | 50 |
Total Lines | 92 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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); |
||
25 | public function createIndex(string $indexName): void |
||
26 | { |
||
27 | $fields = $this->getFields($indexName); |
||
28 | $storedFields = $this->getStoredFields($indexName); |
||
29 | $specs = $this->getFieldSpecs($indexName); |
||
30 | |||
31 | \error_log('SPECS'); |
||
32 | \print_r($specs); |
||
33 | |||
34 | $columns = []; |
||
35 | foreach ($fields as $field) { |
||
36 | $fieldType = $specs[$field]; |
||
37 | |||
38 | // this will be the most common |
||
39 | $indexType = 'text'; |
||
40 | |||
41 | // @todo configure index to strip HTML |
||
42 | switch ($fieldType) { |
||
43 | case FieldTypes::FOREIGN_KEY: |
||
44 | // @todo this perhaps needs to be a token |
||
45 | // See https://docs.manticoresearch.com/3.4.0/html/indexing/data_types.html |
||
46 | |||
47 | // @todo also how to mark strings for tokenizing? |
||
48 | $indexType = 'bigint'; |
||
49 | |||
50 | break; |
||
51 | case FieldTypes::INTEGER: |
||
52 | $indexType = 'integer'; |
||
53 | |||
54 | break; |
||
55 | case FieldTypes::FLOAT: |
||
56 | $indexType = 'float'; |
||
57 | |||
58 | break; |
||
59 | case FieldTypes::TIME: |
||
60 | $indexType = 'timestamp'; |
||
61 | |||
62 | break; |
||
63 | case FieldTypes::BOOLEAN: |
||
64 | // @todo is there a better type? |
||
65 | $indexType = 'integer'; |
||
66 | |||
67 | break; |
||
68 | } |
||
69 | |||
70 | $options = []; |
||
71 | if ($indexType === 'text') { |
||
72 | $options = ['indexed', 'stored']; |
||
73 | } |
||
74 | |||
75 | // override for Link, do not index it. The storing of the Link URL is to save on database hierarchy |
||
76 | // traversal when rendering search results |
||
77 | if ($field === 'Link' || \in_array($field, $storedFields, true)) { |
||
78 | $options = ['stored']; |
||
79 | } |
||
80 | $columns[$field] = ['type' => $indexType, 'options' => $options]; |
||
81 | } |
||
82 | |||
83 | |||
84 | // @todo Add has one |
||
85 | |||
86 | $indexes = new Indexes(); |
||
87 | $index = $indexes->getIndex($indexName); |
||
88 | $mvaFields = $index->getHasManyFields(); |
||
89 | error_log(print_r($mvaFields, true)); |
||
90 | |||
91 | foreach(array_keys($mvaFields) as $mvaColumnName) { |
||
92 | $columns[$mvaColumnName] = ['type' => 'multi']; |
||
93 | } |
||
94 | |||
95 | $client = new Client(); |
||
96 | $manticoreClient = $client->getConnection(); |
||
97 | |||
98 | $settings = [ |
||
99 | 'rt_mem_limit' => '256M', |
||
100 | 'dict' => 'keywords', |
||
101 | 'min_infix_len' => 2, |
||
102 | 'html_strip' => 1, |
||
103 | 'bigram_index' => 'both_freq' |
||
104 | ]; |
||
105 | |||
106 | |||
107 | // drop index, and updating an existing one does not effect change |
||
108 | $manticoreClient->indices()->drop(['index' => $indexName, 'body'=>['silent'=>true]]); |
||
109 | |||
110 | |||
111 | $manticoreIndex = new \Manticoresearch\Index($manticoreClient, $indexName); |
||
112 | |||
113 | $manticoreIndex->create( |
||
114 | $columns, |
||
115 | $settings, |
||
116 | true |
||
117 | ); |
||
120 |