[KinoSearch] Using QueryFilter and BooleanQuery

jack_tanner at yahoo.com jack_tanner at yahoo.com
Wed Apr 16 07:34:05 PDT 2008



One bug in your script is your indexing into @ARGV. $ARGV[0] is not the first parameter to the script, it's the script filename itself. Try this:

print join (', ', @ARGV) . "\n";


----- Original Message ----
> From: Riyaad Miller <riyaad.miller at predix.com>
> To: kinosearch at rectangular.com
> Sent: Wednesday, April 16, 2008 9:49:33 AM
> Subject: [KinoSearch] Using QueryFilter and BooleanQuery
> 
> Hi guys
> 
> Thanks for your previous reply.
> 
> I've installed KinoSearch ver. 0.162. Could you please confirm the QueryFilter 
> is NOT available in this release (0.162)?
> 
> With regards to BooleanQuery, I've put together the following command line 
> script using ver. 0.162.
>  
> When entering 'perl' as my first arg and nutshell as my second (my code should 
> exclude results contain 'nutshell') 
> but for some strange reason it still returns the results with 'nutshell' in 
> them. Could you please tell me what am I doing wrong here?
> 
> Appreciated.
> 
> 
> -----------------------------------------
> 
> use KinoSearch::Searcher;
> use KinoSearch::Analysis::PolyAnalyzer;
> use KinoSearch::Highlight::Highlighter;
> use KinoSearch::Search::QueryFilter;
> use KinoSearch::Search::BooleanQuery;
> 
> $incl = $ARGV[0];
> $incl = '' unless defined $incl;
> 
> $excl = $ARGV[1];
> $excl = '' unless defined $excl;
> 
> print "find $incl but exclude $excl\n";
> 
> print "." x 80 . "\n";
> 
> $invIndexDirectory = '/tmp/KinoSearchIndex';
> 
> $analyzer = KinoSearch::Analysis::PolyAnalyzer->new(language => 'en');
> 
> $searcher = KinoSearch::Searcher->new(
>  analyzer => $analyzer,
>  invindex => $invIndexDirectory
> );
> 
> $bool_query = KinoSearch::Search::BooleanQuery->new;
> 
> $include  = KinoSearch::Search::TermQuery->new(term => 
> KinoSearch::Index::Term->new('bodytext',$incl));
> $bool_query->add_clause(query => $include, occur=>'MUST');
> $exclude  = KinoSearch::Search::TermQuery->new(term => 
> KinoSearch::Index::Term->new('bodytext',$excl));
> $bool_query->add_clause(query => $exclude, occur=>'MUST_NOT');
> 
> $hits = $searcher->search(
>   query  => $bool_query,
> );
> 
> $highlighter = KinoSearch::Highlight::Highlighter->new(excerpt_field => 
> 'bodytext');
> $hits->create_excerpts(highlighter => $highlighter);
> 
> print "-" x 80 . "\n";
> 
> while ($hit = $hits->fetch_hit_hashref)
> {
>   print  "Title: $hit->{title}\n";
>   print  "URL  : $hit->{url}\n";
>   print  "Exc  : $hit->{excerpt}\n";
>   printf "Score: %0.3f\n", $hit->{score};
>   print "-" x 80 . "\n";
> }
> 
> 
> -------End-------
> 
> 
> _______________________________________________
> KinoSearch mailing list
> KinoSearch at rectangular.com
> http://www.rectangular.com/mailman/listinfo/kinosearch
> 




      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch




More information about the kinosearch mailing list