App-CSE

 view release on metacpan or  search on metacpan

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

package App::CSE::Lucy::Search::QueryParser;
$App::CSE::Lucy::Search::QueryParser::VERSION = '0.016';
use base qw/Lucy::Search::QueryParser/;

use Log::Log4perl;
my $LOGGER = Log::Log4perl->get_logger();

use Data::Dumper;

sub make_term_query{
  my ($self, %options) = @_;

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


  if( $term =~ /\*$/ ){
    $LOGGER->trace("Will make a PREFIX  with ".Dumper(\%options));

t/04-search.t  view on Meta::CPAN

  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits()->total_hits() , 3 , "Ok got 3 hits");
}

## Check various queries

{
  # Plain simple term
  local @ARGV = (  '--idx='.$idx_dir, 'hello', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string() , '(call:hello OR content:hello OR decl:hello OR path:hello)');
}

{
  # Plain field term
  local @ARGV = (  '--idx='.$idx_dir, 'content:hello', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), 'content:hello');
}

{
  # Single prefix query
  local @ARGV = (  '--idx='.$idx_dir, 'hell*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), 'content:hell*');
}

{
  # Qualified prefix query
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), 'path:hell*');
}

{
  # Qualified composed queries
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell* AND NOT content:helo*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), '(path:hell* AND -content:helo*)');
}

{
  # Qualified composed queries, multi args
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell*', 'AND', 'NOT' , 'content:helo*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), '(path:hell* AND -content:helo*)');
}

{
  # Same in another way
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell*', '-content:helo*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), '(path:hell* AND -content:helo*)');
}

ok(1);
done_testing();



( run in 0.470 second using v1.01-cache-2.11-cpan-4d50c553e7e )