1

I have use this code to begin with my new solr search.

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('idDocument', 1);
$doc->addField('titleFr', 'Le petit poucet');
*/

$doc->addField(utf8_encode('idDocument'), utf8_encode(1));
$doc->addField(utf8_encode('titleFr'), utf8_encode('Le petit poucet'));

var_dump($doc->getFieldNames());
$updateResponse = $client->addDocument($doc, true, 10000);
//$client->commit();
var_dump($updateResponse->getResponse());

My BootStrap.php is :

/* Nom de domaine du serveur Solr */
define('SOLR_SERVER_HOSTNAME', 'localhost:81/solr/#/testDocument/');

/* Si l'on doit exécuter en mode sécurisé ou non */
define('SOLR_SECURE', true);

/* Port HTTP de connexion */
define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));

/* Nom d'utilisateur pour l'authentification HTTP Basic */
define('SOLR_SERVER_USERNAME', 'admin');

/* Mot de passe pour l'authentification HTTP Basic */
define('SOLR_SERVER_PASSWORD', '');

/* Délai maximal de connexion HTTP */
/* C'estla durée maximale en secondes autorisée pour l'opération de transfert de données http. La valeur par défaut est 30 secondes */
define('SOLR_SERVER_TIMEOUT', 10);

/* Nom du fichier de la clé privée formattée PEM + du certificat privé (concaténés dans cet ordre) */
define('SOLR_SSL_CERT', 'certs/combo.pem');

/* Nom du fichier du certificat privé formatté PEM seulement */
define('SOLR_SSL_CERT_ONLY', 'certs/solr.crt');

/* Nom du fichier de la clé privée formattée PEM */
define('SOLR_SSL_KEY', 'certs/solr.key');

/* Mot de passe pour le fichier de la clé privée formattée PEM */
define('SOLR_SSL_KEYPASSWORD', 'StrongAndSecurePassword');

/* Nom du fichier contenant un ou plusieurs certificats CA pour l'authentification */
define('SOLR_SSL_CAINFO', 'certs/cacert.crt');

/* Nom du dossier contenant les certificats CA pour l'authentification */
define('SOLR_SSL_CAPATH', 'certs/');

And when i use it. I have this error with others errors. Warning: SolrClient::addDocument(): Entity: line 4: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xE9 0x74 0x68 0x6F in C:\wamp\www\testAntoine2\send.php on line 76

I use Bitnami Apache solR stack and I'm completly block by this error. Could you help me ou suggest me some new ideas please :)

Best regards, Uruca :)

Uruca
  • 11
  • 6
  • please check the link http://stackoverflow.com/questions/2507608/error-input-is-not-proper-utf-8-indicate-encoding-using-phps-simplexml-lo – Abhijit Bashetti May 29 '15 at 13:44
  • i saw it. I try to use it but what is "The input charset." ? iso? look i try to use utf8 encode – Uruca May 29 '15 at 13:53
  • i use it like that: $doc->addField(iconv('UTF-8', 'UTF-8//IGNORE', 'idDocument'), iconv('UTF-8', 'UTF-8//IGNORE', 1)); $doc->addField(iconv('UTF-8', 'UTF-8//IGNORE', 'titleFr'), iconv('UTF-8', 'UTF-8//IGNORE', 'Le petit poucet')); – Uruca May 29 '15 at 14:04
  • Don't use `iconv`, use `mb_convert_encoding($string, $newCharset, $oldCharset)`. If in doubt, try ISO-8859-1 for `$oldCharset`. – lxg May 29 '15 at 22:08
  • I have always the same problem when I use `$doc->addField(mb_convert_encoding('idDocument','UTF-8','ISO-8859-1'), mb_convert_encoding(1,'UTF-8','ISO-8859-1'))` – Uruca Jun 01 '15 at 07:16

1 Answers1

0

Your Solr URL includes "/#/" ... this is a URL that will ONLY work in a full graphical browser -- it's part of the admin UI. You cannot use URLs seen in your browser when running the admin UI for API communication with Solr.

If "testDocument" is the name of your Solr core (or collection for SolrCloud install) then this is the Solr URL:

localhost:81/solr/testDocument/

I can't tell for sure what PHP Solr client you are using, but for that $options variable, I believe you should only have "localhost" for the hostname, the correct port number in port, and "/solr/testDocument" for the path. Currently you do not have path at all.

I've got some confusion here ... for the hostname, you have a URL that includes port 81, but for the port, you are using either 8443 or 8983. Which one is the actual port?

elyograg
  • 789
  • 3
  • 14