App-CSE

 view release on metacpan or  search on metacpan

lib/App/CSE/Lucy/Highlight/Highlighter.pm  view on Meta::CPAN


=head2 new

Adds the cse_command new argument.

=cut

sub new{
  my ($class, %options) = @_;
  my $cse_command = delete $options{'cse_command'} || confess("Missing cse_command");
  my $self = $class->SUPER::new(%options);
  # register($self);
  $cse_command{ $self } = $cse_command;
  $cse{ $self } = $cse_command->cse();
  return $self;
}

=head2 encode

Overrides the Lucy encode method to avoid any HTMLI-zation.

lib/App/CSE/Lucy/Highlight/Highlighter.pm  view on Meta::CPAN

    return $cse->colorizer->colored($text , 'yellow on_black');
  }else{
    return '[>'.$text.'<]';
  }
}

sub DESTROY{
  my ($self) = @_;
  delete $cse_command{ $self };
  delete $cse{ $self };
  $self->SUPER::DESTROY();
}

1;

lib/App/CSE/Lucy/Search/QueryParser.pm  view on Meta::CPAN

  my $field = $options{field};
  my $term = $options{term};


  if( $term =~ /\*$/ ){
    $LOGGER->trace("Will make a PREFIX  with ".Dumper(\%options));
    return App::CSE::Lucy::Search::QueryPrefix->new(field => $field,
                                                    query_string => $term);
  }
  $LOGGER->trace("Will make a TERM query with ".Dumper(\%options));
  return $self->SUPER::make_term_query(%options);
}

1;

lib/App/CSE/Lucy/Search/QueryPrefix.pm  view on Meta::CPAN

sub keep_case        { my $self = shift; return $keep_case{$$self} }



sub new {
    my ( $class, %args ) = @_;
    my $query_string = delete $args{query_string};
    my $field        = delete $args{field};
    my $keep_case    = delete $args{keep_case} || 0;

    my $self         = $class->SUPER::new(%args);


    confess("'query_string' param is required")
        unless defined $query_string;
    confess("Invalid query_string: '$query_string'")
        unless $query_string =~ /\*\s*$/;
    confess("'field' param is required")
        unless defined $field;

    $query_string{$$self} = $query_string;

lib/App/CSE/Lucy/Search/QueryPrefix.pm  view on Meta::CPAN

sub add_matching_term{
  my ($self, $term ) = @_;
  push @{$self->highlight_terms()}, $term;
}

sub DESTROY {
    my $self = shift;
    delete $query_string{$$self};
    delete $field{$$self};
    delete $highlight_terms{$$self};
    $self->SUPER::DESTROY;
  }

sub equals {
    my ( $self, $other ) = @_;
    return 0 unless blessed($other);
    return 0 unless $other->isa("App::CSE::Lucy::Search::QueryPrefix");
    return 0 unless $field{$$self} eq $field{$$other};
    return 0 unless $query_string{$$self} eq $query_string{$$other};
    return 1;
  }

lib/App/CSE/Lucy/Search/QueryPrefix.pm  view on Meta::CPAN

my %doc_ids;
my %tick;

sub score{
  return 1.0 ; # Fixed score of 1.0
}

sub new {
  my ( $class, %args ) = @_;
  my $posting_lists = delete $args{posting_lists};
  my $self          = $class->SUPER::new(%args);

  # Cheesy but simple way of interleaving PostingList doc sets.
  my %all_doc_ids;
  for my $posting_list (@$posting_lists) {
    while ( my $doc_id = $posting_list->next ) {
      $all_doc_ids{$doc_id} = undef;
    }
  }
  my @doc_ids = sort { $a <=> $b } keys %all_doc_ids;
  $doc_ids{$$self} = \@doc_ids;

  $tick{$$self}  = -1;

  return $self;
}

sub DESTROY {
  my $self = shift;
  delete $doc_ids{$$self};
  delete $tick{$$self};
  $self->SUPER::DESTROY;
}

sub next {
  my $self    = shift;
  my $doc_ids = $doc_ids{$$self};
  my $tick    = ++$tick{$$self};
  return 0 if $tick >= scalar @$doc_ids;
  return $doc_ids->[$tick];
}



( run in 0.932 second using v1.01-cache-2.11-cpan-49f99fa48dc )