1<?php
2
3include "bootstrap.php";
4
5$options = array
6(
7    'hostname' => SOLR_SERVER_HOSTNAME,
8    'login'    => SOLR_SERVER_USERNAME,
9    'password' => SOLR_SERVER_PASSWORD,
10    'port'     => SOLR_SERVER_PORT,
11    'path'     => SOLR_SERVER_STORE_PATH,
12);
13
14$client = new SolrClient($options);
15
16$product = new SolrInputDocument();
17
18$product->addField('id', 'black');
19$product->addField('cat', 'tshirt');
20$product->addField('cat', 'polo');
21$product->addField('content_type', 'product');
22
23$small = new SolrInputDocument();
24$small->addField('id', 'TS-BLK-S');
25$small->addField('content_type', 'sku');
26$small->addField('size', 'S');
27$small->addField('inventory', 100);
28
29$medium = new SolrInputDocument();
30$medium->addField('id', 'TS-BLK-M');
31$medium->addField('content_type', 'sku');
32$medium->addField('size', 'M');
33$medium->addField('inventory', 200);
34
35$large = new SolrInputDocument();
36$large->addField('id', 'TS-BLK-L');
37$large->addField('content_type', 'sku');
38$large->addField('size', 'L');
39$large->addField('inventory', 300);
40
41// add child documents
42$product->addChildDocument($small);
43$product->addChildDocument($medium);
44$product->addChildDocument($large);
45// or
46// $skus = [$small, $medium, $large];
47// $product->addChildDocuments($skus);
48
49// add product document to the index
50$updateResponse = $client->addDocument(
51		$product,
52		true, // overwrite if the document exists
53		10000 // commit within 10 seconds
54);
55
56print_r($updateResponse->getResponse());
57
58/* OUTPUT SIMILAR TO:
59SolrObject Object
60(
61    [responseHeader] => SolrObject Object
62        (
63            [status] => 0
64            [QTime] => 5
65        )
66)
67*/
68