CLucene

 view release on metacpan or  search on metacpan

CLucene.pm  view on Meta::CPAN

	confess unless $this->{resource};
	CLuceneWrap::CL_GOTOHIT($this->{resource},$hitnum);
}

sub clearsearch
{
	my $this = shift;
	confess unless $this->{resource};
	CLuceneWrap::CL_CLEARSEARCH($this->{resource});
}

sub getfield
{
	my $this = shift;
	confess unless $this->{resource};
	my %arg = @_;
	my $field = $arg{field} || confess "field undefined";
	my $rv = CLuceneWrap::CL_GetField1($this->{resource},$field);
	($rv, $CLuceneWrap::val, $CLuceneWrap::val_len);
}

sub getdatefield
{
	my $this = shift;
	confess unless $this->{resource};
	my %arg = @_;
	my $field = $arg{field} || confess "field undefined";
	CLuceneWrap::CL_GETDATEFIELD($this->{resource}, $field);
}

sub unlock
{
	my $this = shift;
	my %arg = @_;
	my $directorypath = $arg{directorypath} || confess "directorypath undefined";
	CLuceneWrap::CL_UNLOCK($directorypath);
}

sub cleanup
{
	my $this = shift;
	CLuceneWrap::CL_CLEANUP();
}

sub highlight
{
	my $this = shift;
	my %arg = @_;
	my $text = $arg{text} || confess "text unset";
	my $text_is_filename = $arg{text_is_filename} ? 1 : 0;
	CLuceneWrap::CL_Hightlight1($this->{resource}, $text, $text_is_filename);
}

sub highlight_x
{
	my $this = shift;
	my %arg = @_;
	my $text = $arg{text} || confess "text unset";
	my $text_is_filename = $arg{text_is_filename} ? 1 : 0;
	my $sep = $arg{separator} || confess;
	my $max_frags = $arg{max_fragments} || 3;
	my $fragment_size = $arg{fragment_size} || confess;
	my $type = int($arg{type});
	my $html_start = $arg{html_start} || confess;
	my $html_end = $arg{html_end} || confess;
	CLuceneWrap::CL_Hightlight1($this->{resource}, $text, $text_is_filename, $sep, $max_frags, $fragment_size, $type, $html_start, $html_end);
}

# values for flag byte entries
sub NORMAL_FIELD		{ 0 } ;
sub REQUIRED_FIELD	{ 1 } ;
sub PROHIBITED_FIELD	{ 2 } ;

#---

# set if set
sub sis
{
	$_[0] = $_[1] if defined $_[1];
}

# select first defined in list
sub anyof
{
	for (@_)
	{
		return $_ if defined $_;
	}
	undef;
}

1;
__END__

=head1 NAME

CLucene - Perl interface to CLucene C++ search engine

=head1 SYNOPSIS

  use CLucene;
  my $cl = CLucene->new( path => "./index" );

  # create index
  $cl->open( path => "./index", create => 1 );

  # add document to index
  $cl->new_document;
  $cl->add_field( field => "ref", value => "doc1");
  $cl->add_field( field => "cnt", value => "some content");
  $cl->add_date ( field => "add_dt", value => time );
  $cl->insert_document or confess "Failed to insert document";
  $cl->close;

  # search index
  $cl->open( path => "./index", create => 0 );
  $cl->search( query => "some", field => "cnt" ) or confess "Search failed";
  my $hitcount = $cl->hitcount;
  while ($hitcount--)
  {
    (my $ret,my $valref,my $valreflen) = $cl->getfield( field => "ref" );
  	 confess "Failed getfield ref" unless $ret;
  	 ($ret,my $valcnt,my $valcntlen) = $cl->getfield( field => "cnt" );
    confess "Failed getfield cnt" unless $ret;
    my $valadddt = $cl->getdatefield( field => "add_dt" )
      or confess "Failed getdatefield add_dt";



( run in 0.946 second using v1.01-cache-2.11-cpan-b16cb0d3907 )