array( "title" => t("administer solr-search"), "description" => t("administer solr-search.") ) ); } function solr_search_menu() { $items = array(); // solr search admin settings $items['admin/settings/solr_search'] = array( 'title' => 'TBC Solr-Search admin settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('tbc_solr_search_settings_form'), 'access arguments' => array('administer solr-search'), 'type' => MENU_NORMAL_ITEM, 'file' => 'settings.inc', ); $items['tbc_solr_search'] = array( 'title' => 'Search within Textbook Companion Examples', 'page callback' => 'drupal_get_form', 'page arguments' => array('tbc_solr_search_form'), 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM, ); $items['add_all_books_to_solr'] = array( 'title' => 'Add books to Solr', 'page callback' => 'drupal_get_form', 'page arguments' => array('add_all_books_to_solr_form'), 'access arguments' => array('administer solr-search'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function tbc_solr_search_form($form,&$form_state) { $form['tbc_search_key'] = array( '#type' => 'textfield', '#title' => t('Enter your keyword (Note: special characters ^ ( ) { } \" \' [ ] are not allowed)'), '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Search'), '#ajax' => array( 'callback' => 'ajax_solr_search_result_callback', ), ); $form['tbc_search_result'] = array( '#type' => 'item', '#markup' => '
', ); return $form; } function tbc_solr_search_form_validate($form, &$form_state) { if(preg_match('/[^a-zA-Z0-9]/', $form_state['values']['tbc_search_key'])) { form_set_error('tbc_search_key', t('Special characters not allowed')); } return; } function tbc_solr_search_form_submit($form, &$form_state) { //drupal_goto('tbc_solr_search', array('key' => $_POST['tbc_search_key'])); // ajax_solr_search_result_callback($form,$form_state); } function add_all_books_to_solr_form($form, &$form_state) { $form['catid'] = array( '#type' => 'select', '#title' => t('Category'), '#options' => array(0 => 'Please select', 1 => 'Fluid Mechanics', 2 => 'Control Theory & Control Systems', 3 => 'Chemical Engineering', 4 => 'Thermodynamics', 5 => 'Mechanical Engineering', 6 => 'Signal Processing', 7 => 'Digital Communications', 8 => 'Electrical Technology', 9 => 'Mathematics & Pure Science', 10 => 'Analog Electronics', 11 => 'Digital Electronics', 12 => 'Computer Programming', 13 => 'Others' ), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Add to Solr'), // '#suffix' => $output, ); return $form; } function add_all_books_to_solr_form_submit($form, &$form_state) { global $user; ini_set('max_execution_time', 500000); $root_path = variable_get('tbc_example_file_path', ''); //var_dump($root_path);die; $options = array( 'hostname' => SOLR_SERVER_HOSTNAME, 'port' => SOLR_SERVER_PORT, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, ); $client = new SolrClient($options); $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status=1 AND category= :catid AND proposal_id IN (SELECT id from textbook_companion_proposal where proposal_status=3)",array(":catid" => $form_state['values']['catid'])); while($book_data = $book_q->fetchObject()) { $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = :pref_id",array(":pref_id" =>$book_data->id)); while($chapter_row = $chapter_q->fetchObject()) { //$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id); $query = db_select('textbook_companion_example'); $query->fields('textbook_companion_example'); $query->condition('chapter_id', $chapter_row->id); $query->condition('approval_status', 1); $example_q = $query->execute(); while($example_row = $example_q->fetchObject()) { //$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id); $query = db_select('textbook_companion_example_files'); $query->fields('textbook_companion_example_files'); $query->condition('example_id', $example_row->id); $example_files_q = $query->execute(); //$example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id); $query = db_select('textbook_companion_example_dependency'); $query->fields('textbook_companion_example_dependency'); $query->condition('example_id', $example_row->id); $example_dependency_files_q = $query->execute(); $extensions = array('sce', 'sci'); $example_data = ''; while($example_files_row = $example_files_q->fetchObject()) { if(in_array(end(explode('.', $example_files_row->filepath)), $extensions)) { // echo $example_files_row->filepath."'.$response['response']->numFound.' result(s) found
'; if($response['response']->numFound > 0) { $output .= 'Book: '.$doc->title.' ('.$doc->author.')
'; $output .= 'Chapter: '.$doc->chapter.'
'; $output .= 'Example: '.$doc->example.'
'; $output .= 'Links: ⤵ Download code for the entire book » View code for this example
'; $output .= '0 result(s) found
'; } } $commands[] = ajax_command_html("#ajax-search-result-replace", $output); return array('#type' => 'ajax', '#commands' => $commands); }