473,473 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

php solr client

omerbutt
638 Contributor
hi
i am trying to use pache solr with php i have bitnami apache solr and php-solr client installed , i am trying to run the example code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   require_once( 'Solr/Service.php' );
  3.  
  4.   // 
  5.   // 
  6.   // Try to connect to the named server, port, and url
  7.   // 
  8.   $solr = new Apache_Solr_Service( 'localhost', '8983', '/solr' );
  9.  
  10.   if ( ! $solr->ping() ) {
  11.     echo 'Solr service not responding.';
  12.     exit;
  13.   }
  14.   //
  15.   //
  16.   // Create two documents to represent two auto parts.
  17.   // In practice, documents would likely be assembled from a 
  18.   //   database query. 
  19.   //
  20.   $parts = array(
  21.     'spark_plug' => array(
  22.  
  23.       'name' => 'Spark plug',
  24.  
  25.     ),
  26.     'windshield' => array(
  27.  
  28.       'name' => 'Windshield',
  29.  
  30.     )
  31.   );
  32.  
  33.   $documents = array();
  34.  
  35.   foreach ( $parts as $item => $fields ) {
  36.     $part = new Apache_Solr_Document();
  37.  
  38.     foreach ( $fields as $key => $value ) {
  39.       if ( is_array( $value ) ) {
  40.         foreach ( $value as $datum ) {
  41.           $part->setMultiValue( $key, $datum );
  42.         }
  43.       }
  44.       else {
  45.         $part->$key = $value;
  46.       }
  47.     }
  48.  
  49.     $documents[] = $part;
  50.   }
  51.  
  52.   //
  53.   //
  54.   // Load the documents into the index
  55.   // 
  56.   try {
  57.     $solr->addDocuments( $documents );
  58.     $solr->commit();
  59.     $solr->optimize();
  60.   }
  61.   catch ( Exception $e ) {
  62.     echo $e->getMessage();
  63.   }
  64.  
  65.  
  66.   //
  67.   // 
  68.   // Run some queries. Provide the raw path, a starting offset
  69.   //   for result documents, and the maximum number of result
  70.   //   documents to return. You can also use a fourth parameter
  71.   //   to control how results are sorted and highlighted, 
  72.   //   among other options.
  73.   //
  74.   $offset = 0;
  75.   $limit = 10;
  76.  
  77.   $queries = array(
  78.     'name: plug'
  79.   );
  80.  
  81.  
  82.   foreach ( $queries as $query ) {
  83.     $response = $solr->search( $query, $offset, $limit );
  84.     echo '<pre>';
  85.     echo $response->getHttpStatus();
  86.      print_r( $response->getRawResponse() );
  87.      echo $response->response->numFound;
  88.      echo '</pre>';
  89.     break;
  90.     if ( $response->getHttpStatus() == 200 ) { 
  91.       // print_r( $response->getRawResponse() );
  92.  
  93.       if ( $response->response->numFound > 0 ) {
  94.         echo "$query <br />";
  95.  
  96.         foreach ( $response->response->docs as $doc ) { 
  97.           echo "$doc->partno $doc->name <br />";
  98.         }
  99.  
  100.         echo '<br />';
  101.       }
  102.     }
  103.     else {
  104.       echo $response->getHttpStatusMessage();
  105.     }
  106.   }
  107. ?>
  108.  
but it is continiously giving 400 bad request error , can someone help me in this regard , i googled and most of the issues regarding 400 bad request were suggesting to define the fields in the schema.xml but one thing i cant understand is that for the very first time is there any need to load data into it which can be searched , I am confused there are 3 diferent things apache solr and php solr client i downloaded the phpsolr client from
http://code.google.com/p/solr-php-client/downloads/list
regards,
Omer Aslam
Jun 7 '13 #1
1 2005
omerbutt
638 Contributor
i have solved it , this was on the commit() function because solr 4.0 and up versions have deprecated the waitflush parameter in the xml tag , we need to remove this from the optimize() function in the service.php file , do note that we donot need to remove the function parameter but the actual xml tag attribute that is mentioned inthe $rawpost variable

regards,
Omer Aslam
Jun 18 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
11
by: Timothy Shih | last post by:
Hi, I am having a freezing issue with my application. My application serves several remotable objects, all of which must be initialized before their use. Furthermore, some of them depend on each...
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
4
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
8
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.