コード例 #1
0
ファイル: SearchTest.php プロジェクト: php-riak/riak-client
 public function testExecuteCommand()
 {
     $response = new SearchResponse();
     $command = Search::builder()->withReturnFields(['email', 'name', 'age'])->withFilterQuery('age:[18 TO *]')->withDefaultOperation('and')->withReturnField('username')->withQuery('name:Fabio*')->withDefaultField('name')->withIndex('index-name')->withSortField('name')->withPresort('score')->withNumRows(10)->withStart(1)->build();
     $response->maxScore = 1;
     $response->numFound = 2;
     $response->docs = [['email' => ['*****@*****.**'], 'name' => ['Fabio B. Silva'], 'username' => ['FabioBatSilva'], 'age' => ['30']], ['email' => ['*****@*****.**'], 'name' => ['Fabio B. Silva'], 'username' => ['fabios'], 'age' => ['30']]];
     $callback = function ($subject) {
         $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\SearchRequest', $subject);
         $this->assertEquals('age:[18 TO *]', $subject->filter);
         $this->assertEquals('index-name', $subject->index);
         $this->assertEquals('name:Fabio*', $subject->q);
         $this->assertEquals('score', $subject->presort);
         $this->assertEquals('name', $subject->sort);
         $this->assertEquals('name', $subject->df);
         $this->assertEquals('and', $subject->op);
         $this->assertEquals(10, $subject->rows);
         $this->assertEquals(1, $subject->start);
         $this->assertCount(4, $subject->fl);
         $this->assertContains('age', $subject->fl);
         $this->assertContains('name', $subject->fl);
         $this->assertContains('email', $subject->fl);
         $this->assertContains('username', $subject->fl);
         return true;
     };
     $this->adapter->expects($this->once())->method('send')->with($this->callback($callback))->will($this->returnValue($response));
     $result = $this->client->execute($command);
     $this->assertInstanceOf('Riak\\Client\\Command\\Search\\Response\\SearchResponse', $result);
     $this->assertEquals($response->numFound, $result->getNumResults());
     $this->assertEquals($response->maxScore, $result->getMaxScore());
     $this->assertEquals($response->docs, $result->getAllResults());
     $this->assertEquals([['email' => '*****@*****.**', 'name' => 'Fabio B. Silva', 'username' => 'FabioBatSilva', 'age' => '30'], ['email' => '*****@*****.**', 'name' => 'Fabio B. Silva', 'username' => 'fabios', 'age' => '30']], $result->getSingleResults());
 }
コード例 #2
0
 public function testSimpleKvMultSearch()
 {
     $this->dataKv->storeRiakObjects();
     $index = $this->indexKv;
     $search = Search::builder()->withQuery('name_s:Riak*')->withIndex($index)->build();
     $searchResult = $this->client->execute($search);
     $this->assertInstanceOf('Riak\\Client\\Command\\Search\\Response\\SearchResponse', $searchResult);
     $numResults = $searchResult->getNumResults();
     $results = $searchResult->getAllResults();
     $this->assertCount(1, $results);
     $this->assertEquals(1, $numResults);
     $this->assertEquals(['Riak for dummies'], $results[0]['name_s']);
     $this->assertEquals(['it', 'comedy'], $results[0]['category_ss']);
     $this->assertEquals(['Fabio B. Silva'], $results[0]['author_name_s']);
     $this->assertEquals(['*****@*****.**'], $results[0]['author_email_s']);
 }
コード例 #3
0
ファイル: SearchTest.php プロジェクト: php-riak/riak-client
 public function testSearchReturnFields()
 {
     $this->searchData->storeThunderCats();
     $index = $this->indexName;
     $search = Search::builder()->withReturnFields(['name_s', 'age_i'])->withQuery('age_i:30')->withIndex($index)->withNumRows(10)->build();
     $searchResult = $this->client->execute($search);
     $this->assertInstanceOf('Riak\\Client\\Command\\Search\\Response\\SearchResponse', $searchResult);
     $numResults = $searchResult->getNumResults();
     $results = $searchResult->getSingleResults();
     usort($results, function ($arg1, $arg2) {
         return strcmp($arg2['name_s'], $arg1['name_s']);
     });
     $this->assertCount(2, $results);
     $this->assertEquals(2, $numResults);
     $this->assertCount(2, $results[0]);
     $this->assertCount(2, $results[1]);
     $this->assertEquals(30, $results[0]['age_i']);
     $this->assertEquals(30, $results[1]['age_i']);
     $this->assertEquals('Lion-o', $results[0]['name_s']);
     $this->assertEquals('Cheetara', $results[1]['name_s']);
 }