On Friday, I finally managed to get Perl to query the index server using a
specific catalogue. The key was this:
$SQL = "SELECT $FIELDS FROM Psyche..SCOPE(' DEEP TRAVERSAL OF
\"D:\\psyche.net.uk\" ') WHERE FREETEXT(Contents, '\"$QUERY\"') > 0 order
by Rank DESC";
Where Psyche.. (The two dots are important!) is the catalogue that you have
created on the server.
D:\\psyche.net.uk is the directory that you've added to the catalogue on
the server.
I saw that it was possible to specify the catalogue in the SQL statement,
but didn't realise that the two ..s were important. I managed to track
down an example that specified the Catalogue on the command line:
http://www.msdn.microsoft.com/library/psdk/indexsrv/ixrefqls_44rp.htm
After learning that, and making changes to the script, it worked!
Please find attached a standalone script that should query the index
server, specifying a catalogue and scope of your choice.
I hope that this is useful to you.
Regards,
Roland
#Modules
use Win32::OLE;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
$CONNSTR = "Provider=MSIDXS;"; #Provider
$MAXRECORDS = 10; #Max records to return
$QUERY = "Index"; #What to do the freetext query on.
$FIELDS = "
Characterization,
Rank,
DocAuthor,
Size,
DocTitle,
Filename,
HitCount,
Directory,
DocAppName,
Vpath,
write
";
@FIELDS = split(/,/,$FIELDS);
$SQL = "SELECT $FIELDS FROM Psyche..SCOPE(' DEEP TRAVERSAL OF \"D:\\psyche.net.uk\" ')
WHERE FREETEXT(Contents, '\"$QUERY\"') > 0 order by Rank DESC";
my $CONN = new Win32::OLE("ADODB.Connection");
my $RS = new Win32::OLE("ADODB.Recordset");
$CONN->Open($CONNSTR);
$RS->{MaxRecords} = $MAXRECORDS;
$RS->Open($SQL,$CONN,0,1,1);
if ($RS->bof || $RS->eof) {
print "No records found\n";
&TIDYUP;
}
else {
$RS->MoveFirst;
while (!($RS->bof || $RS->eof)) {
$EXPEND = $BLOCK;
foreach $ITEM (@FIELDS) {
$ITEM =~ s/\n//g;
$$ITEM = $RS->Fields($ITEM)->Value;
print "$$ITEM\n";
}
$RS->MoveNext;
}
&TIDYUP;
print "$BOTTOM";
}
sub TIDYUP {
$RS->Close();
undef $RS;
$CONN->Close();
undef $CONN;
}
exit;