Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 81f8515

Browse files
committed
Added configure index command
- Can disable bundle commands - Fixed some existing commands
1 parent 58c9ebb commit 81f8515

File tree

10 files changed

+435
-13
lines changed

10 files changed

+435
-13
lines changed

.php_cs.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"7.1.12-1+ubuntu16.04.1+deb.sury.org+1","version":"2.13.0:v2.13.0#7136aa4e0c5f912e8af82383775460d906168a10","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"single_line":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"binary_operator_spaces":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"include":true,"increment_style":true,"lowercase_cast":true,"lowercase_static_reference":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"]},"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unneeded_curly_braces":true,"no_unneeded_final_method":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":{"tags":["method","param","property","return","throws","type","var"]},"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":true,"semicolon_after_instruction":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true},"hashes":{"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/ProductWriteTransformer.php":4090808924,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":1181469493,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":2186592420,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":4000035678,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":1623406226,"Translator\/AggregationTranslator.php":3471296845,"ApisearchBundle.php":3640212495,"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"Command\/ImportIndexCommand.php":1581740785,"Command\/CreateIndexCommand.php":3936840864,"Command\/ApisearchFormattedCommand.php":1606549717,"Command\/ResetIndexCommand.php":2081910409,"Command\/DeleteIndexCommand.php":2044175677,"Command\/ApisearchCommand.php":2188021223,"Command\/WithAppRepositoryBucketCommand.php":2106806880,"Command\/DeleteTokensCommand.php":1800041030,"Command\/AddTokenCommand.php":1932082409,"Command\/PrintTokensCommand.php":2376828112,"Command\/ExportIndexCommand.php":1321012391,"Command\/WithRepositoryBucketCommand.php":3882313592,"Command\/DeleteTokenCommand.php":3019199442,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":146592760,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/ApisearchConfiguration.php":3473367980,"DependencyInjection\/ApisearchExtension.php":1114385601}}
1+
{"php":"7.1.18-1+ubuntu18.04.1+deb.sury.org+1","version":"2.13.0:v2.13.0#7136aa4e0c5f912e8af82383775460d906168a10","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"single_line":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"binary_operator_spaces":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"include":true,"increment_style":true,"lowercase_cast":true,"lowercase_static_reference":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"]},"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unneeded_curly_braces":true,"no_unneeded_final_method":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":{"tags":["method","param","property","return","throws","type","var"]},"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":true,"semicolon_after_instruction":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true},"hashes":{"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":2061055336,"DependencyInjection\/ApisearchExtension.php":112225700,"DependencyInjection\/ApisearchConfiguration.php":2641313999,"ApisearchBundle.php":3640212495,"Translator\/AggregationTranslator.php":3471296845,"Command\/ExportIndexCommand.php":1321012391,"Command\/ImportIndexCommand.php":1581740785,"Command\/PrintTokensCommand.php":2376828112,"Command\/DeleteTokensCommand.php":1800041030,"Command\/ApisearchCommand.php":2188021223,"Command\/ConfigureIndexCommand.php":3302854000,"Command\/ApisearchFormattedCommand.php":1606549717,"Command\/AddTokenCommand.php":1932082409,"Command\/WithRepositoryBucketCommand.php":3882313592,"Command\/WithAppRepositoryBucketCommand.php":2106806880,"Command\/DeleteTokenCommand.php":3019199442,"Command\/CreateIndexCommand.php":3523765310,"Command\/DeleteIndexCommand.php":903943328,"Command\/ResetIndexCommand.php":2081910409,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2619843458,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":1623406226,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":1181469493,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":2186592420,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":4000035678,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":3159332468,"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/ProductWriteTransformer.php":4090808924}}

Command/ConfigureIndexCommand.php

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch Bundle.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Command;
17+
18+
use Apisearch\App\AppRepositoryBucket;
19+
use Apisearch\Config\Config;
20+
use Apisearch\Config\Synonym;
21+
use Apisearch\Config\SynonymReader;
22+
use Apisearch\Exception\ResourceNotAvailableException;
23+
use Apisearch\Model\IndexUUID;
24+
use Symfony\Component\Console\Input\InputArgument;
25+
use Symfony\Component\Console\Input\InputInterface;
26+
use Symfony\Component\Console\Input\InputOption;
27+
use Symfony\Component\Console\Output\OutputInterface;
28+
29+
/**
30+
* Class ConfigureIndexCommand.
31+
*/
32+
class ConfigureIndexCommand extends WithAppRepositoryBucketCommand
33+
{
34+
/**
35+
* @var SynonymReader
36+
*
37+
* Synonym Reader
38+
*/
39+
private $synonymReader;
40+
41+
/**
42+
* WithAppRepositoryBucketCommand constructor.
43+
*
44+
* @param AppRepositoryBucket $repositoryBucket
45+
* @param SynonymReader $synonymReader
46+
*/
47+
public function __construct(
48+
AppRepositoryBucket $repositoryBucket,
49+
SynonymReader $synonymReader
50+
) {
51+
parent::__construct($repositoryBucket);
52+
53+
$this->synonymReader = $synonymReader;
54+
}
55+
56+
/**
57+
* Configures the current command.
58+
*/
59+
protected function configure()
60+
{
61+
$this
62+
->setName('apisearch:configure-index')
63+
->setDescription('Configure an index')
64+
->addArgument(
65+
'app-name',
66+
InputArgument::REQUIRED,
67+
'App name'
68+
)
69+
->addArgument(
70+
'index',
71+
InputArgument::REQUIRED,
72+
'Index'
73+
)
74+
->addOption(
75+
'language',
76+
null,
77+
InputOption::VALUE_OPTIONAL,
78+
'Index language',
79+
null
80+
)
81+
->addOption(
82+
'no-store-searchable-metadata',
83+
null,
84+
InputOption::VALUE_NONE,
85+
'Store searchable metadata'
86+
)
87+
->addOption(
88+
'synonym',
89+
null,
90+
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
91+
'Synonym'
92+
)
93+
->addOption(
94+
'synonyms-file',
95+
null,
96+
InputOption::VALUE_OPTIONAL,
97+
'Synonyms file',
98+
''
99+
);
100+
}
101+
102+
/**
103+
* Dispatch domain event.
104+
*
105+
* @return string
106+
*/
107+
protected function getHeader(): string
108+
{
109+
return 'Configure index';
110+
}
111+
112+
/**
113+
* Dispatch domain event.
114+
*
115+
* @param InputInterface $input
116+
* @param OutputInterface $output
117+
*
118+
* @return mixed|null
119+
*/
120+
protected function runCommand(InputInterface $input, OutputInterface $output)
121+
{
122+
$appName = $input->getArgument('app-name');
123+
$indexUUID = IndexUUID::createById($input->getArgument('index'));
124+
125+
$this->printInfoMessage(
126+
$output,
127+
$this->getHeader(),
128+
"App name: <strong>{$appName}</strong>"
129+
);
130+
131+
$this->printInfoMessage(
132+
$output,
133+
$this->getHeader(),
134+
"Index ID: <strong>{$indexUUID->composeUUID()}</strong>"
135+
);
136+
137+
$synonyms = $this
138+
->synonymReader
139+
->readSynonymsFromFile($input->getOption('synonyms-file'));
140+
141+
$synonyms += $this
142+
->synonymReader
143+
->readSynonymsFromCommaSeparatedArray($input->getOption('synonym'));
144+
145+
try {
146+
$this
147+
->repositoryBucket
148+
->findRepository($appName)
149+
->configureIndex(
150+
$indexUUID,
151+
Config::createFromArray([
152+
'language' => $input->getOption('language'),
153+
'store_searchable_metadata' => !$input->getOption('no-store-searchable-metadata'),
154+
'synonyms' => $synonyms = array_map(function (Synonym $synonym) {
155+
return $synonym->toArray();
156+
}, $synonyms),
157+
])
158+
);
159+
} catch (ResourceNotAvailableException $exception) {
160+
$this->printInfoMessage(
161+
$output,
162+
$this->getHeader(),
163+
'Index not found. Skipping.'
164+
);
165+
}
166+
}
167+
168+
/**
169+
* Get success message.
170+
*
171+
* @param InputInterface $input
172+
* @param mixed $result
173+
*
174+
* @return string
175+
*/
176+
protected function getSuccessMessage(
177+
InputInterface $input,
178+
$result
179+
): string {
180+
return 'Index configured properly';
181+
}
182+
}

Command/CreateIndexCommand.php

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
namespace Apisearch\Command;
1717

18-
use Apisearch\Config\ImmutableConfig;
18+
use Apisearch\App\AppRepositoryBucket;
19+
use Apisearch\Config\Config;
20+
use Apisearch\Config\Synonym;
21+
use Apisearch\Config\SynonymReader;
1922
use Apisearch\Exception\ResourceNotAvailableException;
2023
use Apisearch\Model\IndexUUID;
2124
use Symfony\Component\Console\Input\InputArgument;
@@ -28,6 +31,28 @@
2831
*/
2932
class CreateIndexCommand extends WithAppRepositoryBucketCommand
3033
{
34+
/**
35+
* @var SynonymReader
36+
*
37+
* Synonym Reader
38+
*/
39+
private $synonymReader;
40+
41+
/**
42+
* WithAppRepositoryBucketCommand constructor.
43+
*
44+
* @param AppRepositoryBucket $repositoryBucket
45+
* @param SynonymReader $synonymReader
46+
*/
47+
public function __construct(
48+
AppRepositoryBucket $repositoryBucket,
49+
SynonymReader $synonymReader
50+
) {
51+
parent::__construct($repositoryBucket);
52+
53+
$this->synonymReader = $synonymReader;
54+
}
55+
3156
/**
3257
* Configures the current command.
3358
*/
@@ -64,6 +89,13 @@ protected function configure()
6489
null,
6590
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
6691
'Synonym'
92+
)
93+
->addOption(
94+
'synonyms-file',
95+
null,
96+
InputOption::VALUE_OPTIONAL,
97+
'Synonyms file',
98+
''
6799
);
68100
}
69101

@@ -88,20 +120,40 @@ protected function getHeader(): string
88120
protected function runCommand(InputInterface $input, OutputInterface $output)
89121
{
90122
$appName = $input->getArgument('app-name');
91-
$index = $input->getArgument('index');
123+
$indexUUID = IndexUUID::createById($input->getArgument('index'));
124+
125+
$this->printInfoMessage(
126+
$output,
127+
$this->getHeader(),
128+
"App name: <strong>{$appName}</strong>"
129+
);
130+
131+
$this->printInfoMessage(
132+
$output,
133+
$this->getHeader(),
134+
"Index ID: <strong>{$indexUUID->composeUUID()}</strong>"
135+
);
136+
137+
$synonyms = $this
138+
->synonymReader
139+
->readSynonymsFromFile($input->getOption('synonyms-file'));
140+
141+
$synonyms += $this
142+
->synonymReader
143+
->readSynonymsFromCommaSeparatedArray($input->getOption('synonym'));
92144

93145
try {
94146
$this
95147
->repositoryBucket
96148
->findRepository($appName)
97149
->createIndex(
98-
new IndexUUID($index),
99-
ImmutableConfig::createFromArray([
150+
$indexUUID,
151+
Config::createFromArray([
100152
'language' => $input->getOption('language'),
101153
'store_searchable_metadata' => !$input->getOption('no-store-searchable-metadata'),
102-
'synonyms' => array_map(function (string $synonym) {
103-
return ['words' => array_map('trim', explode(',', $synonym))];
104-
}, $input->getOption('synonym')),
154+
'synonyms' => $synonyms = array_map(function (Synonym $synonym) {
155+
return $synonym->toArray();
156+
}, $synonyms),
105157
])
106158
);
107159
} catch (ResourceNotAvailableException $exception) {
@@ -125,6 +177,6 @@ protected function getSuccessMessage(
125177
InputInterface $input,
126178
$result
127179
): string {
128-
return 'Indices created properly';
180+
return 'Index created properly';
129181
}
130182
}

Command/DeleteIndexCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
7373
$this
7474
->repositoryBucket
7575
->findRepository($appName)
76-
->deleteIndex(new IndexUUID($index));
76+
->deleteIndex(IndexUUID::createById($index));
7777
} catch (ResourceNotAvailableException $exception) {
7878
$this->printInfoMessage(
7979
$output,
@@ -95,6 +95,6 @@ protected function getSuccessMessage(
9595
InputInterface $input,
9696
$result
9797
): string {
98-
return 'Indices deleted properly';
98+
return 'Index deleted properly';
9999
}
100100
}

0 commit comments

Comments
 (0)