Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( b34a1c...06de54 )
by Sebastian
03:26 queued 50s
created
dlf/lib/SolrPhpClient/Apache/Solr/Document.php 1 patch
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -57,311 +57,311 @@
 block discarded – undo
57 57
  */
58 58
 class Apache_Solr_Document implements IteratorAggregate
59 59
 {
60
-	/**
61
-	 * SVN Revision meta data for this class
62
-	 */
63
-	const SVN_REVISION = '$Revision: 54 $';
60
+    /**
61
+     * SVN Revision meta data for this class
62
+     */
63
+    const SVN_REVISION = '$Revision: 54 $';
64 64
 
65
-	/**
66
-	 * SVN ID meta data for this class
67
-	 */
68
-	const SVN_ID = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
65
+    /**
66
+     * SVN ID meta data for this class
67
+     */
68
+    const SVN_ID = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
69 69
 
70
-	/**
71
-	 * Document boost value
72
-	 *
73
-	 * @var float
74
-	 */
75
-	protected $_documentBoost = false;
70
+    /**
71
+     * Document boost value
72
+     *
73
+     * @var float
74
+     */
75
+    protected $_documentBoost = false;
76 76
 
77
-	/**
78
-	 * Document field values, indexed by name
79
-	 *
80
-	 * @var array
81
-	 */
82
-	protected $_fields = array();
77
+    /**
78
+     * Document field values, indexed by name
79
+     *
80
+     * @var array
81
+     */
82
+    protected $_fields = array();
83 83
 
84
-	/**
85
-	 * Document field boost values, indexed by name
86
-	 *
87
-	 * @var array array of floats
88
-	 */
89
-	protected $_fieldBoosts = array();
84
+    /**
85
+     * Document field boost values, indexed by name
86
+     *
87
+     * @var array array of floats
88
+     */
89
+    protected $_fieldBoosts = array();
90 90
 
91
-	/**
92
-	 * Clear all boosts and fields from this document
93
-	 */
94
-	public function clear()
95
-	{
96
-		$this->_documentBoost = false;
91
+    /**
92
+     * Clear all boosts and fields from this document
93
+     */
94
+    public function clear()
95
+    {
96
+        $this->_documentBoost = false;
97 97
 
98
-		$this->_fields = array();
99
-		$this->_fieldBoosts = array();
100
-	}
98
+        $this->_fields = array();
99
+        $this->_fieldBoosts = array();
100
+    }
101 101
 
102
-	/**
103
-	 * Get current document boost
104
-	 *
105
-	 * @return mixed will be false for default, or else a float
106
-	 */
107
-	public function getBoost()
108
-	{
109
-		return $this->_documentBoost;
110
-	}
102
+    /**
103
+     * Get current document boost
104
+     *
105
+     * @return mixed will be false for default, or else a float
106
+     */
107
+    public function getBoost()
108
+    {
109
+        return $this->_documentBoost;
110
+    }
111 111
 
112
-	/**
113
-	 * Set document boost factor
114
-	 *
115
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
116
-	 */
117
-	public function setBoost($boost)
118
-	{
119
-		$boost = (float) $boost;
112
+    /**
113
+     * Set document boost factor
114
+     *
115
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
116
+     */
117
+    public function setBoost($boost)
118
+    {
119
+        $boost = (float) $boost;
120 120
 
121
-		if ($boost > 0.0)
122
-		{
123
-			$this->_documentBoost = $boost;
124
-		}
125
-		else
126
-		{
127
-			$this->_documentBoost = false;
128
-		}
129
-	}
121
+        if ($boost > 0.0)
122
+        {
123
+            $this->_documentBoost = $boost;
124
+        }
125
+        else
126
+        {
127
+            $this->_documentBoost = false;
128
+        }
129
+    }
130 130
 
131
-	/**
132
-	 * Add a value to a multi-valued field
133
-	 *
134
-	 * NOTE: the solr XML format allows you to specify boosts
135
-	 * PER value even though the underlying Lucene implementation
136
-	 * only allows a boost per field. To remedy this, the final
137
-	 * field boost value will be the product of all specified boosts
138
-	 * on field values - this is similar to SolrJ's functionality.
139
-	 *
140
-	 * <code>
141
-	 * $doc = new Apache_Solr_Document();
142
-	 *
143
-	 * $doc->addField('foo', 'bar', 2.0);
144
-	 * $doc->addField('foo', 'baz', 3.0);
145
-	 *
146
-	 * // resultant field boost will be 6!
147
-	 * echo $doc->getFieldBoost('foo');
148
-	 * </code>
149
-	 *
150
-	 * @param string $key
151
-	 * @param mixed $value
152
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
153
-	 */
154
-	public function addField($key, $value, $boost = false)
155
-	{
156
-		if (!isset($this->_fields[$key]))
157
-		{
158
-			// create holding array if this is the first value
159
-			$this->_fields[$key] = array();
160
-		}
161
-		else if (!is_array($this->_fields[$key]))
162
-		{
163
-			// move existing value into array if it is not already an array
164
-			$this->_fields[$key] = array($this->_fields[$key]);
165
-		}
131
+    /**
132
+     * Add a value to a multi-valued field
133
+     *
134
+     * NOTE: the solr XML format allows you to specify boosts
135
+     * PER value even though the underlying Lucene implementation
136
+     * only allows a boost per field. To remedy this, the final
137
+     * field boost value will be the product of all specified boosts
138
+     * on field values - this is similar to SolrJ's functionality.
139
+     *
140
+     * <code>
141
+     * $doc = new Apache_Solr_Document();
142
+     *
143
+     * $doc->addField('foo', 'bar', 2.0);
144
+     * $doc->addField('foo', 'baz', 3.0);
145
+     *
146
+     * // resultant field boost will be 6!
147
+     * echo $doc->getFieldBoost('foo');
148
+     * </code>
149
+     *
150
+     * @param string $key
151
+     * @param mixed $value
152
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
153
+     */
154
+    public function addField($key, $value, $boost = false)
155
+    {
156
+        if (!isset($this->_fields[$key]))
157
+        {
158
+            // create holding array if this is the first value
159
+            $this->_fields[$key] = array();
160
+        }
161
+        else if (!is_array($this->_fields[$key]))
162
+        {
163
+            // move existing value into array if it is not already an array
164
+            $this->_fields[$key] = array($this->_fields[$key]);
165
+        }
166 166
 
167
-		if ($this->getFieldBoost($key) === false)
168
-		{
169
-			// boost not already set, set it now
170
-			$this->setFieldBoost($key, $boost);
171
-		}
172
-		else if ((float) $boost > 0.0)
173
-		{
174
-			// multiply passed boost with current field boost - similar to SolrJ implementation
175
-			$this->_fieldBoosts[$key] *= (float) $boost;
176
-		}
167
+        if ($this->getFieldBoost($key) === false)
168
+        {
169
+            // boost not already set, set it now
170
+            $this->setFieldBoost($key, $boost);
171
+        }
172
+        else if ((float) $boost > 0.0)
173
+        {
174
+            // multiply passed boost with current field boost - similar to SolrJ implementation
175
+            $this->_fieldBoosts[$key] *= (float) $boost;
176
+        }
177 177
 
178
-		// add value to array
179
-		$this->_fields[$key][] = $value;
180
-	}
178
+        // add value to array
179
+        $this->_fields[$key][] = $value;
180
+    }
181 181
 
182
-	/**
183
-	 * Handle the array manipulation for a multi-valued field
184
-	 *
185
-	 * @param string $key
186
-	 * @param string $value
187
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
188
-	 *
189
-	 * @deprecated Use addField(...) instead
190
-	 */
191
-	public function setMultiValue($key, $value, $boost = false)
192
-	{
193
-		$this->addField($key, $value, $boost);
194
-	}
182
+    /**
183
+     * Handle the array manipulation for a multi-valued field
184
+     *
185
+     * @param string $key
186
+     * @param string $value
187
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
188
+     *
189
+     * @deprecated Use addField(...) instead
190
+     */
191
+    public function setMultiValue($key, $value, $boost = false)
192
+    {
193
+        $this->addField($key, $value, $boost);
194
+    }
195 195
 
196
-	/**
197
-	 * Get field information
198
-	 *
199
-	 * @param string $key
200
-	 * @return mixed associative array of info if field exists, false otherwise
201
-	 */
202
-	public function getField($key)
203
-	{
204
-		if (isset($this->_fields[$key]))
205
-		{
206
-			return array(
207
-				'name' => $key,
208
-				'value' => $this->_fields[$key],
209
-				'boost' => $this->getFieldBoost($key)
210
-			);
211
-		}
196
+    /**
197
+     * Get field information
198
+     *
199
+     * @param string $key
200
+     * @return mixed associative array of info if field exists, false otherwise
201
+     */
202
+    public function getField($key)
203
+    {
204
+        if (isset($this->_fields[$key]))
205
+        {
206
+            return array(
207
+                'name' => $key,
208
+                'value' => $this->_fields[$key],
209
+                'boost' => $this->getFieldBoost($key)
210
+            );
211
+        }
212 212
 
213
-		return false;
214
-	}
213
+        return false;
214
+    }
215 215
 
216
-	/**
217
-	 * Set a field value. Multi-valued fields should be set as arrays
218
-	 * or instead use the addField(...) function which will automatically
219
-	 * make sure the field is an array.
220
-	 *
221
-	 * @param string $key
222
-	 * @param mixed $value
223
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
224
-	 */
225
-	public function setField($key, $value, $boost = false)
226
-	{
227
-		$this->_fields[$key] = $value;
228
-		$this->setFieldBoost($key, $boost);
229
-	}
216
+    /**
217
+     * Set a field value. Multi-valued fields should be set as arrays
218
+     * or instead use the addField(...) function which will automatically
219
+     * make sure the field is an array.
220
+     *
221
+     * @param string $key
222
+     * @param mixed $value
223
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
224
+     */
225
+    public function setField($key, $value, $boost = false)
226
+    {
227
+        $this->_fields[$key] = $value;
228
+        $this->setFieldBoost($key, $boost);
229
+    }
230 230
 
231
-	/**
232
-	 * Get the currently set field boost for a document field
233
-	 *
234
-	 * @param string $key
235
-	 * @return float currently set field boost, false if one is not set
236
-	 */
237
-	public function getFieldBoost($key)
238
-	{
239
-		return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false;
240
-	}
231
+    /**
232
+     * Get the currently set field boost for a document field
233
+     *
234
+     * @param string $key
235
+     * @return float currently set field boost, false if one is not set
236
+     */
237
+    public function getFieldBoost($key)
238
+    {
239
+        return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false;
240
+    }
241 241
 
242
-	/**
243
-	 * Set the field boost for a document field
244
-	 *
245
-	 * @param string $key field name for the boost
246
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
247
-	 */
248
-	public function setFieldBoost($key, $boost)
249
-	{
250
-		$boost = (float) $boost;
242
+    /**
243
+     * Set the field boost for a document field
244
+     *
245
+     * @param string $key field name for the boost
246
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
247
+     */
248
+    public function setFieldBoost($key, $boost)
249
+    {
250
+        $boost = (float) $boost;
251 251
 
252
-		if ($boost > 0.0)
253
-		{
254
-			$this->_fieldBoosts[$key] = $boost;
255
-		}
256
-		else
257
-		{
258
-			$this->_fieldBoosts[$key] = false;
259
-		}
260
-	}
252
+        if ($boost > 0.0)
253
+        {
254
+            $this->_fieldBoosts[$key] = $boost;
255
+        }
256
+        else
257
+        {
258
+            $this->_fieldBoosts[$key] = false;
259
+        }
260
+    }
261 261
 
262
-	/**
263
-	 * Return current field boosts, indexed by field name
264
-	 *
265
-	 * @return array
266
-	 */
267
-	public function getFieldBoosts()
268
-	{
269
-		return $this->_fieldBoosts;
270
-	}
262
+    /**
263
+     * Return current field boosts, indexed by field name
264
+     *
265
+     * @return array
266
+     */
267
+    public function getFieldBoosts()
268
+    {
269
+        return $this->_fieldBoosts;
270
+    }
271 271
 
272
-	/**
273
-	 * Get the names of all fields in this document
274
-	 *
275
-	 * @return array
276
-	 */
277
-	public function getFieldNames()
278
-	{
279
-		return array_keys($this->_fields);
280
-	}
272
+    /**
273
+     * Get the names of all fields in this document
274
+     *
275
+     * @return array
276
+     */
277
+    public function getFieldNames()
278
+    {
279
+        return array_keys($this->_fields);
280
+    }
281 281
 
282
-	/**
283
-	 * Get the values of all fields in this document
284
-	 *
285
-	 * @return array
286
-	 */
287
-	public function getFieldValues()
288
-	{
289
-		return array_values($this->_fields);
290
-	}
282
+    /**
283
+     * Get the values of all fields in this document
284
+     *
285
+     * @return array
286
+     */
287
+    public function getFieldValues()
288
+    {
289
+        return array_values($this->_fields);
290
+    }
291 291
 
292
-	/**
293
-	 * IteratorAggregate implementation function. Allows usage:
294
-	 *
295
-	 * <code>
296
-	 * foreach ($document as $key => $value)
297
-	 * {
298
-	 * 	...
299
-	 * }
300
-	 * </code>
301
-	 */
302
-	public function getIterator()
303
-	{
304
-		$arrayObject = new ArrayObject($this->_fields);
292
+    /**
293
+     * IteratorAggregate implementation function. Allows usage:
294
+     *
295
+     * <code>
296
+     * foreach ($document as $key => $value)
297
+     * {
298
+     * 	...
299
+     * }
300
+     * </code>
301
+     */
302
+    public function getIterator()
303
+    {
304
+        $arrayObject = new ArrayObject($this->_fields);
305 305
 
306
-		return $arrayObject->getIterator();
307
-	}
306
+        return $arrayObject->getIterator();
307
+    }
308 308
 
309
-	/**
310
-	 * Magic get for field values
311
-	 *
312
-	 * @param string $key
313
-	 * @return mixed
314
-	 */
315
-	public function __get($key)
316
-	{
317
-		if (isset($this->_fields[$key]))
318
-		{
319
-			return $this->_fields[$key];
320
-		}
309
+    /**
310
+     * Magic get for field values
311
+     *
312
+     * @param string $key
313
+     * @return mixed
314
+     */
315
+    public function __get($key)
316
+    {
317
+        if (isset($this->_fields[$key]))
318
+        {
319
+            return $this->_fields[$key];
320
+        }
321 321
 		
322
-		return null;
323
-	}
322
+        return null;
323
+    }
324 324
 
325
-	/**
326
-	 * Magic set for field values. Multi-valued fields should be set as arrays
327
-	 * or instead use the addField(...) function which will automatically
328
-	 * make sure the field is an array.
329
-	 *
330
-	 * @param string $key
331
-	 * @param mixed $value
332
-	 */
333
-	public function __set($key, $value)
334
-	{
335
-		$this->setField($key, $value);
336
-	}
325
+    /**
326
+     * Magic set for field values. Multi-valued fields should be set as arrays
327
+     * or instead use the addField(...) function which will automatically
328
+     * make sure the field is an array.
329
+     *
330
+     * @param string $key
331
+     * @param mixed $value
332
+     */
333
+    public function __set($key, $value)
334
+    {
335
+        $this->setField($key, $value);
336
+    }
337 337
 
338
-	/**
339
-	 * Magic isset for fields values.  Do not call directly. Allows usage:
340
-	 *
341
-	 * <code>
342
-	 * isset($document->some_field);
343
-	 * </code>
344
-	 *
345
-	 * @param string $key
346
-	 * @return boolean
347
-	 */
348
-	public function __isset($key)
349
-	{
350
-		return isset($this->_fields[$key]);
351
-	}
338
+    /**
339
+     * Magic isset for fields values.  Do not call directly. Allows usage:
340
+     *
341
+     * <code>
342
+     * isset($document->some_field);
343
+     * </code>
344
+     *
345
+     * @param string $key
346
+     * @return boolean
347
+     */
348
+    public function __isset($key)
349
+    {
350
+        return isset($this->_fields[$key]);
351
+    }
352 352
 
353
-	/**
354
-	 * Magic unset for field values. Do not call directly. Allows usage:
355
-	 *
356
-	 * <code>
357
-	 * unset($document->some_field);
358
-	 * </code>
359
-	 *
360
-	 * @param string $key
361
-	 */
362
-	public function __unset($key)
363
-	{
364
-		unset($this->_fields[$key]);
365
-		unset($this->_fieldBoosts[$key]);
366
-	}
353
+    /**
354
+     * Magic unset for field values. Do not call directly. Allows usage:
355
+     *
356
+     * <code>
357
+     * unset($document->some_field);
358
+     * </code>
359
+     *
360
+     * @param string $key
361
+     */
362
+    public function __unset($key)
363
+    {
364
+        unset($this->_fields[$key]);
365
+        unset($this->_fieldBoosts[$key]);
366
+    }
367 367
 }
368 368
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/InvalidArgumentException.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_InvalidArgumentException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/NoServiceAvailableException.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_NoServiceAvailableException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Service/Balancer.php 1 patch
Indentation   +857 added lines, -857 removed lines patch added patch discarded remove patch
@@ -50,865 +50,865 @@
 block discarded – undo
50 50
  */
51 51
 class Apache_Solr_Service_Balancer
52 52
 {
53
-	/**
54
-	 * SVN Revision meta data for this class
55
-	 */
56
-	const SVN_REVISION = '$Revision: 54 $';
57
-
58
-	/**
59
-	 * SVN ID meta data for this class
60
-	 */
61
-	const SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
62
-
63
-	protected $_createDocuments = true;
64
-
65
-	protected $_readableServices = array();
66
-	protected $_writeableServices = array();
67
-
68
-	protected $_currentReadService = null;
69
-	protected $_currentWriteService = null;
70
-
71
-	protected $_readPingTimeout = 2;
72
-	protected $_writePingTimeout = 4;
73
-
74
-	// Configuration for server selection backoff intervals
75
-	protected $_useBackoff = false;		// Set to true to use more resillient write server selection
76
-	protected $_backoffLimit = 600;		// 10 minute default maximum
77
-	protected $_backoffEscalation = 2.0; 	// Rate at which to increase backoff period
78
-	protected $_defaultBackoff = 2.0;		// Default backoff interval
79
-
80
-	/**
81
-	 * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
82
-	 *
83
-	 * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
84
-	 *
85
-	 * @param string $value
86
-	 * @return string
87
-	 */
88
-	static public function escape($value)
89
-	{
90
-		return Apache_Solr_Service::escape($value);
91
-	}
92
-
93
-	/**
94
-	 * Escape a value meant to be contained in a phrase for special query characters
95
-	 *
96
-	 * @param string $value
97
-	 * @return string
98
-	 */
99
-	static public function escapePhrase($value)
100
-	{
101
-		return Apache_Solr_Service::escapePhrase($value);
102
-	}
103
-
104
-	/**
105
-	 * Convenience function for creating phrase syntax from a value
106
-	 *
107
-	 * @param string $value
108
-	 * @return string
109
-	 */
110
-	static public function phrase($value)
111
-	{
112
-		return Apache_Solr_Service::phrase($value);
113
-	}
114
-
115
-	/**
116
-	 * Constructor. Takes arrays of read and write service instances or descriptions
117
-	 *
118
-	 * @param array $readableServices
119
-	 * @param array $writeableServices
120
-	 */
121
-	public function __construct($readableServices = array(), $writeableServices = array())
122
-	{
123
-		//setup readable services
124
-		foreach ($readableServices as $service)
125
-		{
126
-			$this->addReadService($service);
127
-		}
128
-
129
-		//setup writeable services
130
-		foreach ($writeableServices as $service)
131
-		{
132
-			$this->addWriteService($service);
133
-		}
134
-	}
135
-
136
-	public function setReadPingTimeout($timeout)
137
-	{
138
-		$this->_readPingTimeout = $timeout;
139
-	}
140
-
141
-	public function setWritePingTimeout($timeout)
142
-	{
143
-		$this->_writePingTimeout = $timeout;
144
-	}
145
-
146
-	public function setUseBackoff($enable)
147
-	{
148
-		$this->_useBackoff = $enable;
149
-	}
150
-
151
-	/**
152
-	 * Generates a service ID
153
-	 *
154
-	 * @param string $host
155
-	 * @param integer $port
156
-	 * @param string $path
157
-	 * @return string
158
-	 */
159
-	protected function _getServiceId($host, $port, $path)
160
-	{
161
-		return $host . ':' . $port . $path;
162
-	}
163
-
164
-	/**
165
-	 * Adds a service instance or service descriptor (if it is already
166
-	 * not added)
167
-	 *
168
-	 * @param mixed $service
169
-	 *
170
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
171
-	 */
172
-	public function addReadService($service)
173
-	{
174
-		if ($service instanceof Apache_Solr_Service)
175
-		{
176
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
177
-
178
-			$this->_readableServices[$id] = $service;
179
-		}
180
-		else if (is_array($service))
181
-		{
182
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
183
-			{
184
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
185
-
186
-				$this->_readableServices[$id] = $service;
187
-			}
188
-			else
189
-			{
190
-				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
191
-			}
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * Removes a service instance or descriptor from the available services
197
-	 *
198
-	 * @param mixed $service
199
-	 *
200
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
201
-	 */
202
-	public function removeReadService($service)
203
-	{
204
-		$id = '';
205
-
206
-		if ($service instanceof Apache_Solr_Service)
207
-		{
208
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
209
-		}
210
-		else if (is_array($service))
211
-		{
212
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
213
-			{
214
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
215
-			}
216
-			else
217
-			{
218
-				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
219
-			}
220
-		}
221
-		else if (is_string($service))
222
-		{
223
-			$id = $service;
224
-		}
225
-
226
-		if ($id && isset($this->_readableServices[$id]))
227
-		{
228
-			unset($this->_readableServices[$id]);
229
-		}
230
-	}
231
-
232
-	/**
233
-	 * Adds a service instance or service descriptor (if it is already
234
-	 * not added)
235
-	 *
236
-	 * @param mixed $service
237
-	 *
238
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
239
-	 */
240
-	public function addWriteService($service)
241
-	{
242
-		if ($service instanceof Apache_Solr_Service)
243
-		{
244
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
245
-
246
-			$this->_writeableServices[$id] = $service;
247
-		}
248
-		else if (is_array($service))
249
-		{
250
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
251
-			{
252
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
253
-
254
-				$this->_writeableServices[$id] = $service;
255
-			}
256
-			else
257
-			{
258
-				throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path');
259
-			}
260
-		}
261
-	}
262
-
263
-	/**
264
-	 * Removes a service instance or descriptor from the available services
265
-	 *
266
-	 * @param mixed $service
267
-	 *
268
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
269
-	 */
270
-	public function removeWriteService($service)
271
-	{
272
-		$id = '';
273
-
274
-		if ($service instanceof Apache_Solr_Service)
275
-		{
276
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
277
-		}
278
-		else if (is_array($service))
279
-		{
280
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
281
-			{
282
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
283
-			}
284
-			else
285
-			{
286
-				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
287
-			}
288
-		}
289
-		else if (is_string($service))
290
-		{
291
-			$id = $service;
292
-		}
293
-
294
-		if ($id && isset($this->_writeableServices[$id]))
295
-		{
296
-			unset($this->_writeableServices[$id]);
297
-		}
298
-	}
299
-
300
-	/**
301
-	 * Iterate through available read services and select the first with a ping
302
-	 * that satisfies configured timeout restrictions (or the default)
303
-	 *
304
-	 * @return Apache_Solr_Service
305
-	 *
306
-	 * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
307
-	 */
308
-	protected function _selectReadService($forceSelect = false)
309
-	{
310
-		if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect)
311
-		{
312
-			if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect)
313
-			{
314
-				// we probably had a communication error, ping the current read service, remove it if it times out
315
-				if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false)
316
-				{
317
-					$this->removeReadService($this->_currentReadService);
318
-				}
319
-			}
320
-
321
-			if (count($this->_readableServices))
322
-			{
323
-				// select one of the read services at random
324
-				$ids = array_keys($this->_readableServices);
325
-
326
-				$id = $ids[rand(0, count($ids) - 1)];
327
-				$service = $this->_readableServices[$id];
328
-
329
-				if (is_array($service))
330
-				{
331
-					//convert the array definition to a client object
332
-					$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
333
-					$this->_readableServices[$id] = $service;
334
-				}
335
-
336
-				$service->setCreateDocuments($this->_createDocuments);
337
-				$this->_currentReadService = $id;
338
-			}
339
-			else
340
-			{
341
-				throw new Apache_Solr_NoServiceAvailableException('No read services were available');
342
-			}
343
-		}
344
-
345
-		return $this->_readableServices[$this->_currentReadService];
346
-	}
347
-
348
-	/**
349
-	 * Iterate through available write services and select the first with a ping
350
-	 * that satisfies configured timeout restrictions (or the default)
351
-	 *
352
-	 * @return Apache_Solr_Service
353
-	 *
354
-	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
355
-	 */
356
-	protected function _selectWriteService($forceSelect = false)
357
-	{
358
-		if($this->_useBackoff)
359
-		{
360
-			return $this->_selectWriteServiceSafe($forceSelect);
361
-		}
362
-
363
-		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
364
-		{
365
-			if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect)
366
-			{
367
-				// we probably had a communication error, ping the current read service, remove it if it times out
368
-				if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false)
369
-				{
370
-					$this->removeWriteService($this->_currentWriteService);
371
-				}
372
-			}
373
-
374
-			if (count($this->_writeableServices))
375
-			{
376
-				// select one of the read services at random
377
-				$ids = array_keys($this->_writeableServices);
378
-
379
-				$id = $ids[rand(0, count($ids) - 1)];
380
-				$service = $this->_writeableServices[$id];
381
-
382
-				if (is_array($service))
383
-				{
384
-					//convert the array definition to a client object
385
-					$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
386
-					$this->_writeableServices[$id] = $service;
387
-				}
388
-
389
-				$this->_currentWriteService = $id;
390
-			}
391
-			else
392
-			{
393
-				throw new Apache_Solr_NoServiceAvailableException('No write services were available');
394
-			}
395
-		}
396
-
397
-		return $this->_writeableServices[$this->_currentWriteService];
398
-	}
399
-
400
-	/**
401
-	 * Iterate through available write services and select the first with a ping
402
-	 * that satisfies configured timeout restrictions (or the default).  The
403
-	 * timeout period will increase until a connection is made or the limit is
404
-	 * reached.   This will allow for increased reliability with heavily loaded
405
-	 * server(s).
406
-	 *
407
-	 * @return Apache_Solr_Service
408
-	 *
409
-	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
410
-	 */
411
-
412
-	protected function _selectWriteServiceSafe($forceSelect = false)
413
-	{
414
-		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
415
-		{
416
-			if (count($this->_writeableServices))
417
-			{
418
-				$backoff = $this->_defaultBackoff;
419
-
420
-				do {
421
-					// select one of the read services at random
422
-					$ids = array_keys($this->_writeableServices);
423
-
424
-					$id = $ids[rand(0, count($ids) - 1)];
425
-					$service = $this->_writeableServices[$id];
426
-
427
-					if (is_array($service))
428
-					{
429
-						//convert the array definition to a client object
430
-						$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
431
-						$this->_writeableServices[$id] = $service;
432
-					}
433
-
434
-					$this->_currentWriteService = $id;
435
-
436
-					$backoff *= $this->_backoffEscalation;
437
-
438
-					if($backoff > $this->_backoffLimit)
439
-					{
440
-						throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441
-					}
442
-
443
-				} while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
444
-			}
445
-			else
446
-			{
447
-				throw new Apache_Solr_NoServiceAvailableException('No write services were available');
448
-			}
449
-		}
450
-
451
-		return $this->_writeableServices[$this->_currentWriteService];
452
-	}
453
-
454
-	/**
455
-	 * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
456
-	 * parse the response and create {@link Apache_Solr_Document} instances in place.
457
-	 *
458
-	 * @param boolean $createDocuments
459
-	 */
460
-	public function setCreateDocuments($createDocuments)
461
-	{
462
-		$this->_createDocuments = (bool) $createDocuments;
463
-
464
-		// set on current read service
465
-		if ($this->_currentReadService)
466
-		{
467
-			$service = $this->_selectReadService();
468
-			$service->setCreateDocuments($createDocuments);
469
-		}
470
-	}
471
-
472
-	/**
473
-	 * Get the current state of the create documents flag.
474
-	 *
475
-	 * @return boolean
476
-	 */
477
-	public function getCreateDocuments()
478
-	{
479
-		return $this->_createDocuments;
480
-	}
53
+    /**
54
+     * SVN Revision meta data for this class
55
+     */
56
+    const SVN_REVISION = '$Revision: 54 $';
57
+
58
+    /**
59
+     * SVN ID meta data for this class
60
+     */
61
+    const SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
62
+
63
+    protected $_createDocuments = true;
64
+
65
+    protected $_readableServices = array();
66
+    protected $_writeableServices = array();
67
+
68
+    protected $_currentReadService = null;
69
+    protected $_currentWriteService = null;
70
+
71
+    protected $_readPingTimeout = 2;
72
+    protected $_writePingTimeout = 4;
73
+
74
+    // Configuration for server selection backoff intervals
75
+    protected $_useBackoff = false;		// Set to true to use more resillient write server selection
76
+    protected $_backoffLimit = 600;		// 10 minute default maximum
77
+    protected $_backoffEscalation = 2.0; 	// Rate at which to increase backoff period
78
+    protected $_defaultBackoff = 2.0;		// Default backoff interval
79
+
80
+    /**
81
+     * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
82
+     *
83
+     * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
84
+     *
85
+     * @param string $value
86
+     * @return string
87
+     */
88
+    static public function escape($value)
89
+    {
90
+        return Apache_Solr_Service::escape($value);
91
+    }
92
+
93
+    /**
94
+     * Escape a value meant to be contained in a phrase for special query characters
95
+     *
96
+     * @param string $value
97
+     * @return string
98
+     */
99
+    static public function escapePhrase($value)
100
+    {
101
+        return Apache_Solr_Service::escapePhrase($value);
102
+    }
103
+
104
+    /**
105
+     * Convenience function for creating phrase syntax from a value
106
+     *
107
+     * @param string $value
108
+     * @return string
109
+     */
110
+    static public function phrase($value)
111
+    {
112
+        return Apache_Solr_Service::phrase($value);
113
+    }
114
+
115
+    /**
116
+     * Constructor. Takes arrays of read and write service instances or descriptions
117
+     *
118
+     * @param array $readableServices
119
+     * @param array $writeableServices
120
+     */
121
+    public function __construct($readableServices = array(), $writeableServices = array())
122
+    {
123
+        //setup readable services
124
+        foreach ($readableServices as $service)
125
+        {
126
+            $this->addReadService($service);
127
+        }
128
+
129
+        //setup writeable services
130
+        foreach ($writeableServices as $service)
131
+        {
132
+            $this->addWriteService($service);
133
+        }
134
+    }
135
+
136
+    public function setReadPingTimeout($timeout)
137
+    {
138
+        $this->_readPingTimeout = $timeout;
139
+    }
140
+
141
+    public function setWritePingTimeout($timeout)
142
+    {
143
+        $this->_writePingTimeout = $timeout;
144
+    }
145
+
146
+    public function setUseBackoff($enable)
147
+    {
148
+        $this->_useBackoff = $enable;
149
+    }
150
+
151
+    /**
152
+     * Generates a service ID
153
+     *
154
+     * @param string $host
155
+     * @param integer $port
156
+     * @param string $path
157
+     * @return string
158
+     */
159
+    protected function _getServiceId($host, $port, $path)
160
+    {
161
+        return $host . ':' . $port . $path;
162
+    }
163
+
164
+    /**
165
+     * Adds a service instance or service descriptor (if it is already
166
+     * not added)
167
+     *
168
+     * @param mixed $service
169
+     *
170
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
171
+     */
172
+    public function addReadService($service)
173
+    {
174
+        if ($service instanceof Apache_Solr_Service)
175
+        {
176
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
177
+
178
+            $this->_readableServices[$id] = $service;
179
+        }
180
+        else if (is_array($service))
181
+        {
182
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
183
+            {
184
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
185
+
186
+                $this->_readableServices[$id] = $service;
187
+            }
188
+            else
189
+            {
190
+                throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
191
+            }
192
+        }
193
+    }
194
+
195
+    /**
196
+     * Removes a service instance or descriptor from the available services
197
+     *
198
+     * @param mixed $service
199
+     *
200
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
201
+     */
202
+    public function removeReadService($service)
203
+    {
204
+        $id = '';
205
+
206
+        if ($service instanceof Apache_Solr_Service)
207
+        {
208
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
209
+        }
210
+        else if (is_array($service))
211
+        {
212
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
213
+            {
214
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
215
+            }
216
+            else
217
+            {
218
+                throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
219
+            }
220
+        }
221
+        else if (is_string($service))
222
+        {
223
+            $id = $service;
224
+        }
225
+
226
+        if ($id && isset($this->_readableServices[$id]))
227
+        {
228
+            unset($this->_readableServices[$id]);
229
+        }
230
+    }
231
+
232
+    /**
233
+     * Adds a service instance or service descriptor (if it is already
234
+     * not added)
235
+     *
236
+     * @param mixed $service
237
+     *
238
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
239
+     */
240
+    public function addWriteService($service)
241
+    {
242
+        if ($service instanceof Apache_Solr_Service)
243
+        {
244
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
245
+
246
+            $this->_writeableServices[$id] = $service;
247
+        }
248
+        else if (is_array($service))
249
+        {
250
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
251
+            {
252
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
253
+
254
+                $this->_writeableServices[$id] = $service;
255
+            }
256
+            else
257
+            {
258
+                throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path');
259
+            }
260
+        }
261
+    }
262
+
263
+    /**
264
+     * Removes a service instance or descriptor from the available services
265
+     *
266
+     * @param mixed $service
267
+     *
268
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
269
+     */
270
+    public function removeWriteService($service)
271
+    {
272
+        $id = '';
273
+
274
+        if ($service instanceof Apache_Solr_Service)
275
+        {
276
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
277
+        }
278
+        else if (is_array($service))
279
+        {
280
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
281
+            {
282
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
283
+            }
284
+            else
285
+            {
286
+                throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
287
+            }
288
+        }
289
+        else if (is_string($service))
290
+        {
291
+            $id = $service;
292
+        }
293
+
294
+        if ($id && isset($this->_writeableServices[$id]))
295
+        {
296
+            unset($this->_writeableServices[$id]);
297
+        }
298
+    }
299
+
300
+    /**
301
+     * Iterate through available read services and select the first with a ping
302
+     * that satisfies configured timeout restrictions (or the default)
303
+     *
304
+     * @return Apache_Solr_Service
305
+     *
306
+     * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
307
+     */
308
+    protected function _selectReadService($forceSelect = false)
309
+    {
310
+        if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect)
311
+        {
312
+            if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect)
313
+            {
314
+                // we probably had a communication error, ping the current read service, remove it if it times out
315
+                if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false)
316
+                {
317
+                    $this->removeReadService($this->_currentReadService);
318
+                }
319
+            }
320
+
321
+            if (count($this->_readableServices))
322
+            {
323
+                // select one of the read services at random
324
+                $ids = array_keys($this->_readableServices);
325
+
326
+                $id = $ids[rand(0, count($ids) - 1)];
327
+                $service = $this->_readableServices[$id];
328
+
329
+                if (is_array($service))
330
+                {
331
+                    //convert the array definition to a client object
332
+                    $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
333
+                    $this->_readableServices[$id] = $service;
334
+                }
335
+
336
+                $service->setCreateDocuments($this->_createDocuments);
337
+                $this->_currentReadService = $id;
338
+            }
339
+            else
340
+            {
341
+                throw new Apache_Solr_NoServiceAvailableException('No read services were available');
342
+            }
343
+        }
344
+
345
+        return $this->_readableServices[$this->_currentReadService];
346
+    }
347
+
348
+    /**
349
+     * Iterate through available write services and select the first with a ping
350
+     * that satisfies configured timeout restrictions (or the default)
351
+     *
352
+     * @return Apache_Solr_Service
353
+     *
354
+     * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
355
+     */
356
+    protected function _selectWriteService($forceSelect = false)
357
+    {
358
+        if($this->_useBackoff)
359
+        {
360
+            return $this->_selectWriteServiceSafe($forceSelect);
361
+        }
362
+
363
+        if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
364
+        {
365
+            if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect)
366
+            {
367
+                // we probably had a communication error, ping the current read service, remove it if it times out
368
+                if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false)
369
+                {
370
+                    $this->removeWriteService($this->_currentWriteService);
371
+                }
372
+            }
373
+
374
+            if (count($this->_writeableServices))
375
+            {
376
+                // select one of the read services at random
377
+                $ids = array_keys($this->_writeableServices);
378
+
379
+                $id = $ids[rand(0, count($ids) - 1)];
380
+                $service = $this->_writeableServices[$id];
381
+
382
+                if (is_array($service))
383
+                {
384
+                    //convert the array definition to a client object
385
+                    $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
386
+                    $this->_writeableServices[$id] = $service;
387
+                }
388
+
389
+                $this->_currentWriteService = $id;
390
+            }
391
+            else
392
+            {
393
+                throw new Apache_Solr_NoServiceAvailableException('No write services were available');
394
+            }
395
+        }
396
+
397
+        return $this->_writeableServices[$this->_currentWriteService];
398
+    }
399
+
400
+    /**
401
+     * Iterate through available write services and select the first with a ping
402
+     * that satisfies configured timeout restrictions (or the default).  The
403
+     * timeout period will increase until a connection is made or the limit is
404
+     * reached.   This will allow for increased reliability with heavily loaded
405
+     * server(s).
406
+     *
407
+     * @return Apache_Solr_Service
408
+     *
409
+     * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
410
+     */
411
+
412
+    protected function _selectWriteServiceSafe($forceSelect = false)
413
+    {
414
+        if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
415
+        {
416
+            if (count($this->_writeableServices))
417
+            {
418
+                $backoff = $this->_defaultBackoff;
419
+
420
+                do {
421
+                    // select one of the read services at random
422
+                    $ids = array_keys($this->_writeableServices);
423
+
424
+                    $id = $ids[rand(0, count($ids) - 1)];
425
+                    $service = $this->_writeableServices[$id];
426
+
427
+                    if (is_array($service))
428
+                    {
429
+                        //convert the array definition to a client object
430
+                        $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
431
+                        $this->_writeableServices[$id] = $service;
432
+                    }
433
+
434
+                    $this->_currentWriteService = $id;
435
+
436
+                    $backoff *= $this->_backoffEscalation;
437
+
438
+                    if($backoff > $this->_backoffLimit)
439
+                    {
440
+                        throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441
+                    }
442
+
443
+                } while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
444
+            }
445
+            else
446
+            {
447
+                throw new Apache_Solr_NoServiceAvailableException('No write services were available');
448
+            }
449
+        }
450
+
451
+        return $this->_writeableServices[$this->_currentWriteService];
452
+    }
453
+
454
+    /**
455
+     * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
456
+     * parse the response and create {@link Apache_Solr_Document} instances in place.
457
+     *
458
+     * @param boolean $createDocuments
459
+     */
460
+    public function setCreateDocuments($createDocuments)
461
+    {
462
+        $this->_createDocuments = (bool) $createDocuments;
463
+
464
+        // set on current read service
465
+        if ($this->_currentReadService)
466
+        {
467
+            $service = $this->_selectReadService();
468
+            $service->setCreateDocuments($createDocuments);
469
+        }
470
+    }
471
+
472
+    /**
473
+     * Get the current state of the create documents flag.
474
+     *
475
+     * @return boolean
476
+     */
477
+    public function getCreateDocuments()
478
+    {
479
+        return $this->_createDocuments;
480
+    }
481 481
 	
482
-	/**
483
-	 * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
484
-	 * should be a complete and well formed "add" xml document.
485
-	 *
486
-	 * @param string $rawPost
487
-	 * @return Apache_Solr_Response
488
-	 *
489
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
490
-	 */
491
-	public function add($rawPost)
492
-	{
493
-		$service = $this->_selectWriteService();
494
-
495
-		do
496
-		{
497
-			try
498
-			{
499
-				return $service->add($rawPost);
500
-			}
501
-			catch (Apache_Solr_HttpTransportException $e)
502
-			{
503
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
504
-				{
505
-					throw $e;
506
-				}
507
-			}
508
-
509
-			$service = $this->_selectWriteService(true);
510
-		} while ($service);
511
-
512
-		return false;
513
-	}
514
-
515
-	/**
516
-	 * Add a Solr Document to the index
517
-	 *
518
-	 * @param Apache_Solr_Document $document
519
-	 * @param boolean $allowDups
520
-	 * @param boolean $overwritePending
521
-	 * @param boolean $overwriteCommitted
522
-	 * @return Apache_Solr_Response
523
-	 *
524
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
525
-	 */
526
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
527
-	{
528
-		$service = $this->_selectWriteService();
529
-
530
-		do
531
-		{
532
-			try
533
-			{
534
-				return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted);
535
-			}
536
-			catch (Apache_Solr_HttpTransportException $e)
537
-			{
538
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
539
-				{
540
-					throw $e;
541
-				}
542
-			}
543
-
544
-			$service = $this->_selectWriteService(true);
545
-		} while ($service);
546
-
547
-		return false;
548
-	}
549
-
550
-	/**
551
-	 * Add an array of Solr Documents to the index all at once
552
-	 *
553
-	 * @param array $documents Should be an array of Apache_Solr_Document instances
554
-	 * @param boolean $allowDups
555
-	 * @param boolean $overwritePending
556
-	 * @param boolean $overwriteCommitted
557
-	 * @return Apache_Solr_Response
558
-	 *
559
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
560
-	 */
561
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
562
-	{
563
-		$service = $this->_selectWriteService();
564
-
565
-		do
566
-		{
567
-			try
568
-			{
569
-				return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted);
570
-			}
571
-			catch (Apache_Solr_HttpTransportException $e)
572
-			{
573
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
574
-				{
575
-					throw $e;
576
-				}
577
-			}
578
-
579
-			$service = $this->_selectWriteService(true);
580
-		} while ($service);
581
-
582
-		return false;
583
-	}
584
-
585
-	/**
586
-	 * Send a commit command.  Will be synchronous unless both wait parameters are set
587
-	 * to false.
588
-	 *
589
-	 * @param boolean $waitFlush
590
-	 * @param boolean $waitSearcher
591
-	 * @return Apache_Solr_Response
592
-	 *
593
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
594
-	 */
595
-	public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
596
-	{
597
-		$service = $this->_selectWriteService();
598
-
599
-		do
600
-		{
601
-			try
602
-			{
603
-				return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout);
604
-			}
605
-			catch (Apache_Solr_HttpTransportException $e)
606
-			{
607
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
608
-				{
609
-					throw $e;
610
-				}
611
-			}
612
-
613
-			$service = $this->_selectWriteService(true);
614
-		} while ($service);
615
-
616
-		return false;
617
-	}
618
-
619
-	/**
620
-	 * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
621
-	 * a complete and well formed "delete" xml document
622
-	 *
623
-	 * @param string $rawPost
624
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
625
-	 * @return Apache_Solr_Response
626
-	 *
627
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
628
-	 */
629
-	public function delete($rawPost, $timeout = 3600)
630
-	{
631
-		$service = $this->_selectWriteService();
632
-
633
-		do
634
-		{
635
-			try
636
-			{
637
-				return $service->delete($rawPost, $timeout);
638
-			}
639
-			catch (Apache_Solr_HttpTransportException $e)
640
-			{
641
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
642
-				{
643
-					throw $e;
644
-				}
645
-			}
646
-
647
-			$service = $this->_selectWriteService(true);
648
-		} while ($service);
649
-
650
-		return false;
651
-	}
652
-
653
-	/**
654
-	 * Create a delete document based on document ID
655
-	 *
656
-	 * @param string $id
657
-	 * @param boolean $fromPending
658
-	 * @param boolean $fromCommitted
659
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
660
-	 * @return Apache_Solr_Response
661
-	 *
662
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
663
-	 */
664
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
665
-	{
666
-		$service = $this->_selectWriteService();
667
-
668
-		do
669
-		{
670
-			try
671
-			{
672
-				return $service->deleteById($id, $fromPending, $fromCommitted, $timeout);
673
-			}
674
-			catch (Apache_Solr_HttpTransportException $e)
675
-			{
676
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
677
-				{
678
-					throw $e;
679
-				}
680
-			}
681
-
682
-			$service = $this->_selectWriteService(true);
683
-		} while ($service);
684
-
685
-		return false;
686
-	}
687
-
688
-	/**
689
-	 * Create and post a delete document based on multiple document IDs.
690
-	 *
691
-	 * @param array $ids Expected to be utf-8 encoded strings
692
-	 * @param boolean $fromPending
693
-	 * @param boolean $fromCommitted
694
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
695
-	 * @return Apache_Solr_Response
696
-	 *
697
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
698
-	 */
699
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
700
-	{
701
-		$service = $this->_selectWriteService();
702
-
703
-		do
704
-		{
705
-			try
706
-			{
707
-				return $service->deleteByMultipleId($ids, $fromPending, $fromCommitted, $timeout);
708
-			}
709
-			catch (Apache_Solr_HttpTransportException $e)
710
-			{
711
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
712
-				{
713
-					throw $e;
714
-				}
715
-			}
716
-
717
-			$service = $this->_selectWriteService(true);
718
-		} while ($service);
719
-
720
-		return false;
721
-	}
722
-
723
-	/**
724
-	 * Create a delete document based on a query and submit it
725
-	 *
726
-	 * @param string $rawQuery
727
-	 * @param boolean $fromPending
728
-	 * @param boolean $fromCommitted
729
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
730
-	 * @return Apache_Solr_Response
731
-	 *
732
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
733
-	 */
734
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
735
-	{
736
-		$service = $this->_selectWriteService();
737
-
738
-		do
739
-		{
740
-			try
741
-			{
742
-				return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted, $timeout);
743
-			}
744
-			catch (Apache_Solr_HttpTransportException $e)
745
-			{
746
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
747
-				{
748
-					throw $e;
749
-				}
750
-			}
751
-
752
-			$service = $this->_selectWriteService(true);
753
-		} while ($service);
754
-
755
-		return false;
756
-	}
482
+    /**
483
+     * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
484
+     * should be a complete and well formed "add" xml document.
485
+     *
486
+     * @param string $rawPost
487
+     * @return Apache_Solr_Response
488
+     *
489
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
490
+     */
491
+    public function add($rawPost)
492
+    {
493
+        $service = $this->_selectWriteService();
494
+
495
+        do
496
+        {
497
+            try
498
+            {
499
+                return $service->add($rawPost);
500
+            }
501
+            catch (Apache_Solr_HttpTransportException $e)
502
+            {
503
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
504
+                {
505
+                    throw $e;
506
+                }
507
+            }
508
+
509
+            $service = $this->_selectWriteService(true);
510
+        } while ($service);
511
+
512
+        return false;
513
+    }
514
+
515
+    /**
516
+     * Add a Solr Document to the index
517
+     *
518
+     * @param Apache_Solr_Document $document
519
+     * @param boolean $allowDups
520
+     * @param boolean $overwritePending
521
+     * @param boolean $overwriteCommitted
522
+     * @return Apache_Solr_Response
523
+     *
524
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
525
+     */
526
+    public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
527
+    {
528
+        $service = $this->_selectWriteService();
529
+
530
+        do
531
+        {
532
+            try
533
+            {
534
+                return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted);
535
+            }
536
+            catch (Apache_Solr_HttpTransportException $e)
537
+            {
538
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
539
+                {
540
+                    throw $e;
541
+                }
542
+            }
543
+
544
+            $service = $this->_selectWriteService(true);
545
+        } while ($service);
546
+
547
+        return false;
548
+    }
549
+
550
+    /**
551
+     * Add an array of Solr Documents to the index all at once
552
+     *
553
+     * @param array $documents Should be an array of Apache_Solr_Document instances
554
+     * @param boolean $allowDups
555
+     * @param boolean $overwritePending
556
+     * @param boolean $overwriteCommitted
557
+     * @return Apache_Solr_Response
558
+     *
559
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
560
+     */
561
+    public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
562
+    {
563
+        $service = $this->_selectWriteService();
564
+
565
+        do
566
+        {
567
+            try
568
+            {
569
+                return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted);
570
+            }
571
+            catch (Apache_Solr_HttpTransportException $e)
572
+            {
573
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
574
+                {
575
+                    throw $e;
576
+                }
577
+            }
578
+
579
+            $service = $this->_selectWriteService(true);
580
+        } while ($service);
581
+
582
+        return false;
583
+    }
584
+
585
+    /**
586
+     * Send a commit command.  Will be synchronous unless both wait parameters are set
587
+     * to false.
588
+     *
589
+     * @param boolean $waitFlush
590
+     * @param boolean $waitSearcher
591
+     * @return Apache_Solr_Response
592
+     *
593
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
594
+     */
595
+    public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
596
+    {
597
+        $service = $this->_selectWriteService();
598
+
599
+        do
600
+        {
601
+            try
602
+            {
603
+                return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout);
604
+            }
605
+            catch (Apache_Solr_HttpTransportException $e)
606
+            {
607
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
608
+                {
609
+                    throw $e;
610
+                }
611
+            }
612
+
613
+            $service = $this->_selectWriteService(true);
614
+        } while ($service);
615
+
616
+        return false;
617
+    }
618
+
619
+    /**
620
+     * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
621
+     * a complete and well formed "delete" xml document
622
+     *
623
+     * @param string $rawPost
624
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
625
+     * @return Apache_Solr_Response
626
+     *
627
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
628
+     */
629
+    public function delete($rawPost, $timeout = 3600)
630
+    {
631
+        $service = $this->_selectWriteService();
632
+
633
+        do
634
+        {
635
+            try
636
+            {
637
+                return $service->delete($rawPost, $timeout);
638
+            }
639
+            catch (Apache_Solr_HttpTransportException $e)
640
+            {
641
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
642
+                {
643
+                    throw $e;
644
+                }
645
+            }
646
+
647
+            $service = $this->_selectWriteService(true);
648
+        } while ($service);
649
+
650
+        return false;
651
+    }
652
+
653
+    /**
654
+     * Create a delete document based on document ID
655
+     *
656
+     * @param string $id
657
+     * @param boolean $fromPending
658
+     * @param boolean $fromCommitted
659
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
660
+     * @return Apache_Solr_Response
661
+     *
662
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
663
+     */
664
+    public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
665
+    {
666
+        $service = $this->_selectWriteService();
667
+
668
+        do
669
+        {
670
+            try
671
+            {
672
+                return $service->deleteById($id, $fromPending, $fromCommitted, $timeout);
673
+            }
674
+            catch (Apache_Solr_HttpTransportException $e)
675
+            {
676
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
677
+                {
678
+                    throw $e;
679
+                }
680
+            }
681
+
682
+            $service = $this->_selectWriteService(true);
683
+        } while ($service);
684
+
685
+        return false;
686
+    }
687
+
688
+    /**
689
+     * Create and post a delete document based on multiple document IDs.
690
+     *
691
+     * @param array $ids Expected to be utf-8 encoded strings
692
+     * @param boolean $fromPending
693
+     * @param boolean $fromCommitted
694
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
695
+     * @return Apache_Solr_Response
696
+     *
697
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
698
+     */
699
+    public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
700
+    {
701
+        $service = $this->_selectWriteService();
702
+
703
+        do
704
+        {
705
+            try
706
+            {
707
+                return $service->deleteByMultipleId($ids, $fromPending, $fromCommitted, $timeout);
708
+            }
709
+            catch (Apache_Solr_HttpTransportException $e)
710
+            {
711
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
712
+                {
713
+                    throw $e;
714
+                }
715
+            }
716
+
717
+            $service = $this->_selectWriteService(true);
718
+        } while ($service);
719
+
720
+        return false;
721
+    }
722
+
723
+    /**
724
+     * Create a delete document based on a query and submit it
725
+     *
726
+     * @param string $rawQuery
727
+     * @param boolean $fromPending
728
+     * @param boolean $fromCommitted
729
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
730
+     * @return Apache_Solr_Response
731
+     *
732
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
733
+     */
734
+    public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
735
+    {
736
+        $service = $this->_selectWriteService();
737
+
738
+        do
739
+        {
740
+            try
741
+            {
742
+                return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted, $timeout);
743
+            }
744
+            catch (Apache_Solr_HttpTransportException $e)
745
+            {
746
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
747
+                {
748
+                    throw $e;
749
+                }
750
+            }
751
+
752
+            $service = $this->_selectWriteService(true);
753
+        } while ($service);
754
+
755
+        return false;
756
+    }
757 757
 	
758
-	/**
759
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
760
-	 * to use Solr Cell and what parameters are available.
761
-	 *
762
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
763
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
764
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
765
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
766
-	 *
767
-	 * @param string $file Path to file to extract data from
768
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
769
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
770
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
771
-	 *
772
-	 * @return Apache_Solr_Response
773
-	 *
774
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775
-	 */
776
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
777
-	{
778
-		$service = $this->_selectWriteService();
779
-
780
-		do
781
-		{
782
-			try
783
-			{
784
-				return $service->extract($file, $params, $document, $mimetype);
785
-			}
786
-			catch (Apache_Solr_HttpTransportException $e)
787
-			{
788
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
789
-				{
790
-					throw $e;
791
-				}
792
-			}
793
-
794
-			$service = $this->_selectWriteService(true);
795
-		} while ($service);
796
-
797
-		return false;
798
-	}
758
+    /**
759
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
760
+     * to use Solr Cell and what parameters are available.
761
+     *
762
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
763
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
764
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
765
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
766
+     *
767
+     * @param string $file Path to file to extract data from
768
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
769
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
770
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
771
+     *
772
+     * @return Apache_Solr_Response
773
+     *
774
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775
+     */
776
+    public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
777
+    {
778
+        $service = $this->_selectWriteService();
779
+
780
+        do
781
+        {
782
+            try
783
+            {
784
+                return $service->extract($file, $params, $document, $mimetype);
785
+            }
786
+            catch (Apache_Solr_HttpTransportException $e)
787
+            {
788
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
789
+                {
790
+                    throw $e;
791
+                }
792
+            }
793
+
794
+            $service = $this->_selectWriteService(true);
795
+        } while ($service);
796
+
797
+        return false;
798
+    }
799 799
 	
800
-	/**
801
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
802
-	 * to use Solr Cell and what parameters are available.
803
-	 *
804
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
805
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
806
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
807
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
808
-	 *
809
-	 * @param string $data Data that will be passed to Solr Cell
810
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
811
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
812
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
813
-	 *
814
-	 * @return Apache_Solr_Response
815
-	 *
816
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
817
-	 *
818
-	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819
-	 */
820
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
821
-	{
822
-		$service = $this->_selectWriteService();
823
-
824
-		do
825
-		{
826
-			try
827
-			{
828
-				return $service->extractFromString($data, $params, $document, $mimetype);
829
-			}
830
-			catch (Apache_Solr_HttpTransportException $e)
831
-			{
832
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
833
-				{
834
-					throw $e;
835
-				}
836
-			}
837
-
838
-			$service = $this->_selectWriteService(true);
839
-		} while ($service);
840
-
841
-		return false;
842
-	}
800
+    /**
801
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
802
+     * to use Solr Cell and what parameters are available.
803
+     *
804
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
805
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
806
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
807
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
808
+     *
809
+     * @param string $data Data that will be passed to Solr Cell
810
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
811
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
812
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
813
+     *
814
+     * @return Apache_Solr_Response
815
+     *
816
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
817
+     *
818
+     * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819
+     */
820
+    public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
821
+    {
822
+        $service = $this->_selectWriteService();
823
+
824
+        do
825
+        {
826
+            try
827
+            {
828
+                return $service->extractFromString($data, $params, $document, $mimetype);
829
+            }
830
+            catch (Apache_Solr_HttpTransportException $e)
831
+            {
832
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
833
+                {
834
+                    throw $e;
835
+                }
836
+            }
837
+
838
+            $service = $this->_selectWriteService(true);
839
+        } while ($service);
840
+
841
+        return false;
842
+    }
843 843
 	
844
-	/**
845
-	 * Send an optimize command.  Will be synchronous unless both wait parameters are set
846
-	 * to false.
847
-	 *
848
-	 * @param boolean $waitFlush
849
-	 * @param boolean $waitSearcher
850
-	 * @param float $timeout Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
851
-	 * @return Apache_Solr_Response
852
-	 *
853
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
854
-	 */
855
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
856
-	{
857
-		$service = $this->_selectWriteService();
858
-
859
-		do
860
-		{
861
-			try
862
-			{
863
-				return $service->optimize($waitFlush, $waitSearcher, $timeout);
864
-			}
865
-			catch (Apache_Solr_HttpTransportException $e)
866
-			{
867
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
868
-				{
869
-					throw $e;
870
-				}
871
-			}
872
-
873
-			$service = $this->_selectWriteService(true);
874
-		} while ($service);
875
-
876
-		return false;
877
-	}
878
-
879
-	/**
880
-	 * Simple Search interface
881
-	 *
882
-	 * @param string $query The raw query string
883
-	 * @param int $offset The starting offset for result documents
884
-	 * @param int $limit The maximum number of result documents to return
885
-	 * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters
886
-	 * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
887
-	 * @return Apache_Solr_Response
888
-	 *
889
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
890
-	 */
891
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET)
892
-	{
893
-		$service = $this->_selectReadService();
894
-
895
-		do
896
-		{
897
-			try
898
-			{
899
-				return $service->search($query, $offset, $limit, $params, $method);
900
-			}
901
-			catch (Apache_Solr_HttpTransportException $e)
902
-			{
903
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
904
-				{
905
-					throw $e;
906
-				}
907
-			}
908
-
909
-			$service = $this->_selectReadService(true);
910
-		} while ($service);
911
-
912
-		return false;
913
-	}
844
+    /**
845
+     * Send an optimize command.  Will be synchronous unless both wait parameters are set
846
+     * to false.
847
+     *
848
+     * @param boolean $waitFlush
849
+     * @param boolean $waitSearcher
850
+     * @param float $timeout Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
851
+     * @return Apache_Solr_Response
852
+     *
853
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
854
+     */
855
+    public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
856
+    {
857
+        $service = $this->_selectWriteService();
858
+
859
+        do
860
+        {
861
+            try
862
+            {
863
+                return $service->optimize($waitFlush, $waitSearcher, $timeout);
864
+            }
865
+            catch (Apache_Solr_HttpTransportException $e)
866
+            {
867
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
868
+                {
869
+                    throw $e;
870
+                }
871
+            }
872
+
873
+            $service = $this->_selectWriteService(true);
874
+        } while ($service);
875
+
876
+        return false;
877
+    }
878
+
879
+    /**
880
+     * Simple Search interface
881
+     *
882
+     * @param string $query The raw query string
883
+     * @param int $offset The starting offset for result documents
884
+     * @param int $limit The maximum number of result documents to return
885
+     * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters
886
+     * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
887
+     * @return Apache_Solr_Response
888
+     *
889
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
890
+     */
891
+    public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET)
892
+    {
893
+        $service = $this->_selectReadService();
894
+
895
+        do
896
+        {
897
+            try
898
+            {
899
+                return $service->search($query, $offset, $limit, $params, $method);
900
+            }
901
+            catch (Apache_Solr_HttpTransportException $e)
902
+            {
903
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
904
+                {
905
+                    throw $e;
906
+                }
907
+            }
908
+
909
+            $service = $this->_selectReadService(true);
910
+        } while ($service);
911
+
912
+        return false;
913
+    }
914 914
 }
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Response.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -47,201 +47,201 @@
 block discarded – undo
47 47
  */
48 48
 class Apache_Solr_Response
49 49
 {
50
-	/**
51
-	 * SVN Revision meta data for this class
52
-	 */
53
-	const SVN_REVISION = '$Revision: 54 $';
54
-
55
-	/**
56
-	 * SVN ID meta data for this class
57
-	 */
58
-	const SVN_ID = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
59
-
60
-	/**
61
-	 * Holds the raw response used in construction
62
-	 *
63
-	 * @var Apache_Solr_HttpTransport_Response HTTP response
64
-	 */
65
-	protected $_response;
66
-
67
-	/**
68
-	 * Whether the raw response has been parsed
69
-	 *
70
-	 * @var boolean
71
-	 */
72
-	protected $_isParsed = false;
73
-
74
-	/**
75
-	 * Parsed representation of the data
76
-	 *
77
-	 * @var mixed
78
-	 */
79
-	protected $_parsedData;
80
-
81
-	/**
82
-	 * Data parsing flags.  Determines what extra processing should be done
83
-	 * after the data is initially converted to a data structure.
84
-	 *
85
-	 * @var boolean
86
-	 */
87
-	protected $_createDocuments = true,
88
-			$_collapseSingleValueArrays = true;
89
-
90
-	/**
91
-	 * Constructor. Takes the raw HTTP response body and the exploded HTTP headers
92
-	 *
93
-	 * @return Apache_Solr_HttpTransport_Response HTTP response
94
-	 * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
95
-	 * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
96
-	 */
97
-	public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true)
98
-	{
99
-		$this->_response = $response;
100
-		$this->_createDocuments = (bool) $createDocuments;
101
-		$this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
102
-	}
103
-
104
-	/**
105
-	 * Get the HTTP status code
106
-	 *
107
-	 * @return integer
108
-	 */
109
-	public function getHttpStatus()
110
-	{
111
-		return $this->_response->getStatusCode();
112
-	}
113
-
114
-	/**
115
-	 * Get the HTTP status message of the response
116
-	 *
117
-	 * @return string
118
-	 */
119
-	public function getHttpStatusMessage()
120
-	{
121
-		return $this->_response->getStatusMessage();
122
-	}
123
-
124
-	/**
125
-	 * Get content type of this Solr response
126
-	 *
127
-	 * @return string
128
-	 */
129
-	public function getType()
130
-	{
131
-		return $this->_response->getMimeType();
132
-	}
133
-
134
-	/**
135
-	 * Get character encoding of this response. Should usually be utf-8, but just in case
136
-	 *
137
-	 * @return string
138
-	 */
139
-	public function getEncoding()
140
-	{
141
-		return $this->_response->getEncoding();
142
-	}
143
-
144
-	/**
145
-	 * Get the raw response as it was given to this object
146
-	 *
147
-	 * @return string
148
-	 */
149
-	public function getRawResponse()
150
-	{
151
-		return $this->_response->getBody();
152
-	}
153
-
154
-	/**
155
-	 * Magic get to expose the parsed data and to lazily load it
156
-	 *
157
-	 * @param string $key
158
-	 * @return mixed
159
-	 */
160
-	public function __get($key)
161
-	{
162
-		if (!$this->_isParsed)
163
-		{
164
-			$this->_parseData();
165
-			$this->_isParsed = true;
166
-		}
167
-
168
-		if (isset($this->_parsedData->$key))
169
-		{
170
-			return $this->_parsedData->$key;
171
-		}
172
-
173
-		return null;
174
-	}
175
-
176
-	/**
177
-	 * Magic function for isset function on parsed data
178
-	 *
179
-	 * @param string $key
180
-	 * @return boolean
181
-	 */
182
-	public function __isset($key)
183
-	{
184
-		if (!$this->_isParsed)
185
-		{
186
-			$this->_parseData();
187
-			$this->_isParsed = true;
188
-		}
189
-
190
-		return isset($this->_parsedData->$key);
191
-	}
192
-
193
-	/**
194
-	 * Parse the raw response into the parsed_data array for access
195
-	 *
196
-	 * @throws Apache_Solr_ParserException If the data could not be parsed
197
-	 */
198
-	protected function _parseData()
199
-	{
200
-		//An alternative would be to use Zend_Json::decode(...)
201
-		$data = json_decode($this->_response->getBody());
202
-
203
-		// check that we receive a valid JSON response - we should never receive a null
204
-		if ($data === null)
205
-		{
206
-			throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
207
-		}
208
-
209
-		//if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects
210
-		//and we have response documents, then try to collapse the values and / or convert them now
211
-		if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs))
212
-		{
213
-			$documents = array();
214
-
215
-			foreach ($data->response->docs as $originalDocument)
216
-			{
217
-				if ($this->_createDocuments)
218
-				{
219
-					$document = new Apache_Solr_Document();
220
-				}
221
-				else
222
-				{
223
-					$document = $originalDocument;
224
-				}
225
-
226
-				foreach ($originalDocument as $key => $value)
227
-				{
228
-					//If a result is an array with only a single
229
-					//value then its nice to be able to access
230
-					//it as if it were always a single value
231
-					if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1)
232
-					{
233
-						$value = array_shift($value);
234
-					}
235
-
236
-					$document->$key = $value;
237
-				}
238
-
239
-				$documents[] = $document;
240
-			}
241
-
242
-			$data->response->docs = $documents;
243
-		}
244
-
245
-		$this->_parsedData = $data;
246
-	}
50
+    /**
51
+     * SVN Revision meta data for this class
52
+     */
53
+    const SVN_REVISION = '$Revision: 54 $';
54
+
55
+    /**
56
+     * SVN ID meta data for this class
57
+     */
58
+    const SVN_ID = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
59
+
60
+    /**
61
+     * Holds the raw response used in construction
62
+     *
63
+     * @var Apache_Solr_HttpTransport_Response HTTP response
64
+     */
65
+    protected $_response;
66
+
67
+    /**
68
+     * Whether the raw response has been parsed
69
+     *
70
+     * @var boolean
71
+     */
72
+    protected $_isParsed = false;
73
+
74
+    /**
75
+     * Parsed representation of the data
76
+     *
77
+     * @var mixed
78
+     */
79
+    protected $_parsedData;
80
+
81
+    /**
82
+     * Data parsing flags.  Determines what extra processing should be done
83
+     * after the data is initially converted to a data structure.
84
+     *
85
+     * @var boolean
86
+     */
87
+    protected $_createDocuments = true,
88
+            $_collapseSingleValueArrays = true;
89
+
90
+    /**
91
+     * Constructor. Takes the raw HTTP response body and the exploded HTTP headers
92
+     *
93
+     * @return Apache_Solr_HttpTransport_Response HTTP response
94
+     * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
95
+     * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
96
+     */
97
+    public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true)
98
+    {
99
+        $this->_response = $response;
100
+        $this->_createDocuments = (bool) $createDocuments;
101
+        $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
102
+    }
103
+
104
+    /**
105
+     * Get the HTTP status code
106
+     *
107
+     * @return integer
108
+     */
109
+    public function getHttpStatus()
110
+    {
111
+        return $this->_response->getStatusCode();
112
+    }
113
+
114
+    /**
115
+     * Get the HTTP status message of the response
116
+     *
117
+     * @return string
118
+     */
119
+    public function getHttpStatusMessage()
120
+    {
121
+        return $this->_response->getStatusMessage();
122
+    }
123
+
124
+    /**
125
+     * Get content type of this Solr response
126
+     *
127
+     * @return string
128
+     */
129
+    public function getType()
130
+    {
131
+        return $this->_response->getMimeType();
132
+    }
133
+
134
+    /**
135
+     * Get character encoding of this response. Should usually be utf-8, but just in case
136
+     *
137
+     * @return string
138
+     */
139
+    public function getEncoding()
140
+    {
141
+        return $this->_response->getEncoding();
142
+    }
143
+
144
+    /**
145
+     * Get the raw response as it was given to this object
146
+     *
147
+     * @return string
148
+     */
149
+    public function getRawResponse()
150
+    {
151
+        return $this->_response->getBody();
152
+    }
153
+
154
+    /**
155
+     * Magic get to expose the parsed data and to lazily load it
156
+     *
157
+     * @param string $key
158
+     * @return mixed
159
+     */
160
+    public function __get($key)
161
+    {
162
+        if (!$this->_isParsed)
163
+        {
164
+            $this->_parseData();
165
+            $this->_isParsed = true;
166
+        }
167
+
168
+        if (isset($this->_parsedData->$key))
169
+        {
170
+            return $this->_parsedData->$key;
171
+        }
172
+
173
+        return null;
174
+    }
175
+
176
+    /**
177
+     * Magic function for isset function on parsed data
178
+     *
179
+     * @param string $key
180
+     * @return boolean
181
+     */
182
+    public function __isset($key)
183
+    {
184
+        if (!$this->_isParsed)
185
+        {
186
+            $this->_parseData();
187
+            $this->_isParsed = true;
188
+        }
189
+
190
+        return isset($this->_parsedData->$key);
191
+    }
192
+
193
+    /**
194
+     * Parse the raw response into the parsed_data array for access
195
+     *
196
+     * @throws Apache_Solr_ParserException If the data could not be parsed
197
+     */
198
+    protected function _parseData()
199
+    {
200
+        //An alternative would be to use Zend_Json::decode(...)
201
+        $data = json_decode($this->_response->getBody());
202
+
203
+        // check that we receive a valid JSON response - we should never receive a null
204
+        if ($data === null)
205
+        {
206
+            throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
207
+        }
208
+
209
+        //if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects
210
+        //and we have response documents, then try to collapse the values and / or convert them now
211
+        if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs))
212
+        {
213
+            $documents = array();
214
+
215
+            foreach ($data->response->docs as $originalDocument)
216
+            {
217
+                if ($this->_createDocuments)
218
+                {
219
+                    $document = new Apache_Solr_Document();
220
+                }
221
+                else
222
+                {
223
+                    $document = $originalDocument;
224
+                }
225
+
226
+                foreach ($originalDocument as $key => $value)
227
+                {
228
+                    //If a result is an array with only a single
229
+                    //value then its nice to be able to access
230
+                    //it as if it were always a single value
231
+                    if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1)
232
+                    {
233
+                        $value = array_shift($value);
234
+                    }
235
+
236
+                    $document->$key = $value;
237
+                }
238
+
239
+                $documents[] = $document;
240
+            }
241
+
242
+            $data->response->docs = $documents;
243
+        }
244
+
245
+        $this->_parsedData = $data;
246
+    }
247 247
 }
248 248
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/ParserException.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_ParserException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Service.php 1 patch
Indentation   +1083 added lines, -1083 removed lines patch added patch discarded remove patch
@@ -85,1097 +85,1097 @@
 block discarded – undo
85 85
  */
86 86
 class Apache_Solr_Service
87 87
 {
88
-	/**
89
-	 * SVN Revision meta data for this class
90
-	 */
91
-	const SVN_REVISION = '$Revision: 59 $';
92
-
93
-	/**
94
-	 * SVN ID meta data for this class
95
-	 */
96
-	const SVN_ID = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $';
97
-
98
-	/**
99
-	 * Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
100
-	 */
101
-	const SOLR_WRITER = 'json';
102
-
103
-	/**
104
-	 * NamedList Treatment constants
105
-	 */
106
-	const NAMED_LIST_FLAT = 'flat';
107
-	const NAMED_LIST_MAP = 'map';
108
-
109
-	/**
110
-	 * Search HTTP Methods
111
-	 */
112
-	const METHOD_GET = 'GET';
113
-	const METHOD_POST = 'POST';
114
-
115
-	/**
116
-	 * Servlet mappings
117
-	 */
118
-	const PING_SERVLET = 'admin/ping';
119
-	const UPDATE_SERVLET = 'update';
120
-	const SEARCH_SERVLET = 'select';
121
-	const THREADS_SERVLET = 'admin/threads';
122
-	const EXTRACT_SERVLET = 'update/extract';
123
-
124
-	/**
125
-	 * Server identification strings
126
-	 *
127
-	 * @var string
128
-	 */
129
-	protected $_host, $_port, $_path;
130
-
131
-	/**
132
-	 * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in
133
-	 * the returned parsed data
134
-	 *
135
-	 * @var boolean
136
-	 */
137
-	protected $_createDocuments = true;
138
-
139
-	/**
140
-	 * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
141
-	 * collapsed to appear as a single value would.
142
-	 *
143
-	 * @var boolean
144
-	 */
145
-	protected $_collapseSingleValueArrays = true;
146
-
147
-	/**
148
-	 * How NamedLists should be formatted in the output.  This specifically effects facet counts. Valid values
149
-	 * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}.
150
-	 *
151
-	 * @var string
152
-	 */
153
-	protected $_namedListTreatment = self::NAMED_LIST_MAP;
154
-
155
-	/**
156
-	 * Query delimiters. Someone might want to be able to change
157
-	 * these (to use &amp; instead of & for example), so I've provided them.
158
-	 *
159
-	 * @var string
160
-	 */
161
-	protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = true;
162
-
163
-	/**
164
-	 * Constructed servlet full path URLs
165
-	 *
166
-	 * @var string
167
-	 */
168
-	protected $_pingUrl, $_updateUrl, $_searchUrl, $_threadsUrl;
169
-
170
-	/**
171
-	 * Keep track of whether our URLs have been constructed
172
-	 *
173
-	 * @var boolean
174
-	 */
175
-	protected $_urlsInited = false;
176
-
177
-	/**
178
-	 * HTTP Transport implementation (pluggable)
179
-	 *
180
-	 * @var Apache_Solr_HttpTransport_Interface
181
-	 */
182
-	protected $_httpTransport = false;
183
-
184
-	/**
185
-	 * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
186
-	 *
187
-	 * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
188
-	 *
189
-	 * @param string $value
190
-	 * @return string
191
-	 */
192
-	static public function escape($value)
193
-	{
194
-		//list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
195
-		$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
196
-		$replace = '\\\$1';
197
-
198
-		return preg_replace($pattern, $replace, $value);
199
-	}
200
-
201
-	/**
202
-	 * Escape a value meant to be contained in a phrase for special query characters
203
-	 *
204
-	 * @param string $value
205
-	 * @return string
206
-	 */
207
-	static public function escapePhrase($value)
208
-	{
209
-		$pattern = '/("|\\\)/';
210
-		$replace = '\\\$1';
211
-
212
-		return preg_replace($pattern, $replace, $value);
213
-	}
214
-
215
-	/**
216
-	 * Convenience function for creating phrase syntax from a value
217
-	 *
218
-	 * @param string $value
219
-	 * @return string
220
-	 */
221
-	static public function phrase($value)
222
-	{
223
-		return '"' . self::escapePhrase($value) . '"';
224
-	}
225
-
226
-	/**
227
-	 * Constructor. All parameters are optional and will take on default values
228
-	 * if not specified.
229
-	 *
230
-	 * @param string $host
231
-	 * @param string $port
232
-	 * @param string $path
233
-	 * @param Apache_Solr_HttpTransport_Interface $httpTransport
234
-	 */
235
-	public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false)
236
-	{
237
-		$this->setHost($host);
238
-		$this->setPort($port);
239
-		$this->setPath($path);
240
-
241
-		$this->_initUrls();
242
-
243
-		if ($httpTransport)
244
-		{
245
-			$this->setHttpTransport($httpTransport);
246
-		}
247
-
248
-		// check that our php version is >= 5.1.3 so we can correct for http_build_query behavior later
249
-		$this->_queryBracketsEscaped = version_compare(phpversion(), '5.1.3', '>=');
250
-	}
251
-
252
-	/**
253
-	 * Return a valid http URL given this server's host, port and path and a provided servlet name
254
-	 *
255
-	 * @param string $servlet
256
-	 * @return string
257
-	 */
258
-	protected function _constructUrl($servlet, $params = array())
259
-	{
260
-		if (count($params))
261
-		{
262
-			//escape all parameters appropriately for inclusion in the query string
263
-			$escapedParams = array();
264
-
265
-			foreach ($params as $key => $value)
266
-			{
267
-				$escapedParams[] = urlencode($key) . '=' . urlencode($value);
268
-			}
269
-
270
-			$queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
271
-		}
272
-		else
273
-		{
274
-			$queryString = '';
275
-		}
276
-
277
-		return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString;
278
-	}
279
-
280
-	/**
281
-	 * Construct the Full URLs for the three servlets we reference
282
-	 */
283
-	protected function _initUrls()
284
-	{
285
-		//Initialize our full servlet URLs now that we have server information
286
-		$this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET);
287
-		$this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
288
-		$this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
289
-		$this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
290
-		$this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
291
-
292
-		$this->_urlsInited = true;
293
-	}
294
-
295
-	protected function _generateQueryString($params)
296
-	{
297
-		// use http_build_query to encode our arguments because its faster
298
-		// than urlencoding all the parts ourselves in a loop
299
-		//
300
-		// because http_build_query treats arrays differently than we want to, correct the query
301
-		// string by changing foo[#]=bar (# being an actual number) parameter strings to just
302
-		// multiple foo=bar strings. This regex should always work since '=' will be urlencoded
303
-		// anywhere else the regex isn't expecting it
304
-		//
305
-		// NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked
306
-		// the php version in the constructor and put the results in the instance variable. Also, before
307
-		// 5.1.2 the arg_separator parameter was not available, so don't use it
308
-		if ($this->_queryBracketsEscaped)
309
-		{
310
-			$queryString = http_build_query($params, null, $this->_queryStringDelimiter);
311
-			return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
312
-		}
313
-		else
314
-		{
315
-			$queryString = http_build_query($params);
316
-			return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $queryString);
317
-		}
318
-	}
319
-
320
-	/**
321
-	 * Central method for making a get operation against this Solr Server
322
-	 *
323
-	 * @param string $url
324
-	 * @param float $timeout Read timeout in seconds
325
-	 * @return Apache_Solr_Response
326
-	 *
327
-	 * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
328
-	 */
329
-	protected function _sendRawGet($url, $timeout = FALSE)
330
-	{
331
-		$httpTransport = $this->getHttpTransport();
332
-
333
-		$httpResponse = $httpTransport->performGetRequest($url, $timeout);
334
-		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
335
-
336
-		if ($solrResponse->getHttpStatus() != 200)
337
-		{
338
-			throw new Apache_Solr_HttpTransportException($solrResponse);
339
-		}
340
-
341
-		return $solrResponse;
342
-	}
343
-
344
-	/**
345
-	 * Central method for making a post operation against this Solr Server
346
-	 *
347
-	 * @param string $url
348
-	 * @param string $rawPost
349
-	 * @param float $timeout Read timeout in seconds
350
-	 * @param string $contentType
351
-	 * @return Apache_Solr_Response
352
-	 *
353
-	 * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
354
-	 */
355
-	protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
356
-	{
357
-		$httpTransport = $this->getHttpTransport();
358
-
359
-		$httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
360
-		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
361
-
362
-		if ($solrResponse->getHttpStatus() != 200)
363
-		{
364
-			throw new Apache_Solr_HttpTransportException($solrResponse);
365
-		}
366
-
367
-		return $solrResponse;
368
-	}
369
-
370
-	/**
371
-	 * Returns the set host
372
-	 *
373
-	 * @return string
374
-	 */
375
-	public function getHost()
376
-	{
377
-		return $this->_host;
378
-	}
379
-
380
-	/**
381
-	 * Set the host used. If empty will fallback to constants
382
-	 *
383
-	 * @param string $host
384
-	 *
385
-	 * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
386
-	 */
387
-	public function setHost($host)
388
-	{
389
-		//Use the provided host or use the default
390
-		if (empty($host))
391
-		{
392
-			throw new Apache_Solr_InvalidArgumentException('Host parameter is empty');
393
-		}
394
-		else
395
-		{
396
-			$this->_host = $host;
397
-		}
398
-
399
-		if ($this->_urlsInited)
400
-		{
401
-			$this->_initUrls();
402
-		}
403
-	}
404
-
405
-	/**
406
-	 * Get the set port
407
-	 *
408
-	 * @return integer
409
-	 */
410
-	public function getPort()
411
-	{
412
-		return $this->_port;
413
-	}
414
-
415
-	/**
416
-	 * Set the port used. If empty will fallback to constants
417
-	 *
418
-	 * @param integer $port
419
-	 *
420
-	 * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
421
-	 */
422
-	public function setPort($port)
423
-	{
424
-		//Use the provided port or use the default
425
-		$port = (int) $port;
426
-
427
-		if ($port <= 0)
428
-		{
429
-			throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number');
430
-		}
431
-		else
432
-		{
433
-			$this->_port = $port;
434
-		}
435
-
436
-		if ($this->_urlsInited)
437
-		{
438
-			$this->_initUrls();
439
-		}
440
-	}
441
-
442
-	/**
443
-	 * Get the set path.
444
-	 *
445
-	 * @return string
446
-	 */
447
-	public function getPath()
448
-	{
449
-		return $this->_path;
450
-	}
451
-
452
-	/**
453
-	 * Set the path used. If empty will fallback to constants
454
-	 *
455
-	 * @param string $path
456
-	 */
457
-	public function setPath($path)
458
-	{
459
-		$path = trim($path, '/');
460
-
461
-		$this->_path = '/' . $path . '/';
462
-
463
-		if ($this->_urlsInited)
464
-		{
465
-			$this->_initUrls();
466
-		}
467
-	}
468
-
469
-	/**
470
-	 * Get the current configured HTTP Transport
471
-	 *
472
-	 * @return HttpTransportInterface
473
-	 */
474
-	public function getHttpTransport()
475
-	{
476
-		// lazy load a default if one has not be set
477
-		if ($this->_httpTransport === false)
478
-		{
479
-			require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
480
-
481
-			$this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
482
-		}
483
-
484
-		return $this->_httpTransport;
485
-	}
486
-
487
-	/**
488
-	 * Set the HTTP Transport implemenation that will be used for all HTTP requests
489
-	 *
490
-	 * @param Apache_Solr_HttpTransport_Interface
491
-	 */
492
-	public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport)
493
-	{
494
-		$this->_httpTransport = $httpTransport;
495
-	}
496
-
497
-	/**
498
-	 * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
499
-	 * parse the response and create {@link Apache_Solr_Document} instances in place.
500
-	 *
501
-	 * @param boolean $createDocuments
502
-	 */
503
-	public function setCreateDocuments($createDocuments)
504
-	{
505
-		$this->_createDocuments = (bool) $createDocuments;
506
-	}
507
-
508
-	/**
509
-	 * Get the current state of the create documents flag.
510
-	 *
511
-	 * @return boolean
512
-	 */
513
-	public function getCreateDocuments()
514
-	{
515
-		return $this->_createDocuments;
516
-	}
517
-
518
-	/**
519
-	 * Set the collapse single value arrays flag.
520
-	 *
521
-	 * @param boolean $collapseSingleValueArrays
522
-	 */
523
-	public function setCollapseSingleValueArrays($collapseSingleValueArrays)
524
-	{
525
-		$this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
526
-	}
527
-
528
-	/**
529
-	 * Get the current state of the collapse single value arrays flag.
530
-	 *
531
-	 * @return boolean
532
-	 */
533
-	public function getCollapseSingleValueArrays()
534
-	{
535
-		return $this->_collapseSingleValueArrays;
536
-	}
537
-
538
-	/**
539
-	 * Get the current default timeout setting (initially the default_socket_timeout ini setting)
540
-	 * in seconds
541
-	 *
542
-	 * @return float
543
-	 *
544
-	 * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation
545
-	 */
546
-	public function getDefaultTimeout()
547
-	{
548
-		return $this->getHttpTransport()->getDefaultTimeout();
549
-	}
550
-
551
-	/**
552
-	 * Set the default timeout for all calls that aren't passed a specific timeout
553
-	 *
554
-	 * @param float $timeout Timeout value in seconds
555
-	 *
556
-	 * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation
557
-	 */
558
-	public function setDefaultTimeout($timeout)
559
-	{
560
-		$this->getHttpTransport()->setDefaultTimeout($timeout);
561
-	}
562
-
563
-	/**
564
-	 * Set how NamedLists should be formatted in the response data. This mainly effects
565
-	 * the facet counts format.
566
-	 *
567
-	 * @param string $namedListTreatment
568
-	 * @throws Apache_Solr_InvalidArgumentException If invalid option is set
569
-	 */
570
-	public function setNamedListTreatment($namedListTreatment)
571
-	{
572
-		switch ((string) $namedListTreatment)
573
-		{
574
-			case Apache_Solr_Service::NAMED_LIST_FLAT:
575
-				$this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
576
-				break;
577
-
578
-			case Apache_Solr_Service::NAMED_LIST_MAP:
579
-				$this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP;
580
-				break;
581
-
582
-			default:
583
-				throw new Apache_Solr_InvalidArgumentException('Not a valid named list treatement option');
584
-		}
585
-	}
586
-
587
-	/**
588
-	 * Get the current setting for named list treatment.
589
-	 *
590
-	 * @return string
591
-	 */
592
-	public function getNamedListTreatment()
593
-	{
594
-		return $this->_namedListTreatment;
595
-	}
596
-
597
-	/**
598
-	 * Set the string used to separate the path form the query string.
599
-	 * Defaulted to '?'
600
-	 *
601
-	 * @param string $queryDelimiter
602
-	 */
603
-	public function setQueryDelimiter($queryDelimiter)
604
-	{
605
-		$this->_queryDelimiter = $queryDelimiter;
606
-	}
607
-
608
-	/**
609
-	 * Set the string used to separate the parameters in thequery string
610
-	 * Defaulted to '&'
611
-	 *
612
-	 * @param string $queryStringDelimiter
613
-	 */
614
-	public function setQueryStringDelimiter($queryStringDelimiter)
615
-	{
616
-		$this->_queryStringDelimiter = $queryStringDelimiter;
617
-	}
618
-
619
-	/**
620
-	 * Call the /admin/ping servlet, can be used to quickly tell if a connection to the
621
-	 * server is able to be made.
622
-	 *
623
-	 * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
624
-	 * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
625
-	 */
626
-	public function ping($timeout = 2)
627
-	{
628
-		$start = microtime(true);
88
+    /**
89
+     * SVN Revision meta data for this class
90
+     */
91
+    const SVN_REVISION = '$Revision: 59 $';
92
+
93
+    /**
94
+     * SVN ID meta data for this class
95
+     */
96
+    const SVN_ID = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $';
97
+
98
+    /**
99
+     * Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
100
+     */
101
+    const SOLR_WRITER = 'json';
102
+
103
+    /**
104
+     * NamedList Treatment constants
105
+     */
106
+    const NAMED_LIST_FLAT = 'flat';
107
+    const NAMED_LIST_MAP = 'map';
108
+
109
+    /**
110
+     * Search HTTP Methods
111
+     */
112
+    const METHOD_GET = 'GET';
113
+    const METHOD_POST = 'POST';
114
+
115
+    /**
116
+     * Servlet mappings
117
+     */
118
+    const PING_SERVLET = 'admin/ping';
119
+    const UPDATE_SERVLET = 'update';
120
+    const SEARCH_SERVLET = 'select';
121
+    const THREADS_SERVLET = 'admin/threads';
122
+    const EXTRACT_SERVLET = 'update/extract';
123
+
124
+    /**
125
+     * Server identification strings
126
+     *
127
+     * @var string
128
+     */
129
+    protected $_host, $_port, $_path;
130
+
131
+    /**
132
+     * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in
133
+     * the returned parsed data
134
+     *
135
+     * @var boolean
136
+     */
137
+    protected $_createDocuments = true;
138
+
139
+    /**
140
+     * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
141
+     * collapsed to appear as a single value would.
142
+     *
143
+     * @var boolean
144
+     */
145
+    protected $_collapseSingleValueArrays = true;
146
+
147
+    /**
148
+     * How NamedLists should be formatted in the output.  This specifically effects facet counts. Valid values
149
+     * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}.
150
+     *
151
+     * @var string
152
+     */
153
+    protected $_namedListTreatment = self::NAMED_LIST_MAP;
154
+
155
+    /**
156
+     * Query delimiters. Someone might want to be able to change
157
+     * these (to use &amp; instead of & for example), so I've provided them.
158
+     *
159
+     * @var string
160
+     */
161
+    protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = true;
162
+
163
+    /**
164
+     * Constructed servlet full path URLs
165
+     *
166
+     * @var string
167
+     */
168
+    protected $_pingUrl, $_updateUrl, $_searchUrl, $_threadsUrl;
169
+
170
+    /**
171
+     * Keep track of whether our URLs have been constructed
172
+     *
173
+     * @var boolean
174
+     */
175
+    protected $_urlsInited = false;
176
+
177
+    /**
178
+     * HTTP Transport implementation (pluggable)
179
+     *
180
+     * @var Apache_Solr_HttpTransport_Interface
181
+     */
182
+    protected $_httpTransport = false;
183
+
184
+    /**
185
+     * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
186
+     *
187
+     * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
188
+     *
189
+     * @param string $value
190
+     * @return string
191
+     */
192
+    static public function escape($value)
193
+    {
194
+        //list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
195
+        $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
196
+        $replace = '\\\$1';
197
+
198
+        return preg_replace($pattern, $replace, $value);
199
+    }
200
+
201
+    /**
202
+     * Escape a value meant to be contained in a phrase for special query characters
203
+     *
204
+     * @param string $value
205
+     * @return string
206
+     */
207
+    static public function escapePhrase($value)
208
+    {
209
+        $pattern = '/("|\\\)/';
210
+        $replace = '\\\$1';
211
+
212
+        return preg_replace($pattern, $replace, $value);
213
+    }
214
+
215
+    /**
216
+     * Convenience function for creating phrase syntax from a value
217
+     *
218
+     * @param string $value
219
+     * @return string
220
+     */
221
+    static public function phrase($value)
222
+    {
223
+        return '"' . self::escapePhrase($value) . '"';
224
+    }
225
+
226
+    /**
227
+     * Constructor. All parameters are optional and will take on default values
228
+     * if not specified.
229
+     *
230
+     * @param string $host
231
+     * @param string $port
232
+     * @param string $path
233
+     * @param Apache_Solr_HttpTransport_Interface $httpTransport
234
+     */
235
+    public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false)
236
+    {
237
+        $this->setHost($host);
238
+        $this->setPort($port);
239
+        $this->setPath($path);
240
+
241
+        $this->_initUrls();
242
+
243
+        if ($httpTransport)
244
+        {
245
+            $this->setHttpTransport($httpTransport);
246
+        }
247
+
248
+        // check that our php version is >= 5.1.3 so we can correct for http_build_query behavior later
249
+        $this->_queryBracketsEscaped = version_compare(phpversion(), '5.1.3', '>=');
250
+    }
251
+
252
+    /**
253
+     * Return a valid http URL given this server's host, port and path and a provided servlet name
254
+     *
255
+     * @param string $servlet
256
+     * @return string
257
+     */
258
+    protected function _constructUrl($servlet, $params = array())
259
+    {
260
+        if (count($params))
261
+        {
262
+            //escape all parameters appropriately for inclusion in the query string
263
+            $escapedParams = array();
264
+
265
+            foreach ($params as $key => $value)
266
+            {
267
+                $escapedParams[] = urlencode($key) . '=' . urlencode($value);
268
+            }
269
+
270
+            $queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
271
+        }
272
+        else
273
+        {
274
+            $queryString = '';
275
+        }
276
+
277
+        return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString;
278
+    }
279
+
280
+    /**
281
+     * Construct the Full URLs for the three servlets we reference
282
+     */
283
+    protected function _initUrls()
284
+    {
285
+        //Initialize our full servlet URLs now that we have server information
286
+        $this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET);
287
+        $this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
288
+        $this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
289
+        $this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
290
+        $this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
291
+
292
+        $this->_urlsInited = true;
293
+    }
294
+
295
+    protected function _generateQueryString($params)
296
+    {
297
+        // use http_build_query to encode our arguments because its faster
298
+        // than urlencoding all the parts ourselves in a loop
299
+        //
300
+        // because http_build_query treats arrays differently than we want to, correct the query
301
+        // string by changing foo[#]=bar (# being an actual number) parameter strings to just
302
+        // multiple foo=bar strings. This regex should always work since '=' will be urlencoded
303
+        // anywhere else the regex isn't expecting it
304
+        //
305
+        // NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked
306
+        // the php version in the constructor and put the results in the instance variable. Also, before
307
+        // 5.1.2 the arg_separator parameter was not available, so don't use it
308
+        if ($this->_queryBracketsEscaped)
309
+        {
310
+            $queryString = http_build_query($params, null, $this->_queryStringDelimiter);
311
+            return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
312
+        }
313
+        else
314
+        {
315
+            $queryString = http_build_query($params);
316
+            return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $queryString);
317
+        }
318
+    }
319
+
320
+    /**
321
+     * Central method for making a get operation against this Solr Server
322
+     *
323
+     * @param string $url
324
+     * @param float $timeout Read timeout in seconds
325
+     * @return Apache_Solr_Response
326
+     *
327
+     * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
328
+     */
329
+    protected function _sendRawGet($url, $timeout = FALSE)
330
+    {
331
+        $httpTransport = $this->getHttpTransport();
332
+
333
+        $httpResponse = $httpTransport->performGetRequest($url, $timeout);
334
+        $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
335
+
336
+        if ($solrResponse->getHttpStatus() != 200)
337
+        {
338
+            throw new Apache_Solr_HttpTransportException($solrResponse);
339
+        }
340
+
341
+        return $solrResponse;
342
+    }
343
+
344
+    /**
345
+     * Central method for making a post operation against this Solr Server
346
+     *
347
+     * @param string $url
348
+     * @param string $rawPost
349
+     * @param float $timeout Read timeout in seconds
350
+     * @param string $contentType
351
+     * @return Apache_Solr_Response
352
+     *
353
+     * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
354
+     */
355
+    protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
356
+    {
357
+        $httpTransport = $this->getHttpTransport();
358
+
359
+        $httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
360
+        $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
361
+
362
+        if ($solrResponse->getHttpStatus() != 200)
363
+        {
364
+            throw new Apache_Solr_HttpTransportException($solrResponse);
365
+        }
366
+
367
+        return $solrResponse;
368
+    }
369
+
370
+    /**
371
+     * Returns the set host
372
+     *
373
+     * @return string
374
+     */
375
+    public function getHost()
376
+    {
377
+        return $this->_host;
378
+    }
379
+
380
+    /**
381
+     * Set the host used. If empty will fallback to constants
382
+     *
383
+     * @param string $host
384
+     *
385
+     * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
386
+     */
387
+    public function setHost($host)
388
+    {
389
+        //Use the provided host or use the default
390
+        if (empty($host))
391
+        {
392
+            throw new Apache_Solr_InvalidArgumentException('Host parameter is empty');
393
+        }
394
+        else
395
+        {
396
+            $this->_host = $host;
397
+        }
398
+
399
+        if ($this->_urlsInited)
400
+        {
401
+            $this->_initUrls();
402
+        }
403
+    }
404
+
405
+    /**
406
+     * Get the set port
407
+     *
408
+     * @return integer
409
+     */
410
+    public function getPort()
411
+    {
412
+        return $this->_port;
413
+    }
414
+
415
+    /**
416
+     * Set the port used. If empty will fallback to constants
417
+     *
418
+     * @param integer $port
419
+     *
420
+     * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
421
+     */
422
+    public function setPort($port)
423
+    {
424
+        //Use the provided port or use the default
425
+        $port = (int) $port;
426
+
427
+        if ($port <= 0)
428
+        {
429
+            throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number');
430
+        }
431
+        else
432
+        {
433
+            $this->_port = $port;
434
+        }
435
+
436
+        if ($this->_urlsInited)
437
+        {
438
+            $this->_initUrls();
439
+        }
440
+    }
441
+
442
+    /**
443
+     * Get the set path.
444
+     *
445
+     * @return string
446
+     */
447
+    public function getPath()
448
+    {
449
+        return $this->_path;
450
+    }
451
+
452
+    /**
453
+     * Set the path used. If empty will fallback to constants
454
+     *
455
+     * @param string $path
456
+     */
457
+    public function setPath($path)
458
+    {
459
+        $path = trim($path, '/');
460
+
461
+        $this->_path = '/' . $path . '/';
462
+
463
+        if ($this->_urlsInited)
464
+        {
465
+            $this->_initUrls();
466
+        }
467
+    }
468
+
469
+    /**
470
+     * Get the current configured HTTP Transport
471
+     *
472
+     * @return HttpTransportInterface
473
+     */
474
+    public function getHttpTransport()
475
+    {
476
+        // lazy load a default if one has not be set
477
+        if ($this->_httpTransport === false)
478
+        {
479
+            require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
480
+
481
+            $this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
482
+        }
483
+
484
+        return $this->_httpTransport;
485
+    }
486
+
487
+    /**
488
+     * Set the HTTP Transport implemenation that will be used for all HTTP requests
489
+     *
490
+     * @param Apache_Solr_HttpTransport_Interface
491
+     */
492
+    public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport)
493
+    {
494
+        $this->_httpTransport = $httpTransport;
495
+    }
496
+
497
+    /**
498
+     * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
499
+     * parse the response and create {@link Apache_Solr_Document} instances in place.
500
+     *
501
+     * @param boolean $createDocuments
502
+     */
503
+    public function setCreateDocuments($createDocuments)
504
+    {
505
+        $this->_createDocuments = (bool) $createDocuments;
506
+    }
507
+
508
+    /**
509
+     * Get the current state of the create documents flag.
510
+     *
511
+     * @return boolean
512
+     */
513
+    public function getCreateDocuments()
514
+    {
515
+        return $this->_createDocuments;
516
+    }
517
+
518
+    /**
519
+     * Set the collapse single value arrays flag.
520
+     *
521
+     * @param boolean $collapseSingleValueArrays
522
+     */
523
+    public function setCollapseSingleValueArrays($collapseSingleValueArrays)
524
+    {
525
+        $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
526
+    }
527
+
528
+    /**
529
+     * Get the current state of the collapse single value arrays flag.
530
+     *
531
+     * @return boolean
532
+     */
533
+    public function getCollapseSingleValueArrays()
534
+    {
535
+        return $this->_collapseSingleValueArrays;
536
+    }
537
+
538
+    /**
539
+     * Get the current default timeout setting (initially the default_socket_timeout ini setting)
540
+     * in seconds
541
+     *
542
+     * @return float
543
+     *
544
+     * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation
545
+     */
546
+    public function getDefaultTimeout()
547
+    {
548
+        return $this->getHttpTransport()->getDefaultTimeout();
549
+    }
550
+
551
+    /**
552
+     * Set the default timeout for all calls that aren't passed a specific timeout
553
+     *
554
+     * @param float $timeout Timeout value in seconds
555
+     *
556
+     * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation
557
+     */
558
+    public function setDefaultTimeout($timeout)
559
+    {
560
+        $this->getHttpTransport()->setDefaultTimeout($timeout);
561
+    }
562
+
563
+    /**
564
+     * Set how NamedLists should be formatted in the response data. This mainly effects
565
+     * the facet counts format.
566
+     *
567
+     * @param string $namedListTreatment
568
+     * @throws Apache_Solr_InvalidArgumentException If invalid option is set
569
+     */
570
+    public function setNamedListTreatment($namedListTreatment)
571
+    {
572
+        switch ((string) $namedListTreatment)
573
+        {
574
+            case Apache_Solr_Service::NAMED_LIST_FLAT:
575
+                $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
576
+                break;
577
+
578
+            case Apache_Solr_Service::NAMED_LIST_MAP:
579
+                $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP;
580
+                break;
581
+
582
+            default:
583
+                throw new Apache_Solr_InvalidArgumentException('Not a valid named list treatement option');
584
+        }
585
+    }
586
+
587
+    /**
588
+     * Get the current setting for named list treatment.
589
+     *
590
+     * @return string
591
+     */
592
+    public function getNamedListTreatment()
593
+    {
594
+        return $this->_namedListTreatment;
595
+    }
596
+
597
+    /**
598
+     * Set the string used to separate the path form the query string.
599
+     * Defaulted to '?'
600
+     *
601
+     * @param string $queryDelimiter
602
+     */
603
+    public function setQueryDelimiter($queryDelimiter)
604
+    {
605
+        $this->_queryDelimiter = $queryDelimiter;
606
+    }
607
+
608
+    /**
609
+     * Set the string used to separate the parameters in thequery string
610
+     * Defaulted to '&'
611
+     *
612
+     * @param string $queryStringDelimiter
613
+     */
614
+    public function setQueryStringDelimiter($queryStringDelimiter)
615
+    {
616
+        $this->_queryStringDelimiter = $queryStringDelimiter;
617
+    }
618
+
619
+    /**
620
+     * Call the /admin/ping servlet, can be used to quickly tell if a connection to the
621
+     * server is able to be made.
622
+     *
623
+     * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
624
+     * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
625
+     */
626
+    public function ping($timeout = 2)
627
+    {
628
+        $start = microtime(true);
629 629
 		
630
-		$httpTransport = $this->getHttpTransport();
631
-
632
-		$httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
633
-		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
634
-
635
-		if ($solrResponse->getHttpStatus() == 200)
636
-		{
637
-			return microtime(true) - $start;
638
-		}
639
-		else
640
-		{
641
-			return false;
642
-		}
643
-	}
644
-
645
-	/**
646
-	 * Call the /admin/threads servlet and retrieve information about all threads in the
647
-	 * Solr servlet's thread group. Useful for diagnostics.
648
-	 *
649
-	 * @return Apache_Solr_Response
650
-	 *
651
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
652
-	 */
653
-	public function threads()
654
-	{
655
-		return $this->_sendRawGet($this->_threadsUrl);
656
-	}
657
-
658
-	/**
659
-	 * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
660
-	 * should be a complete and well formed "add" xml document.
661
-	 *
662
-	 * @param string $rawPost
663
-	 * @return Apache_Solr_Response
664
-	 *
665
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
666
-	 */
667
-	public function add($rawPost)
668
-	{
669
-		return $this->_sendRawPost($this->_updateUrl, $rawPost);
670
-	}
671
-
672
-	/**
673
-	 * Add a Solr Document to the index
674
-	 *
675
-	 * @param Apache_Solr_Document $document
676
-	 * @param boolean $allowDups
677
-	 * @param boolean $overwritePending
678
-	 * @param boolean $overwriteCommitted
679
-	 * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
680
-	 * @return Apache_Solr_Response
681
-	 *
682
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
683
-	 */
684
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
685
-	{
686
-		$dupValue = $allowDups ? 'true' : 'false';
687
-		$pendingValue = $overwritePending ? 'true' : 'false';
688
-		$committedValue = $overwriteCommitted ? 'true' : 'false';
630
+        $httpTransport = $this->getHttpTransport();
631
+
632
+        $httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
633
+        $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
634
+
635
+        if ($solrResponse->getHttpStatus() == 200)
636
+        {
637
+            return microtime(true) - $start;
638
+        }
639
+        else
640
+        {
641
+            return false;
642
+        }
643
+    }
644
+
645
+    /**
646
+     * Call the /admin/threads servlet and retrieve information about all threads in the
647
+     * Solr servlet's thread group. Useful for diagnostics.
648
+     *
649
+     * @return Apache_Solr_Response
650
+     *
651
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
652
+     */
653
+    public function threads()
654
+    {
655
+        return $this->_sendRawGet($this->_threadsUrl);
656
+    }
657
+
658
+    /**
659
+     * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
660
+     * should be a complete and well formed "add" xml document.
661
+     *
662
+     * @param string $rawPost
663
+     * @return Apache_Solr_Response
664
+     *
665
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
666
+     */
667
+    public function add($rawPost)
668
+    {
669
+        return $this->_sendRawPost($this->_updateUrl, $rawPost);
670
+    }
671
+
672
+    /**
673
+     * Add a Solr Document to the index
674
+     *
675
+     * @param Apache_Solr_Document $document
676
+     * @param boolean $allowDups
677
+     * @param boolean $overwritePending
678
+     * @param boolean $overwriteCommitted
679
+     * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
680
+     * @return Apache_Solr_Response
681
+     *
682
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
683
+     */
684
+    public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
685
+    {
686
+        $dupValue = $allowDups ? 'true' : 'false';
687
+        $pendingValue = $overwritePending ? 'true' : 'false';
688
+        $committedValue = $overwriteCommitted ? 'true' : 'false';
689 689
 		
690
-		$commitWithin = (int) $commitWithin;
691
-		$commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
690
+        $commitWithin = (int) $commitWithin;
691
+        $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
692 692
 		
693
-		$rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
694
-		$rawPost .= $this->_documentToXmlFragment($document);
695
-		$rawPost .= '</add>';
696
-
697
-		return $this->add($rawPost);
698
-	}
699
-
700
-	/**
701
-	 * Add an array of Solr Documents to the index all at once
702
-	 *
703
-	 * @param array $documents Should be an array of Apache_Solr_Document instances
704
-	 * @param boolean $allowDups
705
-	 * @param boolean $overwritePending
706
-	 * @param boolean $overwriteCommitted
707
-	 * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
708
-	 * @return Apache_Solr_Response
709
-	 *
710
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
711
-	 */
712
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
713
-	{
714
-		$dupValue = $allowDups ? 'true' : 'false';
715
-		$pendingValue = $overwritePending ? 'true' : 'false';
716
-		$committedValue = $overwriteCommitted ? 'true' : 'false';
717
-
718
-		$commitWithin = (int) $commitWithin;
719
-		$commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
720
-
721
-		$rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
722
-
723
-		foreach ($documents as $document)
724
-		{
725
-			if ($document instanceof Apache_Solr_Document)
726
-			{
727
-				$rawPost .= $this->_documentToXmlFragment($document);
728
-			}
729
-		}
730
-
731
-		$rawPost .= '</add>';
732
-
733
-		return $this->add($rawPost);
734
-	}
735
-
736
-	/**
737
-	 * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
738
-	 *
739
-	 * @return string
740
-	 */
741
-	protected function _documentToXmlFragment(Apache_Solr_Document $document)
742
-	{
743
-		$xml = '<doc';
744
-
745
-		if ($document->getBoost() !== false)
746
-		{
747
-			$xml .= ' boost="' . $document->getBoost() . '"';
748
-		}
749
-
750
-		$xml .= '>';
751
-
752
-		foreach ($document as $key => $value)
753
-		{
754
-			$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
755
-			$fieldBoost = $document->getFieldBoost($key);
756
-
757
-			if (is_array($value))
758
-			{
759
-				foreach ($value as $multivalue)
760
-				{
761
-					$xml .= '<field name="' . $key . '"';
762
-
763
-					if ($fieldBoost !== false)
764
-					{
765
-						$xml .= ' boost="' . $fieldBoost . '"';
766
-
767
-						// only set the boost for the first field in the set
768
-						$fieldBoost = false;
769
-					}
770
-
771
-					$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
772
-
773
-					$xml .= '>' . $multivalue . '</field>';
774
-				}
775
-			}
776
-			else
777
-			{
778
-				$xml .= '<field name="' . $key . '"';
779
-
780
-				if ($fieldBoost !== false)
781
-				{
782
-					$xml .= ' boost="' . $fieldBoost . '"';
783
-				}
784
-
785
-				$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
786
-
787
-				$xml .= '>' . $value . '</field>';
788
-			}
789
-		}
790
-
791
-		$xml .= '</doc>';
792
-
793
-		// replace any control characters to avoid Solr XML parser exception
794
-		return $this->_stripCtrlChars($xml);
795
-	}
796
-
797
-	/**
798
-	 * Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
799
-	 *
800
-	 * @param string $string
801
-	 * @return string
802
-	 */
803
-	protected function _stripCtrlChars($string)
804
-	{
805
-		// See:  http://w3.org/International/questions/qa-forms-utf-8.html
806
-		// Printable utf-8 does not include any of these chars below x7F
807
-		return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $string);
808
-	}
809
-
810
-	/**
811
-	 * Send a commit command.  Will be synchronous unless both wait parameters are set to false.
812
-	 *
813
-	 * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away
814
-	 * @param boolean $waitFlush Defaults to true,  block until index changes are flushed to disk
815
-	 * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
816
-	 * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
817
-	 * @return Apache_Solr_Response
818
-	 *
819
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
820
-	 */
821
-	public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
822
-	{
823
-		$expungeValue = $expungeDeletes ? 'true' : 'false';
824
-		$flushValue = $waitFlush ? 'true' : 'false';
825
-		$searcherValue = $waitSearcher ? 'true' : 'false';
826
-
827
-		$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
828
-
829
-		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
830
-	}
831
-
832
-	/**
833
-	 * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
834
-	 * a complete and well formed "delete" xml document
835
-	 *
836
-	 * @param string $rawPost Expected to be utf-8 encoded xml document
837
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
838
-	 * @return Apache_Solr_Response
839
-	 *
840
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
841
-	 */
842
-	public function delete($rawPost, $timeout = 3600)
843
-	{
844
-		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
845
-	}
846
-
847
-	/**
848
-	 * Create a delete document based on document ID
849
-	 *
850
-	 * @param string $id Expected to be utf-8 encoded
851
-	 * @param boolean $fromPending
852
-	 * @param boolean $fromCommitted
853
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
854
-	 * @return Apache_Solr_Response
855
-	 *
856
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
857
-	 */
858
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
859
-	{
860
-		$pendingValue = $fromPending ? 'true' : 'false';
861
-		$committedValue = $fromCommitted ? 'true' : 'false';
862
-
863
-		//escape special xml characters
864
-		$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
865
-
866
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><id>' . $id . '</id></delete>';
867
-
868
-		return $this->delete($rawPost, $timeout);
869
-	}
870
-
871
-	/**
872
-	 * Create and post a delete document based on multiple document IDs.
873
-	 *
874
-	 * @param array $ids Expected to be utf-8 encoded strings
875
-	 * @param boolean $fromPending
876
-	 * @param boolean $fromCommitted
877
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
878
-	 * @return Apache_Solr_Response
879
-	 *
880
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
881
-	 */
882
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
883
-	{
884
-		$pendingValue = $fromPending ? 'true' : 'false';
885
-		$committedValue = $fromCommitted ? 'true' : 'false';
886
-
887
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">';
888
-
889
-		foreach ($ids as $id)
890
-		{
891
-			//escape special xml characters
892
-			$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
893
-
894
-			$rawPost .= '<id>' . $id . '</id>';
895
-		}
896
-
897
-		$rawPost .= '</delete>';
898
-
899
-		return $this->delete($rawPost, $timeout);
900
-	}
901
-
902
-	/**
903
-	 * Create a delete document based on a query and submit it
904
-	 *
905
-	 * @param string $rawQuery Expected to be utf-8 encoded
906
-	 * @param boolean $fromPending
907
-	 * @param boolean $fromCommitted
908
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
909
-	 * @return Apache_Solr_Response
910
-	 *
911
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
912
-	 */
913
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
914
-	{
915
-		$pendingValue = $fromPending ? 'true' : 'false';
916
-		$committedValue = $fromCommitted ? 'true' : 'false';
917
-
918
-		// escape special xml characters
919
-		$rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8');
920
-
921
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><query>' . $rawQuery . '</query></delete>';
922
-
923
-		return $this->delete($rawPost, $timeout);
924
-	}
925
-
926
-	/**
927
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
928
-	 * to use Solr Cell and what parameters are available.
929
-	 *
930
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
931
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
932
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
933
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
934
-	 *
935
-	 * @param string $file Path to file to extract data from
936
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
937
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
938
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
939
-	 *
940
-	 * @return Apache_Solr_Response
941
-	 *
942
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943
-	 */
944
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
945
-	{
946
-		// check if $params is an array (allow null for default empty array)
947
-		if (!is_null($params))
948
-		{
949
-			if (!is_array($params))
950
-			{
951
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
952
-			}
953
-		}
954
-		else
955
-		{
956
-			$params = array();
957
-		}
693
+        $rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
694
+        $rawPost .= $this->_documentToXmlFragment($document);
695
+        $rawPost .= '</add>';
696
+
697
+        return $this->add($rawPost);
698
+    }
699
+
700
+    /**
701
+     * Add an array of Solr Documents to the index all at once
702
+     *
703
+     * @param array $documents Should be an array of Apache_Solr_Document instances
704
+     * @param boolean $allowDups
705
+     * @param boolean $overwritePending
706
+     * @param boolean $overwriteCommitted
707
+     * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
708
+     * @return Apache_Solr_Response
709
+     *
710
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
711
+     */
712
+    public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
713
+    {
714
+        $dupValue = $allowDups ? 'true' : 'false';
715
+        $pendingValue = $overwritePending ? 'true' : 'false';
716
+        $committedValue = $overwriteCommitted ? 'true' : 'false';
717
+
718
+        $commitWithin = (int) $commitWithin;
719
+        $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
720
+
721
+        $rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
722
+
723
+        foreach ($documents as $document)
724
+        {
725
+            if ($document instanceof Apache_Solr_Document)
726
+            {
727
+                $rawPost .= $this->_documentToXmlFragment($document);
728
+            }
729
+        }
730
+
731
+        $rawPost .= '</add>';
732
+
733
+        return $this->add($rawPost);
734
+    }
735
+
736
+    /**
737
+     * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
738
+     *
739
+     * @return string
740
+     */
741
+    protected function _documentToXmlFragment(Apache_Solr_Document $document)
742
+    {
743
+        $xml = '<doc';
744
+
745
+        if ($document->getBoost() !== false)
746
+        {
747
+            $xml .= ' boost="' . $document->getBoost() . '"';
748
+        }
749
+
750
+        $xml .= '>';
751
+
752
+        foreach ($document as $key => $value)
753
+        {
754
+            $key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
755
+            $fieldBoost = $document->getFieldBoost($key);
756
+
757
+            if (is_array($value))
758
+            {
759
+                foreach ($value as $multivalue)
760
+                {
761
+                    $xml .= '<field name="' . $key . '"';
762
+
763
+                    if ($fieldBoost !== false)
764
+                    {
765
+                        $xml .= ' boost="' . $fieldBoost . '"';
766
+
767
+                        // only set the boost for the first field in the set
768
+                        $fieldBoost = false;
769
+                    }
770
+
771
+                    $multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
772
+
773
+                    $xml .= '>' . $multivalue . '</field>';
774
+                }
775
+            }
776
+            else
777
+            {
778
+                $xml .= '<field name="' . $key . '"';
779
+
780
+                if ($fieldBoost !== false)
781
+                {
782
+                    $xml .= ' boost="' . $fieldBoost . '"';
783
+                }
784
+
785
+                $value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
786
+
787
+                $xml .= '>' . $value . '</field>';
788
+            }
789
+        }
790
+
791
+        $xml .= '</doc>';
792
+
793
+        // replace any control characters to avoid Solr XML parser exception
794
+        return $this->_stripCtrlChars($xml);
795
+    }
796
+
797
+    /**
798
+     * Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
799
+     *
800
+     * @param string $string
801
+     * @return string
802
+     */
803
+    protected function _stripCtrlChars($string)
804
+    {
805
+        // See:  http://w3.org/International/questions/qa-forms-utf-8.html
806
+        // Printable utf-8 does not include any of these chars below x7F
807
+        return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $string);
808
+    }
809
+
810
+    /**
811
+     * Send a commit command.  Will be synchronous unless both wait parameters are set to false.
812
+     *
813
+     * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away
814
+     * @param boolean $waitFlush Defaults to true,  block until index changes are flushed to disk
815
+     * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
816
+     * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
817
+     * @return Apache_Solr_Response
818
+     *
819
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
820
+     */
821
+    public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
822
+    {
823
+        $expungeValue = $expungeDeletes ? 'true' : 'false';
824
+        $flushValue = $waitFlush ? 'true' : 'false';
825
+        $searcherValue = $waitSearcher ? 'true' : 'false';
826
+
827
+        $rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
828
+
829
+        return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
830
+    }
831
+
832
+    /**
833
+     * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
834
+     * a complete and well formed "delete" xml document
835
+     *
836
+     * @param string $rawPost Expected to be utf-8 encoded xml document
837
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
838
+     * @return Apache_Solr_Response
839
+     *
840
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
841
+     */
842
+    public function delete($rawPost, $timeout = 3600)
843
+    {
844
+        return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
845
+    }
846
+
847
+    /**
848
+     * Create a delete document based on document ID
849
+     *
850
+     * @param string $id Expected to be utf-8 encoded
851
+     * @param boolean $fromPending
852
+     * @param boolean $fromCommitted
853
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
854
+     * @return Apache_Solr_Response
855
+     *
856
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
857
+     */
858
+    public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
859
+    {
860
+        $pendingValue = $fromPending ? 'true' : 'false';
861
+        $committedValue = $fromCommitted ? 'true' : 'false';
862
+
863
+        //escape special xml characters
864
+        $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
865
+
866
+        $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><id>' . $id . '</id></delete>';
867
+
868
+        return $this->delete($rawPost, $timeout);
869
+    }
870
+
871
+    /**
872
+     * Create and post a delete document based on multiple document IDs.
873
+     *
874
+     * @param array $ids Expected to be utf-8 encoded strings
875
+     * @param boolean $fromPending
876
+     * @param boolean $fromCommitted
877
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
878
+     * @return Apache_Solr_Response
879
+     *
880
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
881
+     */
882
+    public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
883
+    {
884
+        $pendingValue = $fromPending ? 'true' : 'false';
885
+        $committedValue = $fromCommitted ? 'true' : 'false';
886
+
887
+        $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">';
888
+
889
+        foreach ($ids as $id)
890
+        {
891
+            //escape special xml characters
892
+            $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
893
+
894
+            $rawPost .= '<id>' . $id . '</id>';
895
+        }
896
+
897
+        $rawPost .= '</delete>';
898
+
899
+        return $this->delete($rawPost, $timeout);
900
+    }
901
+
902
+    /**
903
+     * Create a delete document based on a query and submit it
904
+     *
905
+     * @param string $rawQuery Expected to be utf-8 encoded
906
+     * @param boolean $fromPending
907
+     * @param boolean $fromCommitted
908
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
909
+     * @return Apache_Solr_Response
910
+     *
911
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
912
+     */
913
+    public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
914
+    {
915
+        $pendingValue = $fromPending ? 'true' : 'false';
916
+        $committedValue = $fromCommitted ? 'true' : 'false';
917
+
918
+        // escape special xml characters
919
+        $rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8');
920
+
921
+        $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><query>' . $rawQuery . '</query></delete>';
922
+
923
+        return $this->delete($rawPost, $timeout);
924
+    }
925
+
926
+    /**
927
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
928
+     * to use Solr Cell and what parameters are available.
929
+     *
930
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
931
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
932
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
933
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
934
+     *
935
+     * @param string $file Path to file to extract data from
936
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
937
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
938
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
939
+     *
940
+     * @return Apache_Solr_Response
941
+     *
942
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943
+     */
944
+    public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
945
+    {
946
+        // check if $params is an array (allow null for default empty array)
947
+        if (!is_null($params))
948
+        {
949
+            if (!is_array($params))
950
+            {
951
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
952
+            }
953
+        }
954
+        else
955
+        {
956
+            $params = array();
957
+        }
958 958
 		
959
-		// if $file is an http request, defer to extractFromUrl instead
960
-		if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://')
961
-		{
962
-			return $this->extractFromUrl($file, $params, $document, $mimetype);
963
-		}
959
+        // if $file is an http request, defer to extractFromUrl instead
960
+        if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://')
961
+        {
962
+            return $this->extractFromUrl($file, $params, $document, $mimetype);
963
+        }
964 964
 		
965
-		// read the contents of the file
966
-		$contents = @file_get_contents($file);
967
-
968
-		if ($contents !== false)
969
-		{
970
-			// add the resource.name parameter if not specified
971
-			if (!isset($params['resource.name']))
972
-			{
973
-				$params['resource.name'] = basename($file);
974
-			}
975
-
976
-			// delegate the rest to extractFromString
977
-			return $this->extractFromString($contents, $params, $document, $mimetype);
978
-		}
979
-		else
980
-		{
981
-			throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
982
-		}
983
-	}
965
+        // read the contents of the file
966
+        $contents = @file_get_contents($file);
967
+
968
+        if ($contents !== false)
969
+        {
970
+            // add the resource.name parameter if not specified
971
+            if (!isset($params['resource.name']))
972
+            {
973
+                $params['resource.name'] = basename($file);
974
+            }
975
+
976
+            // delegate the rest to extractFromString
977
+            return $this->extractFromString($contents, $params, $document, $mimetype);
978
+        }
979
+        else
980
+        {
981
+            throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
982
+        }
983
+    }
984 984
 	
985
-	/**
986
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
987
-	 * to use Solr Cell and what parameters are available.
988
-	 *
989
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
990
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
991
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
992
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
993
-	 *
994
-	 * @param string $data Data that will be passed to Solr Cell
995
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
996
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
997
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
998
-	 *
999
-	 * @return Apache_Solr_Response
1000
-	 *
1001
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
1002
-	 *
1003
-	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004
-	 */
1005
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1006
-	{
1007
-		// check if $params is an array (allow null for default empty array)
1008
-		if (!is_null($params))
1009
-		{
1010
-			if (!is_array($params))
1011
-			{
1012
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1013
-			}
1014
-		}
1015
-		else
1016
-		{
1017
-			$params = array();
1018
-		}
1019
-
1020
-		// make sure we receive our response in JSON and have proper name list treatment
1021
-		$params['wt'] = self::SOLR_WRITER;
1022
-		$params['json.nl'] = $this->_namedListTreatment;
1023
-
1024
-		// check if $document is an Apache_Solr_Document instance
1025
-		if (!is_null($document) && $document instanceof Apache_Solr_Document)
1026
-		{
1027
-			// iterate document, adding literal.* and boost.* fields to $params as appropriate
1028
-			foreach ($document as $field => $fieldValue)
1029
-			{
1030
-				// check if we need to add a boost.* parameters
1031
-				$fieldBoost = $document->getFieldBoost($field);
1032
-
1033
-				if ($fieldBoost !== false)
1034
-				{
1035
-					$params["boost.{$field}"] = $fieldBoost;
1036
-				}
1037
-
1038
-				// add the literal.* parameter
1039
-				$params["literal.{$field}"] = $fieldValue;
1040
-			}
1041
-		}
1042
-
1043
-		// params will be sent to SOLR in the QUERY STRING
1044
-		$queryString = $this->_generateQueryString($params);
1045
-
1046
-		// the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
1047
-		return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
1048
-	}
985
+    /**
986
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
987
+     * to use Solr Cell and what parameters are available.
988
+     *
989
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
990
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
991
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
992
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
993
+     *
994
+     * @param string $data Data that will be passed to Solr Cell
995
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
996
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
997
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
998
+     *
999
+     * @return Apache_Solr_Response
1000
+     *
1001
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
1002
+     *
1003
+     * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004
+     */
1005
+    public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1006
+    {
1007
+        // check if $params is an array (allow null for default empty array)
1008
+        if (!is_null($params))
1009
+        {
1010
+            if (!is_array($params))
1011
+            {
1012
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1013
+            }
1014
+        }
1015
+        else
1016
+        {
1017
+            $params = array();
1018
+        }
1019
+
1020
+        // make sure we receive our response in JSON and have proper name list treatment
1021
+        $params['wt'] = self::SOLR_WRITER;
1022
+        $params['json.nl'] = $this->_namedListTreatment;
1023
+
1024
+        // check if $document is an Apache_Solr_Document instance
1025
+        if (!is_null($document) && $document instanceof Apache_Solr_Document)
1026
+        {
1027
+            // iterate document, adding literal.* and boost.* fields to $params as appropriate
1028
+            foreach ($document as $field => $fieldValue)
1029
+            {
1030
+                // check if we need to add a boost.* parameters
1031
+                $fieldBoost = $document->getFieldBoost($field);
1032
+
1033
+                if ($fieldBoost !== false)
1034
+                {
1035
+                    $params["boost.{$field}"] = $fieldBoost;
1036
+                }
1037
+
1038
+                // add the literal.* parameter
1039
+                $params["literal.{$field}"] = $fieldValue;
1040
+            }
1041
+        }
1042
+
1043
+        // params will be sent to SOLR in the QUERY STRING
1044
+        $queryString = $this->_generateQueryString($params);
1045
+
1046
+        // the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
1047
+        return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
1048
+    }
1049 1049
 	
1050
-	/**
1051
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
1052
-	 * to use Solr Cell and what parameters are available.
1053
-	 *
1054
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
1055
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
1056
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
1057
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
1058
-	 *
1059
-	 * @param string $url URL
1060
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
1061
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
1062
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
1063
-	 *
1064
-	 * @return Apache_Solr_Response
1065
-	 *
1066
-	 * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067
-	 */
1068
-	public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1069
-	{
1070
-		// check if $params is an array (allow null for default empty array)
1071
-		if (!is_null($params))
1072
-		{
1073
-			if (!is_array($params))
1074
-			{
1075
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1076
-			}
1077
-		}
1078
-		else
1079
-		{
1080
-			$params = array();
1081
-		}
1082
-
1083
-		$httpTransport = $this->getHttpTransport();
1050
+    /**
1051
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
1052
+     * to use Solr Cell and what parameters are available.
1053
+     *
1054
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
1055
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
1056
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
1057
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
1058
+     *
1059
+     * @param string $url URL
1060
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
1061
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
1062
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
1063
+     *
1064
+     * @return Apache_Solr_Response
1065
+     *
1066
+     * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067
+     */
1068
+    public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1069
+    {
1070
+        // check if $params is an array (allow null for default empty array)
1071
+        if (!is_null($params))
1072
+        {
1073
+            if (!is_array($params))
1074
+            {
1075
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1076
+            }
1077
+        }
1078
+        else
1079
+        {
1080
+            $params = array();
1081
+        }
1082
+
1083
+        $httpTransport = $this->getHttpTransport();
1084 1084
 		
1085
-		// read the contents of the URL using our configured Http Transport and default timeout
1086
-		$httpResponse = $httpTransport->performGetRequest($url);
1085
+        // read the contents of the URL using our configured Http Transport and default timeout
1086
+        $httpResponse = $httpTransport->performGetRequest($url);
1087 1087
 		
1088
-		// check that its a 200 response
1089
-		if ($httpResponse->getStatusCode() == 200)
1090
-		{
1091
-			// add the resource.name parameter if not specified
1092
-			if (!isset($params['resource.name']))
1093
-			{
1094
-				$params['resource.name'] = $url;
1095
-			}
1096
-
1097
-			// delegate the rest to extractFromString
1098
-			return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype);
1099
-		}
1100
-		else
1101
-		{
1102
-			throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
1103
-		}
1104
-	}
1105
-
1106
-	/**
1107
-	 * Send an optimize command.  Will be synchronous unless both wait parameters are set
1108
-	 * to false.
1109
-	 *
1110
-	 * @param boolean $waitFlush
1111
-	 * @param boolean $waitSearcher
1112
-	 * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
1113
-	 * @return Apache_Solr_Response
1114
-	 *
1115
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1116
-	 */
1117
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
1118
-	{
1119
-		$flushValue = $waitFlush ? 'true' : 'false';
1120
-		$searcherValue = $waitSearcher ? 'true' : 'false';
1121
-
1122
-		$rawPost = '<optimize waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
1123
-
1124
-		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
1125
-	}
1126
-
1127
-	/**
1128
-	 * Simple Search interface
1129
-	 *
1130
-	 * @param string $query The raw query string
1131
-	 * @param int $offset The starting offset for result documents
1132
-	 * @param int $limit The maximum number of result documents to return
1133
-	 * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
1134
-	 * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
1135
-	 * @return Apache_Solr_Response
1136
-	 *
1137
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1138
-	 * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
1139
-	 */
1140
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
1141
-	{
1142
-		// ensure params is an array
1143
-		if (!is_null($params))
1144
-		{
1145
-			if (!is_array($params))
1146
-			{
1147
-				// params was specified but was not an array - invalid
1148
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1149
-			}
1150
-		}
1151
-		else
1152
-		{
1153
-			$params = array();
1154
-		}
1088
+        // check that its a 200 response
1089
+        if ($httpResponse->getStatusCode() == 200)
1090
+        {
1091
+            // add the resource.name parameter if not specified
1092
+            if (!isset($params['resource.name']))
1093
+            {
1094
+                $params['resource.name'] = $url;
1095
+            }
1096
+
1097
+            // delegate the rest to extractFromString
1098
+            return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype);
1099
+        }
1100
+        else
1101
+        {
1102
+            throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
1103
+        }
1104
+    }
1105
+
1106
+    /**
1107
+     * Send an optimize command.  Will be synchronous unless both wait parameters are set
1108
+     * to false.
1109
+     *
1110
+     * @param boolean $waitFlush
1111
+     * @param boolean $waitSearcher
1112
+     * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
1113
+     * @return Apache_Solr_Response
1114
+     *
1115
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1116
+     */
1117
+    public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
1118
+    {
1119
+        $flushValue = $waitFlush ? 'true' : 'false';
1120
+        $searcherValue = $waitSearcher ? 'true' : 'false';
1121
+
1122
+        $rawPost = '<optimize waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
1123
+
1124
+        return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
1125
+    }
1126
+
1127
+    /**
1128
+     * Simple Search interface
1129
+     *
1130
+     * @param string $query The raw query string
1131
+     * @param int $offset The starting offset for result documents
1132
+     * @param int $limit The maximum number of result documents to return
1133
+     * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
1134
+     * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
1135
+     * @return Apache_Solr_Response
1136
+     *
1137
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1138
+     * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
1139
+     */
1140
+    public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
1141
+    {
1142
+        // ensure params is an array
1143
+        if (!is_null($params))
1144
+        {
1145
+            if (!is_array($params))
1146
+            {
1147
+                // params was specified but was not an array - invalid
1148
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1149
+            }
1150
+        }
1151
+        else
1152
+        {
1153
+            $params = array();
1154
+        }
1155 1155
 		
1156
-		// construct our full parameters
1157
-
1158
-		// common parameters in this interface
1159
-		$params['wt'] = self::SOLR_WRITER;
1160
-		$params['json.nl'] = $this->_namedListTreatment;
1161
-
1162
-		$params['q'] = $query;
1163
-		$params['start'] = $offset;
1164
-		$params['rows'] = $limit;
1165
-
1166
-		$queryString = $this->_generateQueryString($params);
1167
-
1168
-		if ($method == self::METHOD_GET)
1169
-		{
1170
-			return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
1171
-		}
1172
-		else if ($method == self::METHOD_POST)
1173
-		{
1174
-			return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
1175
-		}
1176
-		else
1177
-		{
1178
-			throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
1179
-		}
1180
-	}
1156
+        // construct our full parameters
1157
+
1158
+        // common parameters in this interface
1159
+        $params['wt'] = self::SOLR_WRITER;
1160
+        $params['json.nl'] = $this->_namedListTreatment;
1161
+
1162
+        $params['q'] = $query;
1163
+        $params['start'] = $offset;
1164
+        $params['rows'] = $limit;
1165
+
1166
+        $queryString = $this->_generateQueryString($params);
1167
+
1168
+        if ($method == self::METHOD_GET)
1169
+        {
1170
+            return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
1171
+        }
1172
+        else if ($method == self::METHOD_POST)
1173
+        {
1174
+            return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
1175
+        }
1176
+        else
1177
+        {
1178
+            throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
1179
+        }
1180
+    }
1181 1181
 }
1182 1182
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/HttpTransportException.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -38,42 +38,42 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_HttpTransportException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 
51
-	/**
52
-	 * Response for which exception was generated
53
-	 *
54
-	 * @var Apache_Solr_Response
55
-	 */
56
-	private $_response;
51
+    /**
52
+     * Response for which exception was generated
53
+     *
54
+     * @var Apache_Solr_Response
55
+     */
56
+    private $_response;
57 57
 
58
-	/**
59
-	 * HttpTransportException Constructor
60
-	 *
61
-	 * @param Apache_Solr_Response $response
62
-	 */
63
-	public function __construct(Apache_Solr_Response $response)
64
-	{
65
-		parent::__construct("'{$response->getHttpStatus()}' Status: {$response->getHttpStatusMessage()}", $response->getHttpStatus());
58
+    /**
59
+     * HttpTransportException Constructor
60
+     *
61
+     * @param Apache_Solr_Response $response
62
+     */
63
+    public function __construct(Apache_Solr_Response $response)
64
+    {
65
+        parent::__construct("'{$response->getHttpStatus()}' Status: {$response->getHttpStatusMessage()}", $response->getHttpStatus());
66 66
 
67
-		$this->_response = $response;
68
-	}
67
+        $this->_response = $response;
68
+    }
69 69
 
70
-	/**
71
-	 * Get the response for which this exception was generated
72
-	 *
73
-	 * @return Apache_Solr_Response
74
-	 */
75
-	public function getResponse()
76
-	{
77
-		return $this->_response;
78
-	}
70
+    /**
71
+     * Get the response for which this exception was generated
72
+     *
73
+     * @return Apache_Solr_Response
74
+     */
75
+    public function getResponse()
76
+    {
77
+        return $this->_response;
78
+    }
79 79
 }
80 80
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Exception.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_Exception extends Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.