forked from Fyb3roptik/php-pecl-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_solr_input_document.c
executable file
·744 lines (544 loc) · 20.9 KB
/
php_solr_input_document.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Israel Ekpo <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id: php_solr_input_document.c 289006 2009-09-30 15:19:31Z iekpo $ */
#include "php_solr.h"
/** ************************************************************************ **/
/** DEFINITIONS FOR SOLR INPUT DOCUMENT METHODS **/
/** ************************************************************************ **/
/* {{{ proto void SolrInputDocument::__construct()
SolrInputDocument constructor */
PHP_METHOD(SolrInputDocument, __construct)
{
zval *objptr = getThis();
uint nSize = SOLR_INITIAL_HASH_TABLE_SIZE;
ulong document_index = SOLR_UNIQUE_DOCUMENT_INDEX();
auto solr_document_t solr_doc;
solr_document_t *doc_entry = NULL, *doc_ptr = NULL;
memset(&solr_doc, 0, sizeof(solr_document_t));
doc_entry = &solr_doc;
doc_entry->document_index = document_index;
doc_entry->field_count = 0L;
doc_entry->document_boost = 0.0f;
/* Allocated memory for the fields HashTable using fast cache for HashTables */
ALLOC_HASHTABLE(doc_entry->fields);
/* Initializing the hash table used for storing fields in this SolrDocument */
zend_hash_init(doc_entry->fields, nSize, NULL, (dtor_func_t) solr_destroy_field_list, SOLR_DOCUMENT_FIELD_PERSISTENT);
/* Let's check one more time before insert into the HashTable */
if (zend_hash_index_exists(SOLR_GLOBAL(documents), document_index)) {
pefree(doc_entry->fields, SOLR_DOCUMENT_FIELD_PERSISTENT);
return;
}
/* Add the document entry to the directory of documents */
zend_hash_index_update(SOLR_GLOBAL(documents), document_index, (void *) doc_entry, sizeof(solr_document_t), (void **) &doc_ptr);
/* Set the value of the internal id property */
zend_update_property_long(solr_ce_SolrInputDocument, objptr, SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME) - 1, document_index TSRMLS_CC);
/* Keep track of how many SolrDocument instances we currently have */
SOLR_GLOBAL(document_count)++;
/* Overriding the default object handlers */
Z_OBJ_HT_P(objptr) = &solr_input_document_object_handlers;
}
/* }}} */
/* {{{ proto void SolrInputDocument::__destruct(void)
Destructor for SolrInputDocument */
PHP_METHOD(SolrInputDocument, __destruct)
{
solr_document_t *doc_entry = NULL;
/* Retrieve the document entry for this SolrDocument */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
zend_hash_index_del(SOLR_GLOBAL(documents), doc_entry->document_index);
/* Keep track of how many SolrDocument instances we currently have */
SOLR_GLOBAL(document_count)--;
return ;
}
}
/* }}} */
/* {{{ proto void SolrInputDocument::__clone(void)
Clones the current object. Not to be called directly. */
PHP_METHOD(SolrInputDocument, __clone)
{
zval *objptr = getThis();
solr_document_t new_solr_doc;
solr_document_t *new_doc_entry = NULL, *old_doc_entry = NULL;
ulong document_index = SOLR_UNIQUE_DOCUMENT_INDEX();
memset(&new_solr_doc, 0, sizeof(solr_document_t));
new_doc_entry = &new_solr_doc;
/* Retrieve the document entry for the original SolrDocument */
if (solr_fetch_document_entry(objptr, &old_doc_entry TSRMLS_CC) == FAILURE) {
return ;
}
/* Duplicate the doc_entry contents */
memcpy(new_doc_entry, old_doc_entry, sizeof(solr_document_t));
/* Override the document index with a new one and create a new HashTable */
new_doc_entry->document_index = document_index;
/* Allocate new memory for the fields HashTable, using fast cache for HashTables */
ALLOC_HASHTABLE(new_doc_entry->fields);
/* Initializing the hash table used for storing fields in this SolrDocument */
zend_hash_init(new_doc_entry->fields, old_doc_entry->fields->nTableSize, NULL, (dtor_func_t) solr_destroy_field_list, SOLR_DOCUMENT_FIELD_PERSISTENT);
/* Copy the contents of the old fields HashTable to the new SolrDocument */
zend_hash_copy(new_doc_entry->fields, old_doc_entry->fields, (copy_ctor_func_t) field_copy_constructor, NULL, sizeof(solr_field_list_t *));
/* Add the document entry to the directory of documents */
zend_hash_index_update(SOLR_GLOBAL(documents), document_index, (void *) new_doc_entry, sizeof(solr_document_t), NULL);
/* Set the value of the internal id property */
zend_update_property_long(solr_ce_SolrInputDocument, objptr, SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME) - 1, document_index TSRMLS_CC);
/* Keep track of how many SolrDocument instances we currently have */
SOLR_GLOBAL(document_count)++;
}
/* }}} */
/* {{{ proto void SolrInputDocument::__sleep(void)
Should not be called directly. Serialization is not supported. */
PHP_METHOD(SolrInputDocument, __sleep)
{
solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1005 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1005_MSG);
}
/* }}} */
/* {{{ proto void SolrInputDocument::__wakeup(void)
Should not be called directly. Serialization is not supported. */
PHP_METHOD(SolrInputDocument, __wakeup)
{
solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1005 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1005_MSG);
}
/* }}} */
/* {{{ proto bool SolrInputDocument::setBoost(float document_boost)
Sets the boost for the document. */
PHP_METHOD(SolrInputDocument, setBoost)
{
double boost_value = 0.0f;
solr_document_t *doc_entry = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &boost_value) == FAILURE) {
RETURN_FALSE;
}
/* If the submitted boost_value is negative. */
if (boost_value < 0.0) {
RETURN_FALSE;
}
/* Retrieve the document entry for this SolrDocument */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
doc_entry->document_boost = boost_value;
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto float SolrInputDocument::getBoost(void)
Retrieves the boost for the document. */
PHP_METHOD(SolrInputDocument, getBoost)
{
solr_document_t *doc_entry = NULL;
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
RETURN_DOUBLE(doc_entry->document_boost);
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::clear(void)
Discards all the fields and resets the document boost to zero. */
PHP_METHOD(SolrInputDocument, clear)
{
solr_document_t *doc_entry = NULL;
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
doc_entry->document_boost = 0.0;
doc_entry->field_count = 0L;
zend_hash_clean(doc_entry->fields);
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::addField(string field_name, field_value [, float field_boost])
Adds a field to the document. Can be called multiple times. */
PHP_METHOD(SolrInputDocument, addField)
{
solr_char_t *field_name = NULL;
int field_name_length = 0;
solr_char_t *field_value = NULL;
int field_value_length = 0;
double field_boost = 0.0f;
solr_document_t *doc_entry = NULL;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|d", &field_name,
&field_name_length, &field_value,
&field_value_length, &field_boost) == FAILURE) {
RETURN_FALSE;
}
if (!field_name_length) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
{
solr_field_list_t **field_values_ptr = NULL;
solr_field_list_t *field_values = NULL;
/* If the field already exists in the SolrDocument instance append the value to the field list queue */
if (zend_hash_find(doc_entry->fields, field_name, field_name_length, (void **) &field_values_ptr) == SUCCESS) {
if (solr_document_insert_field_value(*field_values_ptr, field_value, field_boost) == FAILURE) {
RETURN_FALSE;
}
} else {
/* Otherwise, create a new one and add it to the hash table */
field_values = (solr_field_list_t *) pemalloc(sizeof(solr_field_list_t), SOLR_DOCUMENT_FIELD_PERSISTENT);
memset(field_values, 0, sizeof(solr_field_list_t));
field_values_ptr = &field_values;
field_values->count = 0L;
field_values->field_boost = 0.0;
field_values->field_name = (solr_char_t *) pestrdup(field_name,SOLR_DOCUMENT_FIELD_PERSISTENT);
field_values->head = NULL;
field_values->last = NULL;
if (solr_document_insert_field_value(field_values, field_value, field_boost) == FAILURE) {
solr_destroy_field_list(&field_values);
RETURN_FALSE;
}
if (zend_hash_add(doc_entry->fields, field_name, field_name_length, (void *) field_values_ptr, sizeof(solr_field_list_t *), (void **) NULL) == FAILURE) {
solr_destroy_field_list(&field_values);
RETURN_FALSE;
}
/* Increment field count only when HEAD is added */
doc_entry->field_count++;
}
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::setFieldBoost(string fieldname, float boost_value)
Sets the boost for the specified field. */
PHP_METHOD(SolrInputDocument, setFieldBoost)
{
solr_char_t *field_name = NULL;
int field_name_length = 0;
double field_boost = 0.0;
solr_document_t *doc_entry = NULL;
/* Process the parameters passed to the default constructor */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &field_name, &field_name_length, &field_boost) == FAILURE) {
RETURN_FALSE;
}
if (!field_name_length) {
RETURN_FALSE;
}
if (field_boost < 0.0) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
solr_field_list_t **field_values = NULL;
/* If the field already exists in the SolrDocument instance append the value to the field list queue */
if (zend_hash_find(doc_entry->fields, (char *) field_name, field_name_length, (void **) &field_values) == SUCCESS) {
(*field_values)->field_boost = field_boost;
RETURN_TRUE;
}
RETURN_FALSE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto float SolrInputDocument::getFieldBoost(string fieldname)
Returns the boost value for the specified field. */
PHP_METHOD(SolrInputDocument, getFieldBoost)
{
solr_char_t *field_name = NULL;
int field_name_length = 0;
solr_document_t *doc_entry = NULL;
/* Process the parameters passed to the default constructor */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &field_name, &field_name_length) == FAILURE) {
RETURN_FALSE;
}
if (!field_name_length) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
solr_field_list_t **field_values = NULL;
if (zend_hash_find(doc_entry->fields, (char *) field_name, field_name_length, (void **) &field_values) == SUCCESS) {
RETURN_DOUBLE((*field_values)->field_boost);
}
RETURN_FALSE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto array SolrInputDocument::getFieldNames(void)
Returns an array of all the field names in the document. */
PHP_METHOD(SolrInputDocument, getFieldNames)
{
solr_document_t *doc_entry = NULL;
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
{
HashTable *fields_ht = doc_entry->fields;
register zend_bool duplicate = 0;
array_init(return_value);
SOLR_HASHTABLE_FOR_LOOP(fields_ht)
{
char *fieldname = NULL;
uint fieldname_length = 0U;
ulong num_index = 0L;
solr_field_list_t **field = NULL;
zend_bool duplicate_field_name = 1;
zend_hash_get_current_key_ex(fields_ht, &fieldname, &fieldname_length, &num_index, duplicate, NULL);
zend_hash_get_current_data_ex(fields_ht, (void **) &field, NULL);
add_next_index_string(return_value, (char *) (*field)->field_name, duplicate_field_name);
}
/* We are done */
return;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto int SolrInputDocument::getFieldCount(void)
Returns the number of fields in document. Multivalued fields are only counted once. */
PHP_METHOD(SolrInputDocument, getFieldCount)
{
solr_document_t *doc_entry = NULL;
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
{
RETURN_LONG(zend_hash_num_elements(doc_entry->fields));
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto SolrDocumentField SolrInputDocument::getField(string fieldname)
Returns the requested field. */
PHP_METHOD(SolrInputDocument, getField)
{
solr_char_t *field_name = NULL;
int field_name_length = 0;
solr_document_t *doc_entry = NULL;
/* Process the parameters passed to the default constructor */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &field_name, &field_name_length) == FAILURE) {
RETURN_FALSE;
}
if (!field_name_length) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
{
solr_field_list_t **field_values = NULL;
if (zend_hash_find(doc_entry->fields, (char *)field_name, field_name_length, (void **) &field_values) == SUCCESS)
{
solr_create_document_field_object(*field_values, &return_value TSRMLS_CC);
/* The field was retrieved, so we're done here */
return ;
}
RETURN_FALSE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto array SolrInputDocument::toArray(void)
Returns an array representation of the object. */
PHP_METHOD(SolrInputDocument, toArray)
{
solr_document_t *doc_entry = NULL;
zval *fields_array = NULL;
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
{
register zend_bool duplicate = 0;
HashTable *fields_ht;
MAKE_STD_ZVAL(fields_array);
array_init(return_value);
array_init(fields_array);
add_assoc_double(return_value, "document_boost", doc_entry->document_boost);
add_assoc_long(return_value, "field_count", doc_entry->field_count);
add_assoc_zval(return_value, "fields", fields_array);
fields_ht = doc_entry->fields;
SOLR_HASHTABLE_FOR_LOOP(fields_ht)
{
solr_char_t *fieldname = NULL;
uint fieldname_length = 0U;
ulong num_index = 0L;
solr_field_list_t **field = NULL;
zval *current_field = NULL;
MAKE_STD_ZVAL(current_field);
zend_hash_get_current_key_ex(fields_ht, (char **) &fieldname, &fieldname_length, &num_index, duplicate, NULL);
zend_hash_get_current_data_ex(fields_ht, (void **) &field, NULL);
solr_create_document_field_object(*field, ¤t_field TSRMLS_CC);
add_next_index_zval(fields_array, current_field);
}
/* We are done */
return;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::fieldExists(string field_name)
Checks if the field name exists in the document. */
PHP_METHOD(SolrInputDocument, fieldExists)
{
solr_char_t *field_name = NULL;
int field_name_length = 0;
solr_document_t *doc_entry = NULL;
/* Process the parameters passed to the default constructor */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &field_name, &field_name_length) == FAILURE) {
RETURN_FALSE;
}
if (!field_name_length) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
if (zend_hash_exists(doc_entry->fields, (char *) field_name, field_name_length)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::deleteField(string field_name)
Removes the request field from the document. */
PHP_METHOD(SolrInputDocument, deleteField)
{
solr_char_t *field_name = NULL;
int field_name_length = 0;
solr_document_t *doc_entry = NULL;
/* Process the parameters passed to the default constructor */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &field_name, &field_name_length) == FAILURE) {
RETURN_FALSE;
}
if (!field_name_length) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) {
if (zend_hash_del(doc_entry->fields, (char *) field_name, field_name_length) == SUCCESS) {
doc_entry->field_count--;
RETURN_TRUE;
}
RETURN_FALSE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::sort(int sort_criterion [, int sort_direction])
Sorts the document fields by the specified criterion. */
PHP_METHOD(SolrInputDocument, sort)
{
long int order_by = 0L;
long int sort_direction = SOLR_SORT_ASC;
solr_document_t *doc_entry = NULL;
int renumber = 0;
/* The pointer to the comparison function used by zend_qsort */
compare_func_t comparison_function = (compare_func_t) NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &order_by, &sort_direction) == FAILURE) {
RETURN_FALSE;
}
/* Retrieve the document entry for the SolrDocument instance */
if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
/* {{{ Select the appropriate comparison function */
switch(order_by)
{
case SOLR_SORT_FIELD_NAME : /* Sorting by field name */
{
switch(sort_direction)
{
case SOLR_SORT_ASC :
comparison_function = solr_compare_field_name;
break;
case SOLR_SORT_DESC :
comparison_function = solr_rcompare_field_name;
break;
}
}
break; /* case SOLR_SORT_FIELD_NAME */
case SOLR_SORT_FIELD_VALUE_COUNT : /* Sorting by number of values per field */
{
switch(sort_direction)
{
case SOLR_SORT_ASC :
comparison_function = solr_compare_field_value_count;
break;
case SOLR_SORT_DESC :
comparison_function = solr_rcompare_field_value_count;
break;
}
}
break; /* case SOLR_SORT_FIELD_VALUE_COUNT */
case SOLR_SORT_FIELD_BOOST_VALUE : /* Sorting by field boost values */
{
switch(sort_direction)
{
case SOLR_SORT_ASC :
comparison_function = solr_compare_field_boost_value;
break;
case SOLR_SORT_DESC :
comparison_function = solr_rcompare_field_boost_value;
break;
}
}
break; /* case SOLR_SORT_FIELD_BOOST_VALUE */
default : /* Undefined sort criteria */
RETURN_FALSE;
break;
} /* }}} switch(order_by) */
/* Undefined sort direction. It was not ASC or DESC */
if (!comparison_function) {
RETURN_FALSE;
}
if (zend_hash_sort(doc_entry->fields, zend_qsort, comparison_function, renumber TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool SolrInputDocument::merge(SolrInputDocument source [, bool override])
Merges the source document to the current object. */
PHP_METHOD(SolrInputDocument, merge)
{
solr_document_t *destination_document = NULL;
solr_document_t *source_document = NULL;
/* The destination SolrDocument instance */
zval * destination_document_zval = getThis();
/* The source SolrDocument instance */
zval *source_document_zval = NULL;
/* Should we skip fields that already exist in destination */
zend_bool overwrite = (zend_bool) 0;
copy_ctor_func_t p_copy_ctor = (copy_ctor_func_t) field_copy_constructor;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &source_document_zval, solr_ce_SolrInputDocument, &overwrite) == FAILURE) {
RETURN_FALSE;
}
if (solr_fetch_document_entry(source_document_zval, &source_document TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (solr_fetch_document_entry(destination_document_zval, &destination_document TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (zend_hash_num_elements(source_document->fields) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Source SolrInputDocument has no fields. Source documentId");
RETURN_FALSE;
}
/* Copy the fields in the source HashTable to the destination HashTable */
zend_hash_merge(destination_document->fields, source_document->fields, p_copy_ctor, NULL, sizeof(solr_field_list_t *), (int) overwrite);
/* Update the field count */
destination_document->field_count = (uint) zend_hash_num_elements(destination_document->fields);
RETURN_TRUE;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
* vim600: fdm=marker
* vim: noet sw=4 ts=4
*/