| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Elastica\Test\Query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Elastica\Document; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Elastica\Mapping; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Elastica\Query\Wildcard; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Elastica\Test\Base as BaseTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @internal | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class WildcardTest extends BaseTest | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * @group unit | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public function testConstruct(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $wildcard = new Wildcard('name', 'aaa*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $data = $wildcard->getParam('name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertIsArray($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->assertSame('aaa*', $data['value']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertSame(1.0, $data['boost']); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * @group unit | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     public function testToArray(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $wildcard = new Wildcard('name', 'value*', 2.0); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $wildcard->setRewrite(Wildcard::REWRITE_SCORING_BOOLEAN); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $expectedArray = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             'wildcard' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |                 'name' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |                     'value' => 'value*', | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |                     'boost' => 2.0, | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |                     'rewrite' => 'scoring_boolean', | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |                 ], | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertEquals($expectedArray, $wildcard->toArray()); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @group functional | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function testSearchWithAnalyzer(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $client = $this->_getClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $index = $client->getIndex('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $indexParams = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'settings' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 'analysis' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     'analyzer' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                         'lw' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                             'type' => 'custom', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                             'tokenizer' => 'keyword', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                             'filter' => ['lowercase'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                     ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $index->create($indexParams, ['recreate' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $mapping = new Mapping([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             'name' => ['type' => 'text', 'analyzer' => 'lw'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $index->setMapping($mapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $index->addDocuments([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             new Document(1, ['name' => 'Basel-Stadt']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             new Document(2, ['name' => 'New York']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             new Document(3, ['name' => 'Baden']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             new Document(4, ['name' => 'Baden Baden']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             new Document(5, ['name' => 'New Orleans']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $index->refresh(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $query = new Wildcard('name', 'ba*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $resultSet = $index->search($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->assertEquals(3, $resultSet->count()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $query = new Wildcard('name', 'baden*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $resultSet = $index->search($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->assertEquals(2, $resultSet->count()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $query = new Wildcard('name', 'baden b*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $resultSet = $index->search($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $this->assertEquals(1, $resultSet->count()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $query = new Wildcard('name', 'baden bas*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $resultSet = $index->search($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->assertEquals(0, $resultSet->count()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |      * @group functional | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     public function testCaseInsensitive(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         // feature doesn't exist on version prior 7.10; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $this->_checkVersion('7.10'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         foreach ([true, false] as $expected) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             $expectedArray = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 'wildcard' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                     'name' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                         'value' => 'exampl*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                         'boost' => 1.0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                         'case_insensitive' => $expected, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                     ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             $query = new Wildcard('name', 'exampl*', 1.0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             $this->assertEquals($expectedArray, $query->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             $query->setCaseInsensitive($expected); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             $this->assertEquals($expectedArray, $query->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 136 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 137 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: