You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2006/09/19 07:14:12 UTC

[Solr Wiki] Update of "SolrUpdate" by BrianLucas

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The following page has been changed by BrianLucas:
http://wiki.apache.org/solr/SolrUpdate

------------------------------------------------------------------------------
  {{{
  <?
  	
- 	// VERSION SolrUpdate 0.100
+ 	// VERSION SolrUpdate 0.200
  	// Written by Brian Lucas, use any which way you see fit.
  	
  	// DESCRIPTION
@@ -179, +179 @@

  		$dom = new DomDocument();
  		$root_element = $dom->createElement('add');
  		$root = $dom->appendChild($root_element);
+ 
+                 // exclude these values from standard processing, handle them in special cases below
+ 		$excludearray = array("dontincludeme");
+ 
  		if($resultarray) foreach($resultarray as $num=>$array) {
  
  			$doc_element = $dom->createElement('doc');
  			$doc = $root->appendChild($doc_element);
  
+    			foreach ( $array as $elementname => $elementvalue ) {
+ 				if (!(in_array($elementname, $excludearray))) { // only run if this isn't excluded from processing
+ 					if(($elementvalue != null)&&(!is_numeric($elementname))) { // ADODB passes numeric entities alongside fieldnames
- 			// add node for each row
- 			$story_id_element = $dom->createElement('field');
- 			$story_id_element->setAttribute('name', 'story_id');
- 			$story_id_text = $dom->createTextNode($array['story_id']);
- 			$story_id_element->appendChild($story_id_text);
- 			$story_id = $doc->appendChild($story_id_element);
- 	
- 			// add node for each row
- 			$group_id_element = $dom->createElement('field');
- 			$group_id_element->setAttribute('name', 'group_id');
- 			$group_id_text = $dom->createTextNode($array['group_id']);
- 			$group_id_element->appendChild($group_id_text);
- 			
- 			$group_id = $doc->appendChild($group_id_element);
- 		
- 			// Basic error checking
- 			if($array["lucene_date"] != null) {
- 				$date_element = $dom->createElement('field');
+ 						$element = $dom->createElement('field');
- 				$date_element->setAttribute('name', 'lucene_date');
+ 						$element->setAttribute('name', $elementname);
- 				$date_text = $dom->createTextNode($array['lucene_date']);
- 				$date_element->appendChild($date_text);
+ 						$elementfinal = $dom->createTextNode($this->escapeChars($elementvalue));
+ 						$element->appendChild($elementfinal);
+ 						$doc->appendChild($element);
+ 					}
- 				
+ 				}
- 				$date = $doc->appendChild($date_element);
  			}
- 			 
- 			
- 			
- 			$title_element = $dom->createElement('field');
- 			$title_element->setAttribute('name', 'title');
- 	 		$title_text = $dom->createTextNode($array['title']);
- 			$title = $doc->appendChild($title_element-);
  			
  		} // end if /foreach
  		
@@ -251, +235 @@

  		return $string;
  	}
  	
+         // the following update DOES work.  If you are having problems, make sure your SOLR install is working properly.
  	function sendUpdate($post_string) {
- 		
- 		$url = "http://".SOLR_META_UPDATE;
+ 		$url = "http://".SOLR_META_UPDATE."/solr/update";
- 		$page = "/solr/update";
- 	
- 		$header  = "POST ".$page." HTTP/1.0 \r\n";
- 		$header .= "MIME-Version: 1.0 \r\n";
- 		$header .= "Content-type: application/PTI26 \r\n";
- 		$header .= "Content-length: ".strlen($post_string)." \r\n";
- 		$header .= "Content-transfer-encoding: text \r\n";
- 		$header .= "Request-number: 1 \r\n";
- 		$header .= "Document-type: Request \r\n";
- 		$header .= "Interface-Version: Test 1.4 \r\n";
- 		$header .= "Connection: close \r\n\r\n";
- 		$header .= $post_string;
- 
  		$ch = curl_init();
  		curl_setopt($ch, CURLOPT_URL,$url);
+ 		curl_setopt($ch, CURLOPT_POST, 1);
+ 		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_string);
  		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- 		curl_setopt($ch, CURLOPT_TIMEOUT, 15);
- 		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
- 		
  		$data = curl_exec($ch);
- 
  		if (curl_errno($ch)) {
- 			print curl_error($ch);
+ 			print "curl_error:".curl_error($ch);
  			return false;
- 
  		} else {
  			curl_close($ch);
  			if ( strstr ( $data, '<result status="0"></result>')) {