php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71568 solr document boost not working in locales where decimal character is a comma
Submitted: 2016-02-11 10:48 UTC Modified: 2016-02-14 17:56 UTC
From: patrik at hall dot fi Assigned: omars (profile)
Status: Closed Package: solr (PECL)
PHP Version: 5.6.18 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: patrik at hall dot fi
New email:
PHP Version: OS:

 

 [2016-02-11 10:48 UTC] patrik at hall dot fi
Description:
------------
Solr expects boosts to be specified as a float with a dot as decimal character.

In solr_functions_document.c, document_boost and field_boost is converted to a string with sprintf. sprintf uses locale info for converting float into a string.

In an environment where decimal delimiter is a comma, solr will not accept the documents.

One solution might be to temporarily switch locale to C before the sprintf calls. Another one would not to use sprintf and use another function that is not locale aware.

Test script:
---------------
<?php
/* use a system locale where decimal delimiter is not a dot. */
$clientOptions = array('hostname' => 'localhost', 'port' => '8080', 'path' => '/solr/core');
$solrClient = new \SolrClient($clientOptions);
$document = new \SolrInputDocument();
document->setBoost(1.0);
$solrClient->addDocuments(array($document));
?>

Expected result:
----------------
Solr would accept inserted documents not depending of the locale settings.

Actual result:
--------------
Solr fails importing the document with java.lang.NumberFormatException: For input string: "1,0"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-14 17:56 UTC] omars@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: omars
 [2016-02-20 02:50 UTC] omars@php.net
Automatic comment on behalf of omars
Revision: http://git.php.net/?p=pecl/search_engine/solr.git;a=commit;h=4b02a6b0f4bb38f510461d22944d59086e70faef
Log: Fix Bug #71568: SolrDocument/DocumentField Boost locale issue
 [2016-02-20 02:50 UTC] omars@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 10:01:27 2025 UTC