You are here

function document_perform_search in Document 8.x

Same name and namespace in other branches
  1. 6 document.inc \document_perform_search()
  2. 7 document.inc \document_perform_search()
2 calls to document_perform_search()
document_search in ./document.callback.inc
document_search_form in ./document.search.inc

File

./document.inc, line 106

Code

function document_perform_search($searchFields, $searchText, $searchYear = NULL, $searchDocType = NULL) {
  $conditions = db_and();
  $conditions
    ->condition('n.status', DOCUMENT_STATUS_PUBLISHED);
  switch ($searchFields) {
    case 0:
      $conditions
        ->condition('author', '%' . $searchText . '%', 'LIKE');
      break;
    case 1:
      $conditions
        ->condition('keywords', '%' . $searchText . '%', 'LIKE');
      break;
    case 2:
      $or = db_or();
      $or
        ->condition('keywords', '%' . $searchText . '%', 'LIKE')
        ->condition('author', '%' . $searchText . '%', 'LIKE');
      $conditions
        ->condition($or);
      break;
    case 3:
      break;
    default:
      die('Invalid Input');
  }
  if (!empty($searchYear)) {
    $conditions
      ->condition('publish_year', $searchYear);
  }
  if (!empty($searchDocType) > 0) {
    $conditions
      ->condition('d.type', '%' . $searchDocType . '%', 'LIKE');
  }
  return document_search_table($conditions);
}