ehime

Solr Code

Apr 25th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1.  
  2. /**
  3.  * Test Query
  4.  */
  5. $client = New Solarium\Client($config->Solr);
  6. $query  = $client->createSelect();
  7.  
  8.           $query->setQuery('*:*')
  9.                 ->setStart(2)
  10.                 ->setRows(1);
  11.  
  12. $response = $client->execute($query)->getData() ['response']['docs']; // call expansion v5.4+
  13.  
  14. /*
  15.  * modify response for insert
  16.  */
  17. $response[0] = ([
  18.         'id'            => 'Opportunity_Test',
  19.         'OpportunityId' => 'Opportunity_Test',
  20.         'text' => [
  21.             strtoupper('Lorem Ipsum'),
  22.             'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel risus quam. In sed augue tristique, consectetur purus sed, sagittis leo. ',
  23.  
  24.         ],
  25.         'Title'         => strtoupper('Lorem Ipsum')
  26.     ] + $response[0]
  27. );
  28.  
  29. print_r($response);
  30.  
  31. $update = $client->createUpdate();
  32. $insert  = [];
  33.  
  34. foreach ($response AS $docId => $array)
  35. {
  36.     $insert[$docId] = $update->createDocument();
  37.     foreach($array AS $name => $part)
  38.     {
  39.         if('_version_' !== $name) $insert[$docId]->$name = $part;
  40.     }
  41. }
  42.  
  43. print_r($insert);
  44.  
  45. $update->addDocuments($insert)
  46.        ->addCommit();
  47.  
  48. // this executes the query and returns the result
  49. $result = $client->update($update);
  50.  
  51. echo "Query status: {$result->getStatus()}";
  52. echo "Query time:   {$result->getQueryTime()}";
  53. die;
Advertisement
Add Comment
Please, Sign In to add comment