@@ 422-463 (lines=42) @@ | ||
419 | /** |
|
420 | * Recursively parse Search API filters. |
|
421 | */ |
|
422 | protected function parseFilter(SearchApiQueryFilter $query_filter, $index_fields, $ignored_field_id = '') { |
|
423 | if (empty($query_filter)) { |
|
424 | return NULL; |
|
425 | } |
|
426 | else { |
|
427 | $conjunction = $query_filter->getConjunction(); |
|
428 | ||
429 | $filters = array(); |
|
430 | ||
431 | try { |
|
432 | foreach ($query_filter->getFilters() as $filter_info) { |
|
433 | $filter = NULL; |
|
434 | ||
435 | // Simple filter [field_id, value, operator]. |
|
436 | if (is_array($filter_info)) { |
|
437 | $filter_assoc = $this->getAssociativeFilter($filter_info); |
|
438 | $this->correctFilter($filter_assoc, $index_fields, $ignored_field_id); |
|
439 | // Check field. |
|
440 | $filter = $this->getFilter($filter_assoc); |
|
441 | ||
442 | if (!empty($filter)) { |
|
443 | $filters[] = $filter; |
|
444 | } |
|
445 | } |
|
446 | // Nested filters. |
|
447 | elseif ($filter_info instanceof SearchApiQueryFilter) { |
|
448 | $nested_filters = $this->parseFilter($filter_info, $index_fields, $ignored_field_id); |
|
449 | if (!empty($nested_filters)) { |
|
450 | $filters = array_merge($filters, $nested_filters); |
|
451 | } |
|
452 | } |
|
453 | } |
|
454 | $filters = $this->setFiltersConjunction($filters, $conjunction); |
|
455 | } |
|
456 | catch (Exception $e) { |
|
457 | watchdog('Elasticsearch', check_plain($e->getMessage()), array(), WATCHDOG_ERROR); |
|
458 | drupal_set_message(check_plain($e->getMessage()), 'error'); |
|
459 | } |
|
460 | ||
461 | return $filters; |
|
462 | } |
|
463 | } |
|
464 | ||
465 | /** |
|
466 | * Get filter by associative array. |
@@ 819-862 (lines=44) @@ | ||
816 | /** |
|
817 | * Helper function: Recursively parse Search API filters. |
|
818 | */ |
|
819 | protected function parseFilter(SearchApiQueryFilter $query_filter, $index_fields, $ignored_field_id = '') { |
|
820 | ||
821 | if (empty($query_filter)) { |
|
822 | return NULL; |
|
823 | } |
|
824 | else { |
|
825 | $conjunction = $query_filter->getConjunction(); |
|
826 | ||
827 | $filters = array(); |
|
828 | ||
829 | try { |
|
830 | foreach ($query_filter->getFilters() as $filter_info) { |
|
831 | $filter = NULL; |
|
832 | ||
833 | // Simple filter [field_id, value, operator]. |
|
834 | if (is_array($filter_info)) { |
|
835 | $filter_assoc = $this->getAssociativeFilter($filter_info); |
|
836 | $this->correctFilter($filter_assoc, $index_fields, $ignored_field_id); |
|
837 | // Check field. |
|
838 | $filter = $this->getFilter($filter_assoc); |
|
839 | ||
840 | if (!empty($filter)) { |
|
841 | $filters[] = $filter; |
|
842 | } |
|
843 | } |
|
844 | // Nested filters. |
|
845 | elseif ($filter_info instanceof SearchApiQueryFilter) { |
|
846 | $nested_filters = $this->parseFilter($filter_info, $index_fields, $ignored_field_id); |
|
847 | // TODO: handle error. - here is unnecessary cause in if we thow exceptions and this is still in try{} . |
|
848 | if (!empty($nested_filters)) { |
|
849 | $filters = array_merge($filters, $nested_filters); |
|
850 | } |
|
851 | } |
|
852 | } |
|
853 | $filters = $this->setFiltersConjunction($filters, $conjunction); |
|
854 | } |
|
855 | catch (Exception $e) { |
|
856 | watchdog('Elasticsearch', check_plain($e->getMessage()), array(), WATCHDOG_ERROR); |
|
857 | drupal_set_message(check_plain($e->getMessage()), 'error'); |
|
858 | } |
|
859 | ||
860 | return $filters; |
|
861 | } |
|
862 | } |
|
863 | ||
864 | /** |
|
865 | * Helper function that return associative array of filters info. |