[KinoSearch] Using QueryFilter and BooleanQuery
Riyaad Miller
riyaad.miller at predix.com
Wed Apr 16 06:49:33 PDT 2008
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
More information about the kinosearch
mailing list