You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by "An Vu (JIRA)" <ji...@apache.org> on 2007/10/06 06:49:50 UTC

[jira] Issue Comment Edited: (SOLR-341) PHP Solr Client

    [ https://issues.apache.org/jira/browse/SOLR-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12532821 ] 

pliersn edited comment on SOLR-341 at 10/5/07 9:48 PM:
-----------------------------------------------------

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}]}}


      was (Author: pliersn):
    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 \\n in $_rawResponse.

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}]}}

  
> PHP Solr Client
> ---------------
>
>                 Key: SOLR-341
>                 URL: https://issues.apache.org/jira/browse/SOLR-341
>             Project: Solr
>          Issue Type: New Feature
>          Components: clients - php
>    Affects Versions: 1.2
>         Environment: PHP >= 5.2.0 (or older with JSON PECL extension or other json_decode function implementation). Solr >= 1.2
>            Reporter: Donovan Jimenez
>            Priority: Trivial
>         Attachments: SolrPhpClient.zip
>
>
> 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";
> }
> ?>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.