You are here

function SarniaSolrService::schemaApplyRules in Sarnia 7

1 call to SarniaSolrService::schemaApplyRules()
SarniaSolrService::getFilteredFields in ./service.inc

File

./service.inc, line 289

Class

SarniaSolrService
Search service class using Solr server.

Code

function schemaApplyRules(&$fields, $filter) {
  $result_fields = array();
  $all_fields = $this
    ->getRemoteFields();
  foreach ($fields as $name => $field) {
    $result_fields[$name] = $field;
    if ($rule = $this
      ->schemaGetRule($field, $filter)) {
      if ($rule->effect == 'disable') {

        // Don't allow fulltext/filter/display/sort on this field.
        unset($result_fields[$name]);
      }
      elseif ($rule->effect == 'replace' && isset($rule->replacement)) {

        // Use this field as the fulltext/filter/display/sort for another field.
        $replacement = NULL;
        if ($rule->match_type == 'name') {
          $replacement = $rule->replacement;
        }
        elseif ($rule->match_type == 'dynamicBase') {
          $replacement = str_replace(trim($rule->match_value, '*'), trim($rule->replacement, '*'), $name);
        }
        if ($replacement && is_object($all_fields[$replacement])) {
          $result_fields[$replacement] = $field;
          unset($result_fields[$name]);
        }
      }
    }
  }
  ksort($result_fields);
  $fields = $result_fields;
}