php - Solr comands not returning json output -


i going through php documentation solr , wanted try out basic example. expected output isn't received , blank page returned when try following code existing project.

<?php include "bootstrap.php";  $options = array ( 'hostname' => solr_server_hostname, 'login'    => solr_server_username, 'password' => solr_server_password, 'port'     => solr_server_port, );  $client = new solrclient($options);  $doc = new solrinputdocument();    $doc->addfield('id', 334455); //$doc->addfield('cat', 'software'); //$doc->addfield('cat', 'lucene');  $updateresponse = $client->adddocument($doc);  print_r($updateresponse->getresponse());  ?> 

the bootstrap.php goes this:

/* domain name of solr server */ define('solr_server_hostname', 'localhost');  /* whether or not run in secure mode */ define('solr_secure', false);  /* http port connection */ define('solr_server_port', ((solr_secure) ? 8443 : 8080));  /* http basic authentication username */ define('solr_server_username', 'admin');  /* http basic authentication password */ define('solr_server_password', 'changeit');  /* http connection timeout */ /* maximum time in seconds allowed http data transfer operation.default value 30 seconds */ define('solr_server_timeout', 10);  /* file name pem-formatted private key + private certificate (concatenated in    order) */ define('solr_ssl_cert', 'certs/combo.pem');  /* file name pem-formatted private certificate */ define('solr_ssl_cert_only', 'certs/solr.crt');  /* file name pem-formatted private key */ define('solr_ssl_key', 'certs/solr.key');  /* password pem-formatted private key file */ define('solr_ssl_keypassword', 'strongandsecurepassword');  /* name of file holding 1 or more ca certificates verify peer with*/ define('solr_ssl_cainfo', 'certs/cacert.crt');  /* name of directory holding multiple ca certificates verify peer */ define('solr_ssl_capath', 'certs/');  ?> 

i'm using tomcat username , password solr_server_username/password. , solr working fine otherwise on ui. using solr 4.6.1 php solrclient 1.0.2

    <?php  // make sure browsers see page utf-8 encoded html header('content-type: text/html; charset=utf-8');  $limit = 10; $query = isset($_request['q']) ? $_request['q'] : false; $results = false;  if ($query) {   // apache solr client library should on include path   // accomplished placing in   // same directory script ( . or current directory default   // php include path entry in php.ini)   require_once('/usr/local/apache-tomcat-7.0.50/solrphpclient/apache/solr/service.php');    // create new solr service instance - host, port, , webapp   // path (all defaults in example)   $solr = new apache_solr_service('localhost', 8080, '/solr/collection1');     // if magic quotes enabled stripslashes needed   if (get_magic_quotes_gpc() == 1)   {     $query = stripslashes($query);   }    // in production code you'll want use try /catch   // possible exceptions emitted  searching (i.e. connection   // problems or query parsing error)   try   {     $results = $solr->search($query, 0, $limit);   }   catch (exception $e)   {     // in production you'd log or email error admin         // , show special message user example         // we're going show full exception          die("<html><head><title>search exception</title><body><pre>{$e->__tostring()}</pre></body></html>");   } }  ?> <html>   <head>     <title>php solr client example</title>   </head>   <body>       <h1>abcd</h1>     <form  accept-charset="utf-8" method="get">       <label for="q">search:</label>       <input id="q" name="q" type="text" value="<?php echo htmlspecialchars($query, ent_quotes, 'utf-8'); ?>"/>       <input type="submit"/>     </form> <?php  // display results if ($results) {   $total = (int) $results->response->numfound;   $start = min(1, $total);   $end = min($limit, $total); ?>     <div>results <?php echo $start; ?> - <?php echo $end;?> of <?php echo $total; ?>:</div>     <ol> <?php   // iterate result documents   foreach ($results->response->docs $doc)   { ?>       <li>         <table style="border: 1px solid black; text-align: left"> <?php     // iterate document fields / values     foreach ($doc $field => $value)     { ?>           <tr>             <th><?php echo htmlspecialchars($field, ent_noquotes, 'utf-8'); ?></th>             <td><?php echo htmlspecialchars($value, ent_noquotes, 'utf-8'); ?></td>           </tr>     <?php     }     ?>         </table>       </li>     <?php   } ?>     </ol>     <?php     }?> 

while trying above alternative code, following error encountered:

exception 'apache_solr_httptransportexception' message ''0' status: communication error' in /usr/local/apache-tomcat-7.0.50/solrphpclient/apache/solr/service.php:338 stack trace:

0 /usr/local/apache-tomcat-7.0.50/solrphpclient/apache/solr/service.php(1170):

apache_solr_service->_sendrawget - ('http://localhos...')

1 /var/www/html/testproject/tryout.php(33): apache_solr_service->search('abhilash', 0, 10)

2 {main}

solr's default response writer xml.

if want results in json, should specify defining url parameter wt=json

example

http://localhost:8983/solr/customers/select?q=customersearchname&wt=json 

make sure so.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -