File: 081.solrutils_digest_json_response.phpt

package info (click to toggle)
php-solr 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,620 kB
  • sloc: ansic: 14,274; xml: 1,313; php: 1,239; pascal: 11; makefile: 3
file content (121 lines) | stat: -rw-r--r-- 3,334 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--TEST--
SolrUtils::digestJsonResponse() - Digest JSON Response
--FILE--
<?php
$responseString = '
{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "indent":"on",
      "wt":"json",
      "q":"lucene",
      "version":"2.2"}},
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"SOLR1000",
        "name":"Solr, the Enterprise Search Server",
        "manu":"Apache Software Foundation",
        "cat":["software",
          "search"],
        "features":["Advanced Full-Text Search Capabilities using Lucene",
          "Optimized for High Volume Web Traffic",
          "Standards Based Open Interfaces - XML and HTTP",
          "Comprehensive HTML Administration Interfaces",
          "Scalability - Efficient Replication to other Solr Search Servers",
          "Flexible and Adaptable with XML configuration and Schema",
          "Good unicode support: hello (hello with an accent over the e)"],
        "price":0.0,
        "price_c":"0,USD",
        "popularity":10,
        "inStock":true,
        "incubationdate_dt":"2006-01-17T00:00:00Z",
        "_version_":1460602453694087168}]
  }}';
if (!json_decode($responseString)) {
	echo "PHP JSON DECODE failed with: ". json_last_error_msg().PHP_EOL;
}
$response = SolrUtils::digestJsonResponse($responseString);
var_dump($response instanceof SolrObject);
var_dump($response);
var_dump($response->response->docs[0]->_version_ == 1460602453694087168);
?>
--EXPECTF--
bool(true)
object(SolrObject)#%d (2) {
  ["responseHeader"]=>
  object(SolrObject)#4 (3) {
    ["status"]=>
    int(0)
    ["QTime"]=>
    int(1)
    ["params"]=>
    object(SolrObject)#5 (4) {
      ["indent"]=>
      string(2) "on"
      ["wt"]=>
      string(4) "json"
      ["q"]=>
      string(6) "lucene"
      ["version"]=>
      string(3) "2.2"
    }
  }
  ["response"]=>
  object(SolrObject)#%d (3) {
    ["numFound"]=>
    int(1)
    ["start"]=>
    int(0)
    ["docs"]=>
    array(1) {
      [0]=>
      object(SolrObject)#%d (11) {
        ["id"]=>
        string(8) "SOLR1000"
        ["name"]=>
        string(34) "Solr, the Enterprise Search Server"
        ["manu"]=>
        string(26) "Apache Software Foundation"
        ["cat"]=>
        array(2) {
          [0]=>
          string(8) "software"
          [1]=>
          string(6) "search"
        }
        ["features"]=>
        array(7) {
          [0]=>
          string(51) "Advanced Full-Text Search Capabilities using Lucene"
          [1]=>
          string(37) "Optimized for High Volume Web Traffic"
          [2]=>
          string(46) "Standards Based Open Interfaces - XML and HTTP"
          [3]=>
          string(44) "Comprehensive HTML Administration Interfaces"
          [4]=>
          string(64) "Scalability - Efficient Replication to other Solr Search Servers"
          [5]=>
          string(56) "Flexible and Adaptable with XML configuration and Schema"
          [6]=>
          string(61) "Good unicode support: hello (hello with an accent over the e)"
        }
        ["price"]=>
        float(0)
        ["price_c"]=>
        string(5) "0,USD"
        ["popularity"]=>
        int(10)
        ["inStock"]=>
        bool(true)
        ["incubationdate_dt"]=>
        string(20) "2006-01-17T00:00:00Z"
        ["_version_"]=>
        %s
      }
    }
  }
}
bool(true)