PHP Operations Solr (PHP SOLR Client)

Source: Internet
Author: User
Tags solr
Download PHP SOLR client:http://code.google.com/p/solr-php-client/downloads/list
# wget http://solr-php-client.googlecode.com/files/SolrPhpClient.r22.2009-11-09.tgz # tar XZVF Solrphpclient.r22.2009-11-09.tgz
Move the file to the Web root # mv solrphpclient/apache//home/www/
New test file: # cd/home/www # vim sorltest.php
<?php include ("apache/solr/service.php");
Connecting to SOLR server $SOLR = new Apache_solr_service (' localhost ', ' 8983 ', '/SOLR ');    if (! $SOLR->ping ()) {echo ' SOLR server not responding '; Exit }
$data = array (' ID ' => ' EN80922032 ', ' name ' => ' men's polished straight-barrel casual jeans ', ' brand ' => ' Energie ', ' cat ' => ' jeans ', ' PR Ice ' => ' 1870.00 '), array (' ID ' => ' EN70906025 ', ' name ' => ' brand logo lapel zipper coat ', ' brand ' => ' Energie ', ' Cat ' => ' Coat ', ' price ' => ' 1680.00 ');
Add Index data $documents = Array ();    foreach ($data as $key => $value) {$part =new apache_solr_document ();     foreach ($value as $key 2 => $value 2) {$part-> $key 2 = $value 2; $documents [] = $part; }
$SOLR->adddocuments ($documents); $SOLR->commit (); $SOLR->optimize ();
Query index $SOLR->search (fields: keywords, beginning, per page display, sort) $offset = 0; $limit = 10; $sort = ' price ASC ';
$rs = $solr->search ("Brand:energie", $offset, $limit, Array (' sort ' => $sort)); if ($rs->response->numfound> 0) {foreach ($rs->response->docs as $doc) {echo $doc->id. ' | '. $doc->name. ' | ' $doc->brand. ' | ' $doc->price. '     <br> '; } }
?>
View: http://localhost/solrtest.php Display results:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.