@@ -56,6 +56,72 @@ public function testExceptionIfNoIndexWhenSearching()
56
56
$ index ->search ('prince ' );
57
57
}
58
58
59
+ public function testParametersCanBeString ()
60
+ {
61
+ $ this ->createFreshIndexAndSeedDocuments ();
62
+ $ response = $ this ->index ->search ('prince ' , [
63
+ 'limit ' => 5 ,
64
+ 'offset ' => 0 ,
65
+ 'attributesToRetrieve ' => 'id,title ' ,
66
+ 'attributesToCrop ' => 'id,title ' ,
67
+ 'cropLength ' => 6 ,
68
+ 'attributesToHighlight ' => 'title ' ,
69
+ 'filters ' => 'title = "Le Petit Prince" ' ,
70
+ 'matches ' => 'true ' ,
71
+ ]);
72
+
73
+ $ this ->assertArrayHasKey ('_matchesInfo ' , $ response ['hits ' ][0 ]);
74
+ $ this ->assertArrayHasKey ('title ' , $ response ['hits ' ][0 ]['_matchesInfo ' ]);
75
+ $ this ->assertArrayHasKey ('_formatted ' , $ response ['hits ' ][0 ]);
76
+ $ this ->assertArrayNotHasKey ('comment ' , $ response ['hits ' ][0 ]);
77
+ $ this ->assertArrayNotHasKey ('comment ' , $ response ['hits ' ][0 ]['_matchesInfo ' ]);
78
+ $ this ->assertSame ('Petit <em>Prince</em> ' , $ response ['hits ' ][0 ]['_formatted ' ]['title ' ]);
79
+ }
80
+
81
+ public function testParametersCanBeArray ()
82
+ {
83
+ $ this ->createFreshIndexAndSeedDocuments ();
84
+ $ response = $ this ->index ->search ('prince ' , [
85
+ 'limit ' => 5 ,
86
+ 'offset ' => 0 ,
87
+ 'attributesToRetrieve ' => ['id ' , 'title ' ],
88
+ 'attributesToCrop ' => ['id ' , 'title ' ],
89
+ 'cropLength ' => 6 ,
90
+ 'attributesToHighlight ' => 'title ' ,
91
+ 'filters ' => 'title = "Le Petit Prince" ' ,
92
+ 'matches ' => 'true ' ,
93
+ ]);
94
+
95
+ $ this ->assertArrayHasKey ('_matchesInfo ' , $ response ['hits ' ][0 ]);
96
+ $ this ->assertArrayHasKey ('title ' , $ response ['hits ' ][0 ]['_matchesInfo ' ]);
97
+ $ this ->assertArrayHasKey ('_formatted ' , $ response ['hits ' ][0 ]);
98
+ $ this ->assertArrayNotHasKey ('comment ' , $ response ['hits ' ][0 ]);
99
+ $ this ->assertArrayNotHasKey ('comment ' , $ response ['hits ' ][0 ]['_matchesInfo ' ]);
100
+ $ this ->assertSame ('Petit <em>Prince</em> ' , $ response ['hits ' ][0 ]['_formatted ' ]['title ' ]);
101
+ }
102
+
103
+ public function testParametersCanBeAStar ()
104
+ {
105
+ $ this ->createFreshIndexAndSeedDocuments ();
106
+ $ response = $ this ->index ->search ('prince ' , [
107
+ 'limit ' => 5 ,
108
+ 'offset ' => 0 ,
109
+ 'attributesToRetrieve ' => '* ' ,
110
+ 'attributesToCrop ' => '* ' ,
111
+ 'cropLength ' => 6 ,
112
+ 'attributesToHighlight ' => '* ' ,
113
+ 'filters ' => 'title = "Le Petit Prince" ' ,
114
+ 'matches ' => 'true ' ,
115
+ ]);
116
+
117
+ $ this ->assertArrayHasKey ('_matchesInfo ' , $ response ['hits ' ][0 ]);
118
+ $ this ->assertArrayHasKey ('title ' , $ response ['hits ' ][0 ]['_matchesInfo ' ]);
119
+ $ this ->assertArrayHasKey ('_formatted ' , $ response ['hits ' ][0 ]);
120
+ $ this ->assertArrayHasKey ('comment ' , $ response ['hits ' ][0 ]);
121
+ $ this ->assertArrayNotHasKey ('comment ' , $ response ['hits ' ][0 ]['_matchesInfo ' ]);
122
+ $ this ->assertSame ('Petit <em>Prince</em> ' , $ response ['hits ' ][0 ]['_formatted ' ]['title ' ]);
123
+ }
124
+
59
125
private function createFreshIndexAndSeedDocuments ()
60
126
{
61
127
$ this ->client ->deleteAllIndexes ();
0 commit comments