×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Making Perl Script Make Two Calls to Search Engine

Making Perl Script Make Two Calls to Search Engine

Making Perl Script Make Two Calls to Search Engine

(OP)
I have a perl script that parses an index for search results.

Is there a way to make the script make a call to two separate indices and display the results as one search.  I want to avoid merging the indices, but instead want to  have a divider between the two sets of results.  ( I have done this with another script, but this one eludes me.)


The script:


#!/usr/local/bin/perl

# REQUIRED

# Firstly check the path to PERL executable in the first line of the script.

$swish_path =  '/path/to/swish-e'; # path to SWISH executable


# You should carefully set configuration options in your `swish.conf' file.
# Search imports `IndexName' and `IndexPointer' values and
# its behaviour considerably depends on `ReplaceRules' settings.

#################################################################################

# YOUR CHOICE

%form = ( 'ipath', '/path/index.swish');#default `Search path'


$bgcolor =     '"#ffffff"'; # background color
$textcolor =   'black'; # text color on `bgcolor' background
$atextcolor =  'white'; # text color on `linkcolor' background and
# activ link color
$headercolor = 'maroon'; # headers color
$linkcolor =   'blue'; # links color and alternate background
$alinkcolor =  'lime'; # links color on `linkcolor' background
$vlinkcolor =  'navy'; # visited links color

#################################################################################

# YOU SHOULD NOT ALTER THE REST OF THE SCRIPT

read( STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
@pairs = split( /&/, $buffer );

foreach $pair( @pairs )
{
  ( $name, $value ) = split( /=/, $pair );

  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;

  $form{ $name } = $value;
}

open( RES, ( $form{ 'terms' } ) ?
  "$swish_path -f $form{ 'ipath' } -m 50 -t HBthe -w $form{ 'terms' } ¦" :
  "$swish_path -f $form{ 'ipath' } -m 1 -w 0 ¦" );

_1: while( <RES> )
{
  $Name = $1 if /^# Name: (.*)$/o;
  $Pointer = $1 if /^# Pointer: (.*)$/o;
  last _1 if defined( $Name ) && defined( $Pointer );
  $error = $1 if /^err: (.*)$/o;
  $error = 'Invalid search words' if /^options:/o;
}

$hc = "FONT COLOR=$headercolor";
$atc = "FONT COLOR=$atextcolor";
$alc = "FONT COLOR=$alinkcolor";

$_ = <<EOP;
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>

<head>
<title></title>
</head>
</head>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td width="50%" valign="top"><img SRC="http://www.site.logo.jpg"; ALT=" " width="442" height="103" BORDER="0">
    </td>
    <td width="50%" style="padding-left: 0" bordercolor="#808080">
      <p align="center"><font size="5"><b><i><br>
      </i></b></font><b><font face="Arial">Tell Your Suppliers You Found Them on
      PetroPages</font></b></td>
  </tr>
</table>

EOP

s/VALUE=.$form{ 'ipath' }./$& CHECKED/o;
s/VALUE=.$form2{ 'ipath' }./$& CHECKED/o;
print;

if( $error )
{
  print "<BR><$hc><B>Error:</B> $error<BR><BR><BR>\n";
}
elsif( $form{ 'terms' } )
{
  print "<BR><$hc><B>Documents found:</B>   <SMALL>(red <FONT COLOR=red>¶</FONT> sign shows confidence in the match, best match first)</SMALL><BR><BR>\n";

  while( <RES> )
  {
    print "<FONT SIZE=\"+0\" COLOR=\"".( $1 > 99 ? 'red' : 'black' ).
        "\"><B>¶</B></FONT> <A HREF=\"$2\">$3</A> <BR>"
      if /^([0-9]*) +([^ ]*) +.([^\"]*). +([0-9]*)/o;
    print "No documents found<BR>\n" if /^err/o;
  }
  print "<BR>\n";
}
else
{
  print <<EOP;
    <UL>
EOP
}

print <<EOP;
<p align="left">

*



<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td width="100%" colspan="2"><font color="maroon" face="Arial">TEXT Display:</font> </td>
  </tr>
 </table>
    
    
   
 <table>
 <tr>
 <td width="50%"><form METHOD="POST" ACTION="http://www.site.com/search.cgi";>
       
         <input TYPE="text"
      NAME="terms" SIZE="21" VALUE><input TYPE="submit" VALUE="  Product Categories "
      ALIGN="top"
      style="background-color: #000000; color: #FFFFFF; font-family: sans-serif; font-size: 10pt; font-weight: normal; background-image: url('/images/DoSearch.jpg')"><input TYPE="text"
      NAME="terms" SIZE="21" VALUE><font COLOR="blue"><input TYPE="submit" VALUE="  Product Categories "
      ALIGN="top"
      style="background-color: #000000; color: #FFFFFF; font-family: sans-serif; font-size: 10pt; font-weight: normal; background-image: url('/images/DoSearch.jpg')"></td>   
  </tr>
</table>


EOP

__END__

RE: Making Perl Script Make Two Calls to Search Engine

a not very sophisticated approach would be simply duplicate the sections which query the index and print the results.  A better approach would be to catch, from the calling process, a list of indeces to be queried and loop through them.  This above code is fairly straight forward.  Consequently, I will assume you are new to PERL (or you would not be asking).  So, here are a few notes about the code.


# This opens a pipe or handle to another process which  querys your index.
# roughly translated......
# open HANDLE, someName, if one of these following things works (returns non-zero)
open( RES, ( $form{ 'terms' } ) ?
  "$swish_path -f $form{ 'ipath' } -m 50 -t HBthe -w $form{ 'terms' } ¦" :
  "$swish_path -f $form{ 'ipath' } -m 1 -w 0 ¦" );


#  the 'while (<RES>)' is listening to the handle opened above
# while it gets stuff from the index via the pipe/handle 'RES', catch some stuff
# or jump out of the while.
_1: while( <RES> )
{
  $Name = $1 if /^# Name: (.*)$/o;
  $Pointer = $1 if /^# Pointer: (.*)$/o;
 
# bail out if you have name  and pointer
  last _1 if defined( $Name ) && defined( $Pointer );
                                                                          
  $error = $1 if /^err: (.*)$/o;
  $error = 'Invalid search words' if /^options:/o;
}


# while you get results, in '$_', back from the opened handle (RES)
# print them to the client via STDOUT
# note that the conditional statement follows the action taken
# if the condition is true.  PERL lets you turn this around and it can
# be confusing if you are not used to looking at it.
  while( <RES> )
  {
    # print contents of '$_' with a little tweaking on the fly
    print "<FONT SIZE=\"+0\" COLOR=\"".( $1 > 99 ? 'red' : 'black' ).
        "\"><B>¶</B></FONT> <A HREF=\"$2\">$3</A> <BR>"
      if /^([0-9]*) +([^ ]*) +.([^\"]*). +([0-9]*)/o;
# print error statement          if error is returned.
    print "No documents found<BR>\n" if /^err/o;
  }



close RES; # do this prior to next iteration

# do next iteration and then print the end stuff for the html.

RE: Making Perl Script Make Two Calls to Search Engine

(OP)
Thanks!  I got it figured out.
 %form=('ipath1', '/path/index', 'ipath2', '/path/index);

Plus duplicating the sections.  That was what I wanted, even if apparently unsophisticated.

But out of curiosity, can you give me a clue as what this is about?

"A better approach would be to catch, from the calling process, a list of indeces to be queried and loop through them."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close