Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project: search.cgi cs149 - PERL programming Submitted by: Sheshagiri Pai Instructor and Guide: Professor Jon Degallier Date: 05/22/2006.

Similar presentations


Presentation on theme: "Project: search.cgi cs149 - PERL programming Submitted by: Sheshagiri Pai Instructor and Guide: Professor Jon Degallier Date: 05/22/2006."— Presentation transcript:

1 Project: search.cgi cs149 - PERL programming Submitted by: Sheshagiri Pai Instructor and Guide: Professor Jon Degallier Date: 05/22/2006

2 Executive Summary Fetch strings according to search criteria From the messages in the message board Display the search results Link the search results to the messages by message id

3 Setup Place search.cgi file in the student home directory by ftp chmode the file to 755 Login as user tt2 with password ********* Go to discussion board Click on the Search menu item This should bring up The “SEARCH” page.

4 Search page description Search Criteria: Any - any word present in the message All the words - in no particular order All the words - in order Expression - using AND or OR Search input - text box for the words to be searched Exact Match - if checked, else search is case-insensitive Search button - for carrying out the search and displaying the results

5 Query string params When search menu item is clicked, the search.cgi page is invoked with the following parameters: querystring: class=26930&&admin_id=jond&admin_name=Jon%20Degallier&b oard_name=26930&board_code=jond26930&name=Sheshagiri%20 Pai&email=shesh.pai@gmail.com&userid=spai&group=1&inst=ohlo ne

6 Main Algorithm if (!param('search_data')) { &create_form(); } else { &print_search_before_result(); &get_n_prepare_data(); foreach $topic(@topics) { &get_messages($topic); foreach $message_file(@message_files) { &separate_thread($message_file); foreach $message (@thread_array) { if(&find_match()) { &process_found_message(); &print_search_result(); } } } } &print_search_after_result(); }

7 Search Form

8 Search Form - contd..

9 Search Results

10 Search Results - Linked Message

11 Create Form The parameters from the query string are gathered and passed as hidden parameters Also passed are the parameters for ‘search text’ and ‘exact match checkbox’ $userid = param('userid'); $board_code = param('board_code'); $admin_id = param('admin_id'); $class = param('class'); $board_name = param('board_name'); $topic_name = param('topic_name'); $name = param('name'); $group = param('group'); $email = param('email'); $admin_name = param('admin_name'); $admin_email = param('admin_email');

12 Create Form - contd.. SEARCH Enter the string to search in the message boards Any All NO order All IN order Expression Search String: Exact Match:

13 Highlights : Existing methods get_n_prepare_data() open( INPUT, "<../../teachers/jond/boards/$board_name/topics.dat") or die("could not open boards/$board_name/topics.dat\n "); @topics = reverse(@topics); get_messages() @message_files = ; separate_thread() if($message_file =~ /\d$/) { open(INPUT, " "); @thread = ; close INPUT; } # split the message by 'message_id::' to into a 'thread' array $thread = join("\n", @thread); @thread_array = split(/message_id:: /, $thread);

14 Find Match sub find_match() { $menu_item = param('option'); # Take action based on the user's choice if ($menu_item == 1) { return &search_any(); } elsif ($menu_item == 2) { return &search_all_no_order(); } elsif ($menu_item == 3) { return &search_all_in_order(); } elsif ($menu_item == 4) { return &search_with_expression(); } else { print ” You have to select a criteria\n "; exit; }

15 Find Match - search_any() sub search_any() { #print "Search Any\n"; # method 1: find any of the terms in one message # loop through search array and search message content $search = 0; @search_any_term = split(" ", "@search_terms"); foreach(@search_any_term) { if($match eq "on") { if($message =~ m/\b$_\b/) { $search = 1; last; } } else { if($message =~ m/\b$_\b/i) { $search = 1; last; } return $search; }

16 Find Match - search_all_no_order() sub search_all_no_order() { #print "Search All in No order\n"; # method 2: find all the terms in one message $search = 0; @search_any_term = split(" ", "@search_terms"); foreach(@search_any_term) { if($match eq "on") { $search = 1; } else { $search = 0; last; } else { if($message =~ m/\b$_\b/i) { $search = 1; } else { $search = 0; last; } return $search; }

17 Find Match - search_all_in_order() sub search_all_in_order() { #print "Search All in order\n"; # method 3: find all the terms in order $search = 0; $search_all_order = "@search_terms"; if($match eq "on") { if($message =~ m/\b$search_all_order\b/) { $search = 1; } else { $search = 0; } else { if($message =~ m/\b$search_all_order\b/i) { $search = 1; } else { $search = 0; } return $search; }

18 Find Match - search_with_expression() Show in actual code

19 Process Found Message sub process_found_message() { # grab writer's name, message id, date, and subject # concatenate the above in one string separated by pipes(|) # push string to $found string $message = "@thread_array"; &trim($message); #print($message); $message_id_only = substr $message, 0, index($message, 'date_time::'); $message_id = "message_id:: "."$message_id_only"; #print("$message_id\n"); my $subject = substr $message, index($message, 'subject:: '), index($message, 'attach:: ')-index($message, 'subject:: '); #print("$subject\n"); $found = "$message_id"."|"."$date_time"."|"."$from"."|"."$subject"; #print(" $found "); }

20 Print Search Result sub print_search_result() { #foreach $found_message(@thread_array) { # build a table of all found messages with links #containing all cgi variables in a string $userid_new = substr($userid, 0, -1); $name_new = substr($name, 0, -1); $email_new = substr($email, 0, -1); $admin_id_new = substr($admin_id, 0, -1); $admin_name_new = substr($admin_name, 0, -1); $board_name_new = substr($board_name, 0, -1); $board_code_new = substr($board_code, 0, -1); $group_new = substr($group, 0, -1); $message_id_only =~ s/^\s+//; #print($message_id_only);

21 Print Search Result - contd.. print(" <a href=\"new_message.cgi?userid=$userid_new&name=$name&email =$email_new&". "admin_id=$admin_id_new&admin_name=$admin_name_new&board_name= $board_name_new&board_code=$board_code_new&". "group=$group_new&topic_name=$topic_path&message_id=$message_id_on ly\" target = \"_blank\">$found "); #} #end loop of found array }

22 Thanks Q & A


Download ppt "Project: search.cgi cs149 - PERL programming Submitted by: Sheshagiri Pai Instructor and Guide: Professor Jon Degallier Date: 05/22/2006."

Similar presentations


Ads by Google