Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: kinosearch: discuss

Using QueryFilter and BooleanQuery

 

 

kinosearch discuss RSS feed   Index | Next | Previous | View Threaded


riyaad.miller at predix

Apr 16, 2008, 6:49 AM

Post #1 of 5 (1137 views)
Permalink
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
http://www.rectangular.com/mailman/listinfo/kinosearch


jack_tanner at yahoo

Apr 16, 2008, 7:34 AM

Post #2 of 5 (1082 views)
Permalink
Re: Using QueryFilter and BooleanQuery [In reply to]

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>
> To: kinosearch [at] rectangular
> 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
> 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
http://www.rectangular.com/mailman/listinfo/kinosearch


riyaad.miller at predix

Apr 16, 2008, 7:42 AM

Post #3 of 5 (1081 views)
Permalink
Using QueryFilter and BooleanQuery [In reply to]

Hi Jack

Thanks for your response. Admittedly the arguments work both ways!
I've tested them with both

$incl = @ARGV[0];
$incl = '' unless defined $incl;

$excl = @ARGV[1];
$excl = '' unless defined $excl;

print "find $incl but exclude $excl\n";

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

And ...

$incl = $ARGV[0];
$incl = '' unless defined $incl;

$excl = $ARGV[1];
$excl = '' unless defined $excl;

print "find $incl but exclude $excl\n";

In both case the print out correctly.
Thanks for the intel though!

Anyone with answers to my previous post?

Appreciated ...

(R)


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


alex at primafila

Apr 16, 2008, 7:44 AM

Post #4 of 5 (1077 views)
Permalink
Re: Using QueryFilter and BooleanQuery [In reply to]

On 16-04-2008 at 16:34, jack_tanner [at] yahoo wrote:

>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";

You're confusing Perl with C. See perlvar:

@ARGV The array @ARGV contains the command-line arguments intended
for the script. $#ARGV is generally the number of arguments
minus one, because $ARGV[0] is the first argument, not the pro-
gram's command name itself. See $0 for the command name.

al.

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


marvin at rectangular

Apr 16, 2008, 11:02 AM

Post #5 of 5 (1073 views)
Permalink
Re: Using QueryFilter and BooleanQuery [In reply to]

On Apr 16, 2008, at 6:49 AM, Riyaad Miller wrote:

> I've installed KinoSearch ver. 0.162. Could you please confirm the
> QueryFilter is NOT available in this release (0.162)?

Confirm that it's not there? QueryFilter *is* in 0.162. The module
is there in the distribution tarball. The documentation is on
search.cpan.org: <http://search.cpan.org/~creamyg/KinoSearch-0.162/lib/KinoSearch/Search/QueryFilter.pm
>. Etc.

Why did you think it was gone? How did you verify that it was gone?
Was there more than one source that led you to believe that it was
missing? Have you read <http://catb.org/~esr/faqs/smart-
questions.html> ?

Best,

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/


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

kinosearch discuss RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.