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

Commit 95b4e70

Browse files
authored
Merge pull request #46 from apisearch-io/feature/using-query-parameters-feature
Using new query parameters
2 parents 2edc5c0 + 42eb264 commit 95b4e70

File tree

9 files changed

+58
-45
lines changed

9 files changed

+58
-45
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.23-2+ubuntu16.04.1+deb.sury.org+1","version":"2.14.0:v2.14.0#b788ea0af899cedc8114dca7db119c93b6685da2","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_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"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\/ApisearchBundleFunctionalTest.php":1130132530,"Tests\/Functional\/ProductWriteTransformer.php":4090808924,"Tests\/Functional\/Command\/IndexCommandTest.php":673234498,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/Command\/QueryCommandTest.php":2580406218,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":3415234775,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1149363544,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3052848166,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":1388027657,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":2500445244,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2956180423,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Translator\/AggregationTranslator.php":4238166597,"ApisearchBundle.php":3640212495,"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"Command\/ImportIndexCommand.php":3461230433,"Command\/CreateIndexCommand.php":3585751415,"Command\/ApisearchFormattedCommand.php":1111995920,"Command\/ResetIndexCommand.php":3426927232,"Command\/DeleteIndexCommand.php":1350714493,"Command\/ApisearchCommand.php":1457306061,"Command\/WithAppRepositoryBucketCommand.php":2197592132,"Command\/PrintIndicesCommand.php":2224987197,"Command\/DeleteTokensCommand.php":290859330,"Command\/AddTokenCommand.php":684681072,"Command\/PrintTokensCommand.php":1079623314,"Command\/ExportIndexCommand.php":1133721139,"Command\/ConfigureIndexCommand.php":2627529992,"Command\/WithRepositoryBucketCommand.php":3434324818,"Command\/DeleteTokenCommand.php":121828308,"Command\/QueryCommand.php":362290438,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":4244359397,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/ApisearchConfiguration.php":1136730770,"DependencyInjection\/ApisearchExtension.php":112225700}}
1+
{"php":"7.1.26-1+ubuntu18.04.1+deb.sury.org+1","version":"2.14.2:v2.14.2#ff401e58261ffc5934a58f795b3f95b355e276cb","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_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"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":774594588,"DependencyInjection\/ApisearchExtension.php":112225700,"DependencyInjection\/ApisearchConfiguration.php":1136730770,"ApisearchBundle.php":3640212495,"Translator\/AggregationTranslator.php":4238166597,"Command\/ExportIndexCommand.php":1133721139,"Command\/ImportIndexCommand.php":3461230433,"Command\/PrintTokensCommand.php":1079623314,"Command\/DeleteTokensCommand.php":290859330,"Command\/ApisearchCommand.php":1457306061,"Command\/ConfigureIndexCommand.php":2627529992,"Command\/ApisearchFormattedCommand.php":1111995920,"Command\/PrintIndicesCommand.php":2224987197,"Command\/AddTokenCommand.php":684681072,"Command\/WithRepositoryBucketCommand.php":3434324818,"Command\/WithAppRepositoryBucketCommand.php":2197592132,"Command\/DeleteTokenCommand.php":121828308,"Command\/QueryCommand.php":3024631832,"Command\/CreateIndexCommand.php":3731774129,"Command\/DeleteIndexCommand.php":1350714493,"Command\/ResetIndexCommand.php":3426927232,"Tests\/Functional\/ApisearchBundleFunctionalTest.php":1130132530,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2956180423,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3052848166,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":1388027657,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":2500445244,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1149363544,"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/Command\/QueryCommandTest.php":2580406218,"Tests\/Functional\/Command\/IndexCommandTest.php":673234498,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":3415234775,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/ProductWriteTransformer.php":4090808924}}

Command/ConfigureIndexCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ protected function configure()
9292
'synonyms-file',
9393
null,
9494
InputOption::VALUE_OPTIONAL,
95-
'Synonyms file',
96-
''
95+
'Synonyms file'
9796
)
9897
->addOption(
9998
'shards',
@@ -123,10 +122,13 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
123122
{
124123
$appName = $input->getArgument('app-name');
125124
list($_, $indexUUID) = $this->getRepositoryAndIndex($input, $output);
125+
$synonymsFile = $input->getOption('synonyms-file');
126126

127-
$synonyms = $this
128-
->synonymReader
129-
->readSynonymsFromFile($input->getOption('synonyms-file'));
127+
$synonyms = !is_null($synonymsFile)
128+
? $this
129+
->synonymReader
130+
->readSynonymsFromFile($input->getOption('synonyms-file'))
131+
: [];
130132

131133
$synonyms += $this
132134
->synonymReader

Command/CreateIndexCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ protected function configure()
9292
'synonyms-file',
9393
null,
9494
InputOption::VALUE_OPTIONAL,
95-
'Synonyms file',
96-
''
95+
'Synonyms file'
9796
)
9897
->addOption(
9998
'shards',
@@ -123,10 +122,13 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
123122
{
124123
$appName = $input->getArgument('app-name');
125124
list($_, $indexUUID) = $this->getRepositoryAndIndex($input, $output);
125+
$synonymsFile = $input->getOption('synonyms-file');
126126

127-
$synonyms = $this
128-
->synonymReader
129-
->readSynonymsFromFile($input->getOption('synonyms-file'));
127+
$synonyms = !is_null($synonymsFile)
128+
? $this
129+
->synonymReader
130+
->readSynonymsFromFile($input->getOption('synonyms-file'))
131+
: [];
130132

131133
$synonyms += $this
132134
->synonymReader

Command/QueryCommand.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ protected function configure()
6565
InputOption::VALUE_OPTIONAL,
6666
'Number of results',
6767
ModelQuery::DEFAULT_SIZE
68+
)
69+
->addOption(
70+
'parameter',
71+
null,
72+
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
73+
'Query parameters',
74+
[]
6875
);
6976
}
7077

@@ -79,11 +86,12 @@ protected function configure()
7986
protected function runCommand(InputInterface $input, OutputInterface $output)
8087
{
8188
$repository = $this->getRepository($input, $output);
89+
$parameters = $input->getOption('parameter');
8290
self::makeQueryAndPrintResults(
8391
$input,
8492
$output,
85-
function (Query $query) use ($repository) {
86-
return $repository->query($query);
93+
function (Query $query) use ($repository, $parameters) {
94+
return $repository->query($query, $parameters);
8795
}
8896
);
8997
}

DependencyInjection/CompilerPass/RepositoryCompilerPass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Apisearch\App\DiskAppRepository;
1919
use Apisearch\App\HttpAppRepository;
2020
use Apisearch\App\InMemoryAppRepository;
21-
use Apisearch\Http\GuzzleClient;
2221
use Apisearch\Http\RetryMap;
2322
use Apisearch\Http\TCPClient;
2423
use Apisearch\Http\TestClient;

Tests/Functional/Command/AddDeleteTokensCommandTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function testTokenCreation()
4444
'app-name' => 'app123name',
4545
]);
4646

47-
$this->assertTrue(
48-
false !== strpos($output, 'new-token-999')
49-
);
47+
$this->assertNotFalse(strpos($output, 'new-token-999'));
5048

5149
static::runCommand([
5250
'command' => 'apisearch:delete-token',
@@ -78,13 +76,8 @@ public function testTokenCreation()
7876
'app-name' => 'app123name',
7977
]);
8078

81-
$this->assertTrue(
82-
false !== strpos($output, 'new-token-888')
83-
);
84-
85-
$this->assertTrue(
86-
false !== strpos($output, 'new-token-999')
87-
);
79+
$this->assertNotFalse(strpos($output, 'new-token-888'));
80+
$this->assertNotFalse(strpos($output, 'new-token-999'));
8881

8982
$output = static::runCommand([
9083
'command' => 'apisearch:delete-all-tokens',

Tests/Functional/Command/IndexCommandTest.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ public function testTokenCreation()
2929
{
3030
$fileName = tempnam('/tmp', 'test-apisearch');
3131

32-
static::runCommand([
32+
$createOutput = static::runCommand([
3333
'command' => 'apisearch:create-index',
3434
'app-name' => 'app123name',
3535
'index-name' => 'index123name',
3636
]);
3737

38+
$this->assertNotFalse(strpos($createOutput, 'Index created properly'));
39+
3840
$importOutput = static::runCommand([
3941
'command' => 'apisearch:import-index',
4042
'app-name' => 'app123name',
4143
'index-name' => 'index123name',
4244
'file' => __DIR__.'/data.as',
4345
]);
4446

45-
$this->assertTrue(
46-
false !== strpos($importOutput, 'Partial import of 28 items')
47-
);
47+
$this->assertNotFalse(strpos($importOutput, 'Partial import of 28 items'));
4848

4949
$exportOutput = static::runCommand([
5050
'command' => 'apisearch:export-index',
@@ -58,8 +58,19 @@ public function testTokenCreation()
5858
file_get_contents($fileName)
5959
);
6060

61-
$this->assertTrue(
62-
false !== strpos($exportOutput, 'Partial export of 28 items')
61+
$this->assertNotFalse(strpos($exportOutput, 'Partial export of 28 items'));
62+
63+
$configureOutput = static::runCommand([
64+
'command' => 'apisearch:configure-index',
65+
'app-name' => 'app123name',
66+
'index-name' => 'index123name',
67+
]);
68+
69+
$this->assertNotFalse(strpos($configureOutput, 'Index configured properly'));
70+
71+
$this->assertEquals(
72+
file_get_contents(__DIR__.'/data.as'),
73+
file_get_contents($fileName)
6374
);
6475

6576
static::runCommand([

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"scripts": {
4242
"fix-code": [
4343
"vendor/bin/php-cs-fixer fix --config=.php_cs",
44-
"vendor/bin/php-formatter f:h:f . --exclude=vendor",
45-
"vendor/bin/php-formatter f:s:f . --exclude=vendor",
46-
"vendor/bin/php-formatter f:u:s . --exclude=vendor"
44+
"vendor/bin/php-formatter f:h:f . --exclude=vendor --exclude=var",
45+
"vendor/bin/php-formatter f:s:f . --exclude=vendor --exclude=var",
46+
"vendor/bin/php-formatter f:u:s . --exclude=vendor --exclude=var"
4747
],
4848
"test": "vendor/bin/phpunit"
4949
}

0 commit comments

Comments
 (0)