@@ -12,13 +12,61 @@ class Match extends \Tester\TestCase
1212 {
1313 $ match = new \Spameri \ElasticQuery \Query \Match (
1414 'name ' ,
15- 'Avengers '
15+ 'Avengers ' ,
16+ 1.0 ,
17+ \Spameri \ElasticQuery \Query \Match \Operator::OR ,
18+ new \Spameri \ElasticQuery \Query \Match \Fuzziness (
19+ \Spameri \ElasticQuery \Query \Match \Fuzziness::AUTO
20+ ),
21+ 'standard ' ,
22+ 2
1623 );
1724
1825 $ array = $ match ->toArray ();
1926
2027 \Tester \Assert::true (isset ($ array ['match ' ]['name ' ]['query ' ]));
2128 \Tester \Assert::same ('Avengers ' , $ array ['match ' ]['name ' ]['query ' ]);
29+ \Tester \Assert::same (1.0 , $ array ['match ' ]['name ' ]['boost ' ]);
30+ \Tester \Assert::same (\Spameri \ElasticQuery \Query \Match \Operator::OR , $ array ['match ' ]['name ' ]['operator ' ]);
31+ \Tester \Assert::same (\Spameri \ElasticQuery \Query \Match \Fuzziness::AUTO , $ array ['match ' ]['name ' ]['fuzziness ' ]);
32+ \Tester \Assert::same ('standard ' , $ array ['match ' ]['name ' ]['analyzer ' ]);
33+ \Tester \Assert::same (2 , $ array ['match ' ]['name ' ]['minimum_should_match ' ]);
34+
35+ $ document = new \Spameri \ElasticQuery \Document (
36+ 'spameri_video ' ,
37+ new \Spameri \ElasticQuery \Document \Body \Plain (
38+ (
39+ new \Spameri \ElasticQuery \ElasticQuery (
40+ new \Spameri \ElasticQuery \Query \QueryCollection (
41+ new \Spameri \ElasticQuery \Query \MustCollection (
42+ $ match
43+ )
44+ )
45+ )
46+ )->toArray ()
47+ ),
48+ 'spameri_video '
49+ );
50+
51+ $ ch = curl_init ();
52+ curl_setopt ($ ch , CURLOPT_URL , 'localhost:9200/_search ' );
53+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
54+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'GET ' );
55+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , ['Content-Type: application/json ' ]);
56+ curl_setopt (
57+ $ ch , CURLOPT_POSTFIELDS ,
58+ \json_encode ($ document ->toArray ()['body ' ])
59+ );
60+
61+ \Tester \Assert::noError (static function () use ($ ch ) {
62+ $ response = curl_exec ($ ch );
63+ $ resultMapper = new \Spameri \ElasticQuery \Response \ResultMapper ();
64+ /** @var \Spameri\ElasticQuery\Response\ResultSearch $result */
65+ $ result = $ resultMapper ->map (\json_decode ($ response , TRUE ));
66+ \Tester \Assert::type ('int ' , $ result ->stats ()->total ());
67+ });
68+
69+ curl_close ($ ch );
2270 }
2371
2472}
0 commit comments