Project

General

Profile

« Previous | Next » 

Revision 6eaec849

Added by Katja Luther almost 5 years ago

implement blast search table for the result

View differences:

modules/cdm_dataportal/cdm_dataportal.search.php
165 165
 * @return array
166 166
 *   the form array
167 167
 */
168
function cdm_dataportal_search_taxon_form($form, &$form_state, $advanced_form = FALSE, $classification_select = TRUE) {
168
function cdm_dataportal_search_taxon_form($form, &$form_state, $advanced_form = FALSE, $classification_select = TRUE)
169
{
169 170

  
170
  $query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
171
    if ($form_state['build_info']['form_id'] == 'cdm_dataportal_search_blast_form') {
172
        $form = cdm_dataportal_search_blast_form($form, $form_state);
173
    } else {
171 174

  
172
  if ($advanced_form || variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, FALSE)) {
173
    $search_service_endpoint = CDM_WS_PORTAL_TAXON_SEARCH;
174
  }
175
  else {
176
    $search_service_endpoint = CDM_WS_PORTAL_TAXON_FIND;
177
  }
178 175

  
179
  $form = cdm_dataportal_search_form_prepare(
180
    'cdm_dataportal/search/results/taxon',
181
    $search_service_endpoint,
182
    $query_field_default_value,
183
    t('Enter the name or part of a name you wish to search for.
184
      The asterisk  character * can be used as wildcard, but must not be used as first character.')
185
  );
176
        $query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
186 177

  
178
        if ($advanced_form || variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, FALSE)) {
179
            $search_service_endpoint = CDM_WS_PORTAL_TAXON_SEARCH;
180
        } else {
181
            $search_service_endpoint = CDM_WS_PORTAL_TAXON_FIND;
182
        }
183

  
184
        $form = cdm_dataportal_search_form_prepare(
185
            'cdm_dataportal/search/results/taxon',
186
            $search_service_endpoint,
187
            $query_field_default_value,
188
            t('Enter the name or part of a name you wish to search for.
189
          The asterisk  character * can be used as wildcard, but must not be used as first character.')
190
        );
191
    }
187 192
  if (!$advanced_form) {
188 193
    $form['query']['#size'] = 20;
189 194
  }
......
385 390
  return $form;
386 391
}
387 392

  
393
/**
394
 * Creates a search form for searching on taxa.
395
 *
396
 * If advanced $advanced_form id TRUE the form will offer additional choices
397
 *
398
 * @param array $form
399
 *   A drupal form array
400
 * @param array $form_state
401
 *   The drupal form state passed as reference
402
 * @param bool $advanced_form
403
 *   default is FALSE
404
 * @param bool $classification_select
405
 *   set TRUE to offer a classification selector in the form - default is FALSE
406
 *   if only available in the advanced mode
407
 *
408
 * @return array
409
 *   the form array
410
 */
411
function cdm_dataportal_search_blast_form($form, &$form_state) {
412

  
413
    $query_field_default_value = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
414

  
415
    $search_service_endpoint = CDM_WS_PORTAL_BLAST;
416

  
417

  
418
    $form = cdm_dataportal_search_blast_form_prepare(
419
        'cdm_dataportal/search/results/specimen',
420
        $search_service_endpoint,
421
        $query_field_default_value,
422
        t('Enter the sequence or part of a sequence you wish to search for.')
423
    );
424

  
425

  
426

  
427
    $form['search']['pageSize'] = array(
428
        '#weight' => -1,
429
        '#type' => 'hidden',
430
        '#value' => variable_get('cdm_dataportal_search_items_on_page', 25),
431
    );
432

  
433
    $form['search']['pageNumber'] = array(
434
        '#weight' => -1,
435
        '#type' => 'hidden',
436
        '#value' => 0,
437
    );
438

  
439

  
440

  
441

  
442

  
443
    return $form;
444
}
445

  
446
/**
447
 * Prepares a form array for a general purpose search form.
448
 *
449
 * The form is used for general purpose search functionality in the
450
 * dataportal. The form returned is populated with all necessary fields
451
 * for internal processing and has the textfield element $form['query']
452
 * which holds the query term.
453
 *
454
 * @param string $action_path
455
 *   The Drupal path to be put into the action url to which the form will
456
 *   be submitted.
457
 * @param string $search_webservice
458
 *   The cdm-remote webservice to be used, valid values are defined by
459
 *   the constants: FIXME.
460
 * @param string $query_field_default_value
461
 *   A default text for the query field
462
 * @param string $query_field_description
463
 *   The description text for the query field
464
 * @param string $process
465
 *   The value for #process, if NULL (default), 'cdm_dataportal_search_process'
466
 *   is used.
467
 *
468
 * @return array
469
 *   The prepared form array.
470
 */
471
function cdm_dataportal_search_blast_form_prepare($action_path, $search_webservice, $query_field_default_value, $query_field_description, $process = NULL) {
472

  
473
    if ($process == NULL) {
474
        $process = 'cdm_dataportal_search_process';
475
    }
476

  
477
    $form['#method'] = 'get';
478
    //
479
    //  $form['#process'] = array(
480
    //  $process => array(),
481
    //  );
482
    //
483
    $form['#action'] = url($action_path, array(
484
        'absolute' => TRUE,
485
    ));
486

  
487
    $form['ws'] = array(
488
        '#type' => 'hidden',
489
        '#value' => $search_webservice,
490
        '#name' => 'ws',
491
    );
492

  
493
    $form['query'] = array(
494
        '#weight' => 0,
495
        '#type' => 'textarea',
496
        '#size' => 68,
497
        // This causes the description to display also when hovering over
498
        // the textfield.
499
        // This is wanted behaviour for the simple seach but could
500
        // be disabled for the advances search.
501
        '#attributes' => array(
502
            'title' => $query_field_description,
503
        ),
504
        '#description' => $query_field_description,
505
       // '#value' => $query_field_default_value,
506
        // '#description' => $query_field_description,
507
    );
508

  
509

  
510
    $form['search'] = array(
511
        '#weight' => 3,
512
        '#tree' => TRUE,
513
        // '#type' => $advanced_form ? 'fieldset': 'hidden',
514
        '#title' => t('Options'),
515
    );
516

  
517
    // Clean URL get forms breaks if we don't give it a 'q'.
518
    if (!(bool) variable_get('clean_url', '0')) {
519
        $form['search']['q'] = array(
520
            '#type' => 'hidden',
521
            '#value' => $action_path,
522
            '#name' => 'q',
523
        );
524
    }
525

  
526
    $form['search']['word_size'] = array(
527
        '#weight' => 1,
528
        '#type' => 'textfield',
529
        '#title' => t('Word size'),
530
        '#default_value' => 7,
531
        '#description' => t('Length of initial exact match'),
532
    );
533

  
534
    $form['search']['reward'] = array(
535
        '#weight' => 2,
536
        '#type' => 'textfield',
537
        '#title' => t('Reward'),
538
        '#default_value' => 1,
539
        '#description' => t('Reward for Matching'),
540
    );
541

  
542
    $form['search']['penalty'] = array(
543
        '#weight' => 3,
544
        '#type' => 'textfield',
545
        '#title' => t('Penalty'),
546
        '#default_value' => -2,
547
        '#description' => t('Penalty for mismatching'),
548
    );
549

  
550
    $form['search']['gap_open'] = array(
551
        '#weight' => 4,
552
        '#type' => 'textfield',
553
        '#title' => t('Gap open'),
554
        '#default_value' => 5,
555
        '#description' => t('Cost to open a gap'),
556
    );
557

  
558
    $form['search']['gap_extend'] = array(
559
        '#weight' => 5,
560
        '#type' => 'textfield',
561
        '#title' => t('Gap extend'),
562
        '#default_value' => -2,
563
        '#description' => t('Cost for extend a gap'),
564
    );
565

  
566
    $form['submit'] = array(
567
        '#weight' => 5,
568
        '#type' => 'submit',
569
        '#name' => '',
570
        '#value' => t('Search'),
571
    );
572

  
573
    return $form;
574
}
388 575
/**
389 576
 * Wrapper function for cdm_dataportal_search_taxon_form().
390 577
 *
......
581 768
  return $form_params;
582 769
}
583 770

  
771
/**
772
 * Processes the query parameters of the blast search form.
773
 *
774
 * Reads the query parameters from $_REQUEST and modifies and adds additional
775
 * query parameters if necessary.
776
 *
777
 *  - Filters $_REQUEST by a list of valid request parameters
778
 *
779
 *
780
 * @param $search_endpoint string
781
 *    The web service endpoint which will be used for executing the search.
782
 *
783
 * @return array
784
 *   the processed request parameters submitted by the search form and
785
 *   also stores them in $_SESSION['cdm']['search']
786
 */
787
function cdm_dataportal_blast_search_request($search_endpoint)
788
{
789

  
790
    $form_params = array();
791

  
792
    if (isset($_REQUEST['search']) && is_array($_REQUEST['search'])) {
793
        array_deep_copy($_REQUEST['search'], $form_params['data']);
794
    }
795

  
796

  
797
    //$query = trim($_REQUEST['query']);
798
    $form_params['data'] = formatParams($_REQUEST['search']);
799

  
800
    /*if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
801
        $form_params = array_merge($form_params, $_REQUEST['pager']);
802
    }*/
803

  
804
    $form_params['query']= trim($_REQUEST['query']);
805

  
806

  
807
    // Store in session.
808
    $_SESSION['cdm']['search'] = $form_params;
809

  
810
    return $form_params;
811
}
812

  
813

  
814

  
584 815
/**
585 816
 * Provides the classification to which the last search has been limited to..
586 817
 *
......
669 900
  return $taxon_pager;
670 901
}
671 902

  
903
/**
904
 * Sends a search request to the cdm server.
905
 *
906
 * The parameters to build the query are taken obtained by calling
907
 * cdm_dataportal_search_request() which reads the query parameters
908
 * from $_REQUEST and add additional query parameters if nessecary.
909
 *
910
 * @see cdm_dataportal_search_request()
911
 */
912
function cdm_dataportal_search_blast_execute() {
913

  
914
    // Store as last search in session.
915
    $_SESSION['cdm']['last_blast_search'] = $_SERVER['REQUEST_URI'];
916

  
917
    // Validate the search webservice parameter:
918
    if (!isset($_REQUEST['ws'])) {
919
        drupal_set_message(
920
            t("Invalid search, webservice parameter 'ws' is missing"), 'warning'
921
        );
922
        return NULL;
923
    }
924
//    if (!cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
925
//        // Endpoint is unknown.
926
//        drupal_set_message(
927
//            t("Invalid search webservice parameter 'ws' given"), 'warning'
928
//        );
929
//        return NULL;
930
//    }
931

  
932
    // Read the query parameters from $_REQUEST and add additional query
933
    // parameters if necessary.
934
    $request_params = cdm_dataportal_blast_search_request($_REQUEST['ws']);
935
   // $url = drupal_http_build_query($_REQUEST['ws'], $request_params);
936

  
937
    $taxon_pager = drupal_http_request($_REQUEST['ws'].'?sequence='.$request_params['query'], $request_params);
938

  
939
    return $taxon_pager;
940
}
941

  
942

  
672 943

  
673 944
/**
674 945
 * Sends a request for a registrations filter search to the cdm server.

Also available in: Unified diff