Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Invalid
    • Affects Version/s: 1.2
    • Fix Version/s: 1.5
    • Component/s: clients - php
    • Labels:
      None
    • Environment:

      PHP >= 5.2.0 (or older with JSON PECL extension or other json_decode function implementation). Solr >= 1.2

      Description

      Since I'm unable to currently update the Solr WIKI page that points to this issue and its downloads, I've left this issue open. I, however, need to note that active releases of the PHP code are now available from:

      http://code.google.com/p/solr-php-client/downloads/list

      If you have any issues specific to this PHP client, please post / discuss them there (or on the solr user mailing list - I am a subscriber).

        Activity

        Donovan Jimenez created issue -
        Hide
        Donovan Jimenez added a comment -

        Source code, license stuff, and PHPDocs

        Show
        Donovan Jimenez added a comment - Source code, license stuff, and PHPDocs
        Donovan Jimenez made changes -
        Field Original Value New Value
        Attachment SolrPhpClient.zip [ 12364169 ]
        Donovan Jimenez made changes -
        Description Developed this client when the example PHP source didn't meet our needs. The company I work for agreed to release it under the terms of the Apache License.

        This version is slightly different from what I originally linked to on the dev mailing list. I've incorporated feedback from Yonik and "hossman" to simplify the client and only accept one response format (JSON currently).

        When Solr 1.3 is released the client can be updated to use the PHP or Serialized PHP response writer.
        Developed this client when the example PHP source didn't meet our needs. The company I work for agreed to release it under the terms of the Apache License.

        This version is slightly different from what I originally linked to on the dev mailing list. I've incorporated feedback from Yonik and "hossman" to simplify the client and only accept one response format (JSON currently).

        When Solr 1.3 is released the client can be updated to use the PHP or Serialized PHP response writer.

        example usage from my original mailing list post:

        <?php
        require_once('Solr/Service.php');

        $start = microtime(true);

        $solr = new Solr_Service(); //Or explicitly new Solr_Service('localhost', 8180, '/solr');

        try
        {
                $response = $solr->search('solr', 0, 10,
                        array(/* you can include other parameters here */));

                echo 'search returned with status = ', $response->responseHeader->status,
                        ' and took ', microtime(true) - $start, ' seconds', "\n";

                //here's how you would access results
                //Notice that I've mapped the values by name into a tree of stdClass objects
                //and arrays (actually, most of this is done by json_decode )
                if ($response->response->numFound > 0)
                {
                        $doc_number = $response->response->start;

                        foreach ($response->response->docs as $doc)
                        {
                                $doc_number++;

                                echo $doc_number, ': ', $doc->text, "\n";
                        }
                }

                //for the purposes of seeing the available structure of the response
                //NOTE: Solr_Response::_parsedData is lazy loaded, so a print_r on the response before
                //any values are accessed may result in different behavior (in case
                //anyone has some troubles debugging)
                //print_r($response);
        }
        catch (Exception $e)
        {
                echo $e->getMessage(), "\n";
        }

        ?>
        Hide
        Donovan Jimenez added a comment -

        Attaching a new zip because previous had bug in Solr_Service::escape function

        Show
        Donovan Jimenez added a comment - Attaching a new zip because previous had bug in Solr_Service::escape function
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12364182 ]
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12364169 ]
        Hide
        Donovan Jimenez added a comment -

        Updates to the Solr Client:

        • search can now take muliple parameters of the same name, such as when using facets
        • ping now can take a timeout value which acts as a maximum time allowed to wait for a response
        • namespace change to Apache_Solr to avoid confusion with php Solar (unrelated) project
        • Apache_Solr_Document now implements iterator interface, so its fields can be foreach'd
        • Reference implementation of a read from slave / write to master balancer has be added
        Show
        Donovan Jimenez added a comment - Updates to the Solr Client: search can now take muliple parameters of the same name, such as when using facets ping now can take a timeout value which acts as a maximum time allowed to wait for a response namespace change to Apache_Solr to avoid confusion with php Solar (unrelated) project Apache_Solr_Document now implements iterator interface, so its fields can be foreach'd Reference implementation of a read from slave / write to master balancer has be added
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12366939 ]
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12364182 ]
        An Vu made changes -
        Comment [ If result of solr has {{\n}} character in a field, this script show nothing.

        I found that when the $_rawResponse (in Apache_Solr_Response class) has {{\n}} character, the json_decode function will return null. So, to solve this issue, the \n character must be replace by {noformat}\\n{noformat} in $_rawResponse.

        This is an example
        bq.{"responseHeader":{"status":0,"QTime":1,"params":{"start":"0","q":"job.title:Chuyên","wt":"json","rows":"10","version":"2.2"}},"response":{"numFound":1,"start":0,"docs":[{"job.contact_phone":"(04) 773 70 70","job.career_level_id":1,"job.code":"C01","job.invoice_address":"71 Nguyễn Chí Thanh","job.description":"Tham gia các dự án Tư vấn Tài chính doanh nghiệp cho các khách hàng, đối tác.\n­Tiếp xúc, thu thập, phân tích thông tin và đưa ra các báo cáo tư vấn cho khách hàng về các nghiệp vụ Cổ phần hóa, Định giá doanh nghiệp,Tư vấn phát hành, Tư vấn niêm yết chứng khoán, Tư vấn Tái cấu trúc vốn, Tư vấn bảo lãnh phát hành...\nThực hiện các nhiệm vụ khác theo yêu cầu của Trưởng bộ phận. ","job.desired_skills":"","job.activated_date":"2007-10-05T10:59:07.054Z","job.company_mobile_phone":"","job.contact_country_id":1,"job.invoice_type":"","job.invoice_country_id":1,"job.auto_response_email_id":,"job.skills":"Tốt nghiệp Đại học chuyên nghành về Tài chính, Kế toán. Ưu tiên ứng cử viên học ACCA, hoặc CFA, hoặc có chứng chỉ CPA.­\nCó tối thiểu 03 năm kinh nghiệm làm việc trong lĩnh vực liên quan.\nCó khả năng giao tiếp, truyền đạt và thuyết phục tốt. ­Trung thực, nhiệt tình và trách nhiệm cao trong công việc.\nThành thạo tiếng Anh, vi tính văn phòng.","job.contact_instruction":"Đơn xin việc - Sơ yếu lý lịch\nBản sao các bằng cấp liên quan\nGiấy khám sức khỏe (trong vòng 6 tháng)\nBản sao Giấy khai sinh\n02 ảnh 4x6 (ảnh chụp mới nhất).\nChấp nhận hồ sơ gửi qua email\nNộp đơn qua địa chỉ email:\nhuyennt@fpts.com.vn\nhuonglt@fpts.com.vn\nHoặc theo địa chỉ:71 Nguyễn Chí Thanh, Đống Đa, Hà Nội","job.suspended":true,"job.salary_min":600,"job.salary_type":"S","job.post_date":"NOW-2DAY","job.invoice_city_id":1,"job.contact_district":"Đống Đa","job.company_size_id":1,"job.title":"Chuyên viên tư vấn tài chính doanh nghiệp","job.company_website":"http://fpts.com.vn","job.degree_required_id":1,"job.employer_id":1,"job.company_address":"71 Nguyễn Chí Thanh","job.contact_mobile_phone":"","job.stripped_title":"Chuyen-vien-tu-van-tai-chinh-doanh-nghiep","job.company_name":"Công ty Cổ Phần Chứng Khoán FPT","job.company_description":"FPTS mong muốn trở thành một định chế tài chính hùng mạnh, bằng nỗ lực xây dựng đội ngũ cán bộ và năng lực công nghệ, mang lại những sản phẩm dịch vụ chất lượng cao nhất cho khách hàng và cuộc sống đầy đủ về vật chất, phong phú về tinh thần cho mọi thành viên\".","job.expire_date":"NOW+30DAY","job.activated":true,"job.company_email":"huonglt@fpts.com.vn","job.career_level_required_id":1,"job.id":1,"job.salary_max":600,"job.invoice_district":"Đống Đa","job.year_of_experience":"1","job.company_city_id":1,"job.company_contact":"Luong Thanh Huong","job.company_fax":"(04) 773 90 58","job.featured_job_expire":"NOW+7DAY","job.contact_fax":"(04) 773 90 58","job.company_phone":"(04) 773 70 70","job.invoice_tax":"","job.contact_city_id":1,"job.contact_company_name":"Công ty Cổ Phần Chứng Khoán FPT","job.contact_name":"Luong Thanh Huong","job.company_country_id":1,"job.featured":false,"job.degree_id":1,"job.company_district":"Đống Đa","job.invoice_company_name":"Công ty Cổ Phần Chứng Khoán FPT","job.contact_address":"71 Nguyễn Chí Thanh","job.contact_email":"huonglt@fpts.com.vn","timestamp":"2007-10-05T10:59:07.057Z","popularity":0}]}}
        ]
        Hide
        Donovan Jimenez added a comment -

        Updates to PHP client

        • fixes Apache_Solr_Document::setMultiValue typo
        • Apache_Solr_Service_Balancer fixes
        • Apache_Solr_Service / Apache_Solr_Response now use the json.nl parameter for NamedList handling at the Solr server side instead of doing PHP client side
        • Apache_Solr_Service::commit() method signature has changed for optimize parameter
        • Included a Changelog file generated from subversion
        Show
        Donovan Jimenez added a comment - Updates to PHP client fixes Apache_Solr_Document::setMultiValue typo Apache_Solr_Service_Balancer fixes Apache_Solr_Service / Apache_Solr_Response now use the json.nl parameter for NamedList handling at the Solr server side instead of doing PHP client side Apache_Solr_Service::commit() method signature has changed for optimize parameter Included a Changelog file generated from subversion
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12373807 ]
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12366939 ]
        Hide
        Mark Lindeman added a comment - - edited

        it would be nice to have support for custom instances of StandardRequestHandler. Apache_Solr_Service now uses a class constant SEARCH_SERVLET to build it's query.

        A quick fix would be:
        add extra parameter to function search:
        public function search($query, $offset = 0, $limit = 10, $params = array(), $search_servlet = null)

        and change last line of this function to:
        $searchUrl = $search_servlet==null ? $this->_searchUrl : $this->_constructUrl($search_servlet);
        return $this->_sendRawGet($searchUrl . $this->_queryDelimiter . $queryString);

        Another wish:
        please make your methods and object variables "protected" in stead of "private" so we can extend your great Class.

        Show
        Mark Lindeman added a comment - - edited it would be nice to have support for custom instances of StandardRequestHandler. Apache_Solr_Service now uses a class constant SEARCH_SERVLET to build it's query. A quick fix would be: add extra parameter to function search: public function search($query, $offset = 0, $limit = 10, $params = array(), $search_servlet = null) and change last line of this function to: $searchUrl = $search_servlet==null ? $this->_searchUrl : $this->_constructUrl($search_servlet); return $this->_sendRawGet($searchUrl . $this->_queryDelimiter . $queryString); Another wish: please make your methods and object variables "protected" in stead of "private" so we can extend your great Class.
        Hide
        Donovan Jimenez added a comment -

        Made private members and functions protected so that they could be used / overridden by subclasses. See included changelog for other changes.

        Show
        Donovan Jimenez added a comment - Made private members and functions protected so that they could be used / overridden by subclasses. See included changelog for other changes.
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-09-02.zip [ 12389347 ]
        Otis Gospodnetic made changes -
        Fix Version/s 1.4 [ 12313351 ]
        Hide
        Rich R added a comment - - edited

        Hi

        I've encountered an issue in the _documentToXmlFragment() method of the Apache_Solr_Service class.

        To cut a long story short, I'm building up documents from database rows, some of which contain NULL values. I've noticed that NULL values interfere with the following (Iterator-based) code in the above method:

        foreach ($document as $key => $value)
        {
        ...

        What basically happens is that a NULL $value seems to cause the foreach loop to terminate prematurely. Any fields 'beyond' that with the NULL value do not get added to the index.

        The very simple workaround for this was to replace the above code fragment with the following:

        $keys = $document->getFieldNames();
        foreach ($keys as $key)
        {
        $value = $document->$key;
        ...

        As you can see, it's essentially the same, and fully backwards-compatible. It just avoids the issue I've been experiencing with the iterator.

        I'd really like to see this change make it to the code if possible (I can submit a patch if necessary).

        For reference, I'm using PHP 5.3 on OSX.

        Best regards
        Rich

        Show
        Rich R added a comment - - edited Hi I've encountered an issue in the _documentToXmlFragment() method of the Apache_Solr_Service class. To cut a long story short, I'm building up documents from database rows, some of which contain NULL values. I've noticed that NULL values interfere with the following (Iterator-based) code in the above method: foreach ($document as $key => $value) { ... What basically happens is that a NULL $value seems to cause the foreach loop to terminate prematurely. Any fields 'beyond' that with the NULL value do not get added to the index. The very simple workaround for this was to replace the above code fragment with the following: $keys = $document->getFieldNames(); foreach ($keys as $key) { $value = $document->$key; ... As you can see, it's essentially the same, and fully backwards-compatible. It just avoids the issue I've been experiencing with the iterator. I'd really like to see this change make it to the code if possible (I can submit a patch if necessary). For reference, I'm using PHP 5.3 on OSX. Best regards Rich
        Hide
        Donovan Jimenez added a comment -

        Rich Robinson helped me to track down an issue where he found that documents with values = false were creating prematurely exiting foreach loops (when iterating a document). I determined it was the valid() implementation of the Iterator iterface, and after fussing with it decided to just implement IteratorAggregator instead and use the pre-existing SPL ArrayIterator class. This simplifies the Apache_Solr_Document code and now all document values are looped even when some are false.

        Show
        Donovan Jimenez added a comment - Rich Robinson helped me to track down an issue where he found that documents with values = false were creating prematurely exiting foreach loops (when iterating a document). I determined it was the valid() implementation of the Iterator iterface, and after fussing with it decided to just implement IteratorAggregator instead and use the pre-existing SPL ArrayIterator class. This simplifies the Apache_Solr_Document code and now all document values are looped even when some are false.
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-11-14.zip [ 12393965 ]
        Hide
        Pieter Berkel added a comment -

        Hi Donovan,

        Great work on the PHP client library, however I noticed that there is no way to specify document- and/or field-level boost values when creating and indexing documents:

        http://wiki.apache.org/solr/UpdateXmlMessages

        Perhaps Apache_Solr_Document could have a constructor method with an optional parameter for setting the document boost:

        public function __construct($boost = '1.0') {

        Not so sure how the field-level boost should be set, maybe add methods setFieldBoost($key) and getFieldBoost($key) to Apache_Solr_Document?

        If necessary I can also submit code patches for these changes.

        cheers,
        Piete

        Show
        Pieter Berkel added a comment - Hi Donovan, Great work on the PHP client library, however I noticed that there is no way to specify document- and/or field-level boost values when creating and indexing documents: http://wiki.apache.org/solr/UpdateXmlMessages Perhaps Apache_Solr_Document could have a constructor method with an optional parameter for setting the document boost: public function __construct($boost = '1.0') { Not so sure how the field-level boost should be set, maybe add methods setFieldBoost($key) and getFieldBoost($key) to Apache_Solr_Document? If necessary I can also submit code patches for these changes. cheers, Piete
        Hide
        Donovan Jimenez added a comment -

        Added additional functionality to Apache_Solr_Document and Apache_Solr_Service for document and field based boost values.

        $doc = new Apache_Solr_Document();
        
        // can set document boost 
        $doc->setBoost(1.5);
        
        // can set a field boost at value assignment time
        $doc->setField('foo', 'bar', 1.3);
        
        // or as a separate call
        $doc->setFieldBoost('foo', 3.141579);
        
        Show
        Donovan Jimenez added a comment - Added additional functionality to Apache_Solr_Document and Apache_Solr_Service for document and field based boost values. $doc = new Apache_Solr_Document(); // can set document boost $doc->setBoost(1.5); // can set a field boost at value assignment time $doc->setField('foo', 'bar', 1.3); // or as a separate call $doc->setFieldBoost('foo', 3.141579);
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-11-24.zip [ 12394609 ]
        Hide
        Pieter Berkel added a comment -

        Thanks for the quick response, just wanted to check that you uploaded the updated class files? I couldn't find the new setBoost() / setField() / setFieldBoost() methods in the Document class located in SolrPhpClient.2008-11-24.zip

        Show
        Pieter Berkel added a comment - Thanks for the quick response, just wanted to check that you uploaded the updated class files? I couldn't find the new setBoost() / setField() / setFieldBoost() methods in the Document class located in SolrPhpClient.2008-11-24.zip
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-11-24.zip [ 12394609 ]
        Hide
        Donovan Jimenez added a comment -

        You are correct, I didn't zip up the updated files. I did the work on a branch, but my build script takes from trunk.

        This new one should be what you want - i double checked , sorry for the confusion.

        Show
        Donovan Jimenez added a comment - You are correct, I didn't zip up the updated files. I did the work on a branch, but my build script takes from trunk. This new one should be what you want - i double checked , sorry for the confusion.
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-11-25.zip [ 12394706 ]
        Hide
        Mark Lindeman added a comment -

        in Apache/Solr/Document.php on line 218:
        $this->_fieldBoosts = $boost;

        this should be:
        $this->_fieldBoosts[$key] = $boost;

        If I do not use the $fieldboost parameter in setField() method, than I end up with a document full off boost="" parameters which triggers errors in Solr 1.3

        Show
        Mark Lindeman added a comment - in Apache/Solr/Document.php on line 218: $this->_fieldBoosts = $boost; this should be: $this->_fieldBoosts [$key] = $boost; If I do not use the $fieldboost parameter in setField() method, than I end up with a document full off boost="" parameters which triggers errors in Solr 1.3
        Hide
        Shalin Shekhar Mangar added a comment -

        Marked for 1.5

        Show
        Shalin Shekhar Mangar added a comment - Marked for 1.5
        Shalin Shekhar Mangar made changes -
        Fix Version/s 1.4 [ 12313351 ]
        Fix Version/s 1.5 [ 12313566 ]
        Hide
        Nick Martin added a comment -

        Revision 5 of PhpSolrClient is used by the apachesolr Drupal module (http://drupal.org/project/apachesolr). That revision of the code is absent from this site, but the apachesolr readme.txt lists downloading code from here as a viable option. Unfortunately the older versions of the code posted here do not work. Could you please post revision 5 here?

        Thanks!

        Show
        Nick Martin added a comment - Revision 5 of PhpSolrClient is used by the apachesolr Drupal module ( http://drupal.org/project/apachesolr ). That revision of the code is absent from this site, but the apachesolr readme.txt lists downloading code from here as a viable option. Unfortunately the older versions of the code posted here do not work. Could you please post revision 5 here? Thanks!
        Hide
        Peter Wolanin added a comment -

        r6 has been bundled into a release: http://code.google.com/p/solr-php-client/downloads/list

        We'll test this with the Drupal module soon, but is likely to work fine.

        Show
        Peter Wolanin added a comment - r6 has been bundled into a release: http://code.google.com/p/solr-php-client/downloads/list We'll test this with the Drupal module soon, but is likely to work fine.
        Hide
        Donovan Jimenez added a comment -

        updated issue text to reflect new file hosting on Google Code.

        Show
        Donovan Jimenez added a comment - updated issue text to reflect new file hosting on Google Code.
        Donovan Jimenez made changes -
        Description Developed this client when the example PHP source didn't meet our needs. The company I work for agreed to release it under the terms of the Apache License.

        This version is slightly different from what I originally linked to on the dev mailing list. I've incorporated feedback from Yonik and "hossman" to simplify the client and only accept one response format (JSON currently).

        When Solr 1.3 is released the client can be updated to use the PHP or Serialized PHP response writer.

        example usage from my original mailing list post:

        <?php
        require_once('Solr/Service.php');

        $start = microtime(true);

        $solr = new Solr_Service(); //Or explicitly new Solr_Service('localhost', 8180, '/solr');

        try
        {
                $response = $solr->search('solr', 0, 10,
                        array(/* you can include other parameters here */));

                echo 'search returned with status = ', $response->responseHeader->status,
                        ' and took ', microtime(true) - $start, ' seconds', "\n";

                //here's how you would access results
                //Notice that I've mapped the values by name into a tree of stdClass objects
                //and arrays (actually, most of this is done by json_decode )
                if ($response->response->numFound > 0)
                {
                        $doc_number = $response->response->start;

                        foreach ($response->response->docs as $doc)
                        {
                                $doc_number++;

                                echo $doc_number, ': ', $doc->text, "\n";
                        }
                }

                //for the purposes of seeing the available structure of the response
                //NOTE: Solr_Response::_parsedData is lazy loaded, so a print_r on the response before
                //any values are accessed may result in different behavior (in case
                //anyone has some troubles debugging)
                //print_r($response);
        }
        catch (Exception $e)
        {
                echo $e->getMessage(), "\n";
        }

        ?>
        Since I'm unable to currently update the Solr WIKI page that points to this issue and its downloads, I've left this issue open. I, however, need to note that active releases of the PHP code are now available from:

        http://code.google.com/p/solr-php-client/downloads/list

        If you have any issues specific to this PHP client, please post / discuss them there (or on the solr user mailing list - I am a subscriber).
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.zip [ 12373807 ]
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-11-25.zip [ 12394706 ]
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-09-02.zip [ 12389347 ]
        Donovan Jimenez made changes -
        Attachment SolrPhpClient.2008-11-14.zip [ 12393965 ]
        Hide
        Donovan Jimenez added a comment -

        Now that the Solr integration in PHP wiki page is updated to reflect the new download location for the client this issue no longer needs to stay open.

        Show
        Donovan Jimenez added a comment - Now that the Solr integration in PHP wiki page is updated to reflect the new download location for the client this issue no longer needs to stay open.
        Donovan Jimenez made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Donovan Jimenez
          • Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development