diff --git a/api/bootstrap.php b/api/bootstrap.php index eacec832..b0aca7a8 100644 --- a/api/bootstrap.php +++ b/api/bootstrap.php @@ -23,7 +23,6 @@ require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/build_search_forms_form.inc'; require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/link_results_to_pages_form.inc'; -require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/alter_search_forms_form.inc'; require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/delete_search_forms_form.inc'; require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/view_search_forms_form.inc'; -require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/sitewide_search_box_form.inc'; \ No newline at end of file +require_once drupal_get_path('module', 'tripal_elasticsearch') . '/includes/search/website_search_box_form.inc'; \ No newline at end of file diff --git a/includes/search/alter_search_forms_form.inc b/includes/search/alter_search_forms_form.inc deleted file mode 100644 index f663ca3a..00000000 --- a/includes/search/alter_search_forms_form.inc +++ /dev/null @@ -1,9 +0,0 @@ -make(); + $elastic_index = (new ElasticIndex($connection)); + $indices_options = $elastic_index->GetIndices(); + $form['indices'] = array( + '#type' => 'select', + '#title' => t('Select an index'), + '#options' => ['none' => 'Select an index'] + $indices_options, + '#ajax' => [ + 'callback' => 'display_form_fields_ajax', + 'wrapper' => 'display_form_fields' + ] + ); + + $index_name = !empty($form_state['values']['indices']) ? $form_state['values']['indices'] : 'Select an index'; + + $form['form_fields'] = [ + '#type' => 'fieldset', + '#title' => t('Form Fields'), + '#tree' => true, + '#prefix' => '
This page allows you to add dynamic URL to search results. '; + $description .= 'Here dynamic URL means that the URL dependens on the seach result values. '; + $description .= 'For example, the search form for organism has four fields: abbreviation, common_name, genus, species. '; + $description .= 'We want to link some search results to corresponding oranism pages. '; + $description .= 'Assuming that all organism pages have the same pattern: organism/genus/species '; + $description .= '(all URLs have the same part "organism/" but are different at "genus" and "species"),'; + $description .= 'and the different parts in URLs only depend on the values of search results, '; + $description .= 'in this case, we can link search results to their corresponding organism pages by adding dynamic links to the fields.
'; + $description .= 'A dynamic link is created by replacing variable values in URL with corresponding field names within "[]".
'; + $description .= 'The example below shows how to add links to search results in fields abbreviation and species.
'; + $form['add_links']['description'] = array( + '#type' => 'item', + '#markup' => $description, + ); + $form['add_links']['abbreviation'] = array( + '#type' => 'textfield', + '#title' => t('abbreviation'), + '#title_display' => 'after', + '#default_value' => t('organism/[genus]/[species]'), + ); + $form['add_links']['common_name'] = array( + '#type' => 'textfield', + '#title' => t('common_name'), + '#title_display' => 'after', + ); + $form['add_links']['genus'] = array( + '#type' => 'textfield', + '#title' => t('genus'), + '#title_display' => 'after', + ); + $form['add_links']['species'] = array( + '#type' => 'textfield', + '#title' => t('species'), + '#title_display' => 'after', + '#default_value' => t('organism/[genus]/[species]'), + ); return $form; } \ No newline at end of file diff --git a/includes/search/view_search_forms_form.inc b/includes/search/view_search_forms_form.inc index 4979a368..3703c6fa 100644 --- a/includes/search/view_search_forms_form.inc +++ b/includes/search/view_search_forms_form.inc @@ -68,52 +68,6 @@ function view_search_forms_form ($form, &$form_state, $table_name) { } -/* -function view_search_forms_form_submit ($form, &$form_state) { - - $connection = (new ElasticConnection(["127.0.0.1:9201"]))->make(); - $elastic_search = new ElasticSearch($connection); - - $table_name = $form_state['storage']['table_name']; - $index = preg_replace('/^chado./', 'chado_', $table_name); - $type = $table_name; - - foreach ($form_state['storage']['fields'] as $field) { - $field_content_pairs[$field] = $form_state['values'][$field]; - } - $query = $elastic_search->build_search_query_from_field_content_pairs($field_content_pairs); - $params = $elastic_search->build_table_search_params($index = $index, $type = $type, $query = $query); - $search_res = $elastic_search->search($params); - - dpm($search_res); - - - - // display search results in a table - - $per_page = 10; - foreach ($form_state['storage']['fields'] as $field) { - $header[] = [ - 'data' => $field, - 'field' => $field, - ]; - } - $rows = $search_res; - $current_page = pager_default_initialize(count($rows), $per_page); - $chunks = array_chunk($rows, $per_page, TRUE); - $output = theme('table', array('header' => $header, 'rows' => $chunks[$current_page])); - $output .= theme('pager', array('quantity', count($rows))); - - $form['search_results'] = [ - '#markup' => $output, - ]; - - - - $form_state['rebuild'] = true; -} -*/ - diff --git a/includes/search/sitewide_search_box_form.inc b/includes/search/website_search_box_form.inc similarity index 66% rename from includes/search/sitewide_search_box_form.inc rename to includes/search/website_search_box_form.inc index b44bc3c7..ec8f838c 100644 --- a/includes/search/sitewide_search_box_form.inc +++ b/includes/search/website_search_box_form.inc @@ -1,7 +1,7 @@ 'textfield', ]; diff --git a/tripal_elasticsearch.admin.inc b/tripal_elasticsearch.admin.inc index 6be2f2a2..eadfa8cd 100644 --- a/tripal_elasticsearch.admin.inc +++ b/tripal_elasticsearch.admin.inc @@ -96,7 +96,7 @@ function delete_indices_page() function build_search_forms_page () { // create a connection port - $connection = (new ElasticConnection(["127.0.0.1:9201"]))->make(); + // $connection = (new ElasticConnection(["127.0.0.1:9201"]))->make(); return drupal_get_form ('build_search_forms_form'); /* @@ -116,14 +116,11 @@ function build_search_forms_page () */ function link_results_to_pages_page () { - // create a connection port - $connection = (new ElasticConnection(["127.0.0.1:9201"]))->make(); - if ($connection) { - return drupal_get_form ('link_results_to_pages_form'); - } else { - drupal_set_message ('Elasticsearch cluster is disconnected.', 'warning'); - return ''; - } + $example_form = drupal_get_form('link_results_to_pages_example_form'); + $form = drupal_get_form('link_results_to_pages_form'); + $output = drupal_render($example_form).drupal_render($form); + + return $output; } diff --git a/tripal_elasticsearch.module b/tripal_elasticsearch.module index b1dcb3a6..0fee6feb 100644 --- a/tripal_elasticsearch.module +++ b/tripal_elasticsearch.module @@ -2,10 +2,6 @@ require drupal_get_path('module', 'tripal_elasticsearch') . '/api/bootstrap.php'; - -set_time_limit(0); - - /** * Implementation of hook_menu(). */ @@ -102,7 +98,6 @@ function tripal_elasticsearch_menu() 'weight' => 2, 'file' => 'tripal_elasticsearch.admin.inc', ); - /* $items[$pre . '/search/link_results_to_pages'] = array( 'title' => t('Link results to pages'), 'page callback' => 'link_results_to_pages_page', @@ -112,21 +107,10 @@ function tripal_elasticsearch_menu() 'weight' => 3, 'file' => 'tripal_elasticsearch.admin.inc', ); - $items[$pre . '/search/alter_search_forms'] = array( - 'title' => t('Alter search forms'), - 'page callback' => 'alter_search_forms_page', - 'access callback' => 'user_access', - 'access arguments' => array('administer users'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 4, - 'file' => 'tripal_elasticsearch.admin.inc', - ); - */ - $items['website-search/%'] = [ - 'title' => t('Website Search'), - 'page callback' => 'website_search_results_page', - 'page arguments' => array(1), + $items['table_search'] = [ + 'title' => t(''), + 'page callback' => 'database_table_search_results_page', 'access callback' => true, ]; @@ -134,9 +118,11 @@ function tripal_elasticsearch_menu() } -function website_search_results_page($node_type) +/* + * create an empty page for displaying website search results + */ +function database_table_search_results_page() { - return ''; } @@ -147,21 +133,20 @@ function tripal_elasticsearch_block_info() { $blocks = array(); // Block for main search box. - $blocks['_sitewide_search_box'] = array( - 'info' => t('tripal_elasticsearch sitewide search box'), + $blocks['_website_search_box'] = array( + 'info' => t('tripal_elasticsearch website search box'), 'status' => TRUE, 'region' => 'help', 'cache' => DRUPAL_NO_CACHE, 'weight' => -99, ); // Block for main search results - $blocks['_sitewide_search_results'] = array( - 'info' => t('tripal_elasticsearch sitewide search results'), + $blocks['_website_search_results'] = array( + 'info' => t('tripal_elasticsearch website search results'), 'status' => TRUE, 'region' => 'content', - 'visibility' => BLOCK_VISIBILITY_LISTED, - 'pages' => "website-search\nwebsite-search/*", 'cache' => DRUPAL_NO_CACHE, + 'weight' => -999, ); //=================TODO====================== @@ -169,8 +154,8 @@ function tripal_elasticsearch_block_info() //=========================================== /* // block for website search categories - $blocks['_sitewide_search_categories'] = [ - 'info' => t('tripal_elasticsearch sitewide search categories'), + $blocks['_website_search_categories'] = [ + 'info' => t('tripal_elasticsearch website search categories'), 'status' => true, 'region' => 'content', 'visibility' => BLOCK_VISIBILITY_LISTED, @@ -196,7 +181,7 @@ function tripal_elasticsearch_block_info() 'status' => TRUE, 'region' => 'content', 'visibility' => BLOCK_VISIBILITY_LISTED, - 'pages' => "elastic_search\nelastic_search/*", + 'pages' => "table_search\ntable_search/*", 'cache' => DRUPAL_NO_CACHE, ); // prefix table name with "sr_" and use it for search result block names @@ -209,7 +194,7 @@ function tripal_elasticsearch_block_info() 'status' => TRUE, 'region' => 'content', 'visibility' => BLOCK_VISIBILITY_LISTED, - 'pages' => "elastic_search\nelastic_search/*", + 'pages' => "table_search\ntable_search/*", 'cache' => DRUPAL_NO_CACHE, ); } @@ -237,14 +222,14 @@ function tripal_elasticsearch_block_view($delta = '') $block_type = 'search_result_block'; $table_name = preg_replace('/^(_sf_)/', '', $delta); } - if ($delta == "_sitewide_search_box") { - $block_type = '_sitewide_search_box'; + if ($delta == "_website_search_box") { + $block_type = '_website_search_box'; } - if ($delta == "_sitewide_search_results") { - $block_type = '_sitewide_search_results'; + if ($delta == "_website_search_results") { + $block_type = '_website_search_results'; } - if ($delta == "_sitewide_search_categories") { - $block_type = '_sitewide_search_categories'; + if ($delta == "_website_search_categories") { + $block_type = '_website_search_categories'; } switch ($block_type) { @@ -261,36 +246,21 @@ function tripal_elasticsearch_block_view($delta = '') if (isset($_GET['_table_name']) && !empty($_GET['_table_name'])) { $block['content'] = theme('database_table_search_results', ['table_name' => $_GET['_table_name']]); } else { - $block['content'] = 'No records were found'; + $block['content'] = ''; } break; - case '_sitewide_search_box': + case '_website_search_box': $block['subject'] = ''; - $block['content'] = drupal_get_form('sitewide_search_box_form'); + $block['content'] = drupal_get_form('website_search_box_form'); break; - case '_sitewide_search_results': + case '_website_search_results': $block['subject'] = ''; - if (isset($_GET['sitewide_search_box']) && !empty($_GET['sitewide_search_box'])) { - $search_content = $_GET['sitewide_search_box']; - - /* - // run elastic search - $connection = (new ElasticConnection(["127.0.0.1:9201"]))->make(); - $elastic_search = new ElasticSearch($connection); - $params = $elastic_search->build_website_search_params($index = 'website', $type = 'website', $search_content = $search_content, $from = 0, $size = 1000); - $search_res = $elastic_search->website_search($params); - $elastic_search->search_count($params); - - if (!empty($search_res)) { - $block['content'] = theme('website_search_results', ['website_search_results' => $search_res]); - } else { - $block['content'] = 'No records were found.'; - } - */ + if (isset($_GET['website_search_box']) && !empty($_GET['website_search_box'])) { + $search_content = $_GET['website_search_box']; $block['content'] = theme('website_search_results', ['search_content' => $search_content]); } else { - $block['content'] = 'No records were found.'; + $block['content'] = ''; } break; @@ -298,11 +268,11 @@ function tripal_elasticsearch_block_view($delta = '') // //=========================================== /* - case '_sitewide_search_categories': + case '_website_search_categories': $block['subject'] = t('Search result categories'); - if (isset($_GET['sitewide_search_box']) && !empty($_GET['sitewide_search_box'])) { - $search_content = $_GET['sitewide_search_box']; + if (isset($_GET['website_search_box']) && !empty($_GET['website_search_box'])) { + $search_content = $_GET['website_search_box']; // run elastic search $connection = (new ElasticConnection(["127.0.0.1:9201"]))->make(); $elastic_search = new ElasticSearch($connection); diff --git a/tripal_elasticsearch.theme.inc b/tripal_elasticsearch.theme.inc index ff6e7e4c..6b3c7040 100644 --- a/tripal_elasticsearch.theme.inc +++ b/tripal_elasticsearch.theme.inc @@ -90,6 +90,7 @@ function theme_website_search_results ($variables) { $output .= theme('table', array('header' => [], 'rows' => $chunks[$current_page])); $output .= theme('pager', array('quantity', count($rows))); + return $output; } @@ -109,7 +110,7 @@ function theme_website_search_categories ($variables) { $categories = []; foreach ($node_type_by_count as $type=>$count) { $text = "$type ($count)"; - $categories[] = l($text, 'website-search/' . $type . '?sitewide_search_box=' . $search_content); + $categories[] = l($text, 'website-search/' . $type . '?website_search_box=' . $search_content); } $output = theme('item_list', array('items' => $categories));