package QueryParser;
use OpenSRF::Utils::JSON;
+
+=head1 NAME
+
+QueryParser - basic QueryParser class
+
+=head1 SYNOPSIS
+
+use QueryParser;
+my $QParser = QueryParser->new(%args);
+
+=head1 DESCRIPTION
+
+Main entrypoint into the QueryParser functionality.
+
+=head1 FUNCTIONS
+
+=cut
+
+# Note that the first key must match the name of the package.
our %parser_config = (
QueryParser => {
filters => [],
}
+=head2 facet_class_count
+
+ $count = $QParser->facet_class_count();
+=cut
+
sub facet_class_count {
my $self = shift;
return @{$self->facet_classes};
}
+=head2 search_class_count
+
+ $count = $QParser->search_class_count();
+=cut
+
sub search_class_count {
my $self = shift;
return @{$self->search_classes};
}
+=head2 filter_count
+
+ $count = $QParser->filter_count();
+=cut
+
sub filter_count {
my $self = shift;
return @{$self->filters};
}
+=head2 modifier_count
+
+ $count = $QParser->modifier_count();
+=cut
+
sub modifier_count {
my $self = shift;
return @{$self->modifiers};
}
+=head2 custom_data
+
+ $data = $QParser->custom_data($class);
+=cut
+
sub custom_data {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{custom_data};
}
+=head2 operators
+
+ $operators = $QParser->operators();
+
+Returns hashref of the configured operators.
+=cut
+
sub operators {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{allow_nested_modifiers};
}
+=head2 filters
+
+ $filters = $QParser->filters();
+
+Returns arrayref of the configured filters.
+=cut
+
sub filters {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{filters};
}
+=head2 filter_callbacks
+
+ $filter_callbacks = $QParser->filter_callbacks();
+
+Returns hashref of the configured filter callbacks.
+=cut
+
sub filter_callbacks {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{filter_callbacks};
}
+=head2 modifiers
+
+ $modifiers = $QParser->modifiers();
+
+Returns arrayref of the configured modifiers.
+=cut
+
sub modifiers {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{modifiers};
}
+=head2 new
+
+ $QParser = QueryParser->new(%args);
+
+Creates a new QueryParser object.
+=cut
+
sub new {
my $class = shift;
$class = ref($class) || $class;
return $self;
}
+=head2 new_plan
+
+ $query_plan = $QParser->new_plan();
+
+Create a new query plan.
+=cut
+
sub new_plan {
my $self = shift;
my $pkg = ref($self) || $self;
return do{$pkg.'::query_plan'}->new( QueryParser => $self, @_ );
}
+=head2 add_search_filter
+
+ $QParser->add_search_filter($filter, [$callback]);
+
+Adds a filter with the specified name and an optional callback to the
+QueryParser configuration.
+=cut
+
sub add_search_filter {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $filter;
}
+=head2 add_search_modifier
+
+ $QParser->add_search_modifier($modifier);
+
+Adds a modifier with the specified name to the QueryParser configuration.
+=cut
+
sub add_search_modifier {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $modifier;
}
+=head2 add_facet_class
+
+ $QParser->add_facet_class($facet_class);
+
+Adds a facet class with the specified name to the QueryParser configuration.
+=cut
+
sub add_facet_class {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $class;
}
+=head2 add_search_class
+
+ $QParser->add_search_class($class);
+
+Adds a search class with the specified name to the QueryParser configuration.
+=cut
+
sub add_search_class {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $class;
}
+=head2 add_search_modifier
+
+ $op = $QParser->operator($operator, [$newvalue]);
+
+Retrieves or sets value for the specified operator. Valid operators and
+their defaults are as follows:
+
+=over 4
+
+=item * and => &&
+
+=item * or => ||
+
+=item * group_start => (
+
+=item * group_end => )
+
+=item * required => +
+
+=item * disallowed => -
+
+=item * modifier => #
+
+=back
+
+=cut
+
sub operator {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{operators}{$opname};
}
+=head2 facet_classes
+
+ $classes = $QParser->facet_classes([\@newclasses]);
+
+Returns arrayref of all configured facet classes after optionally
+replacing configuration.
+=cut
+
sub facet_classes {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{facet_classes};
}
+=head2 search_classes
+
+ $classes = $QParser->search_classes([\@newclasses]);
+
+Returns arrayref of all configured search classes after optionally
+replacing the previous configuration.
+=cut
+
sub search_classes {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{classes};
}
+=head2 add_query_normalizer
+
+ $function = $QParser->add_query_normalizer($class, $field, $func, [\@params]);
+
+=cut
+
sub add_query_normalizer {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $func;
}
+=head2 query_normalizers
+
+ $normalizers = $QParser->query_normalizers($class, $field);
+
+Returns a list of normalizers associated with the specified search class
+and field
+=cut
+
sub query_normalizers {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $parser_config{$pkg}{normalizers};
}
+=head2 add_filter_normalizer
+
+ $normalizer = $QParser->add_filter_normalizer($filter, $func, [\@params]);
+
+Adds a normalizer function to the specified filter.
+=cut
+
sub add_filter_normalizer {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $func;
}
+=head2 filter_normalizers
+
+ $normalizers = $QParser->filter_normalizers($filter);
+
+Return arrayref of normalizer functions associated with the specified filter.
+=cut
+
sub filter_normalizers {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $parser_config{$pkg}{filter_normalizers};
}
+=head2 default_search_class
+
+ $default_class = $QParser->default_search_class([$class]);
+
+Set or return the default search class.
+=cut
+
sub default_search_class {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $QueryParser::parser_config{$pkg}{default_class};
}
+=head2 remove_facet_class
+
+ $QParser->remove_facet_class($class);
+
+Remove the specified facet class from the configuration.
+=cut
+
sub remove_facet_class {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $class;
}
+=head2 remove_search_class
+
+ $QParser->remove_search_class($class);
+
+Remove the specified search class from the configuration.
+=cut
+
sub remove_search_class {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return $class;
}
+=head2 add_facet_field
+
+ $QParser->add_facet_field($class, $field);
+
+Adds the specified field (and facet class if it doesn't already exist)
+to the configuration.
+=cut
+
sub add_facet_field {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => $field };
}
+=head2 facet_fields
+
+ $fields = $QParser->facet_fields($class);
+
+Returns arrayref with list of fields for specified facet class.
+=cut
+
sub facet_fields {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{facet_fields};
}
+=head2 add_search_field
+
+ $QParser->add_search_field($class, $field);
+
+Adds the specified field (and facet class if it doesn't already exist)
+to the configuration.
+=cut
+
sub add_search_field {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => $field };
}
+=head2 search_fields
+
+ $fields = $QParser->search_fields();
+
+Returns arrayref with list of configured search fields.
+=cut
+
sub search_fields {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{fields};
}
+=head2 add_search_class_alias
+
+ $QParser->add_search_class_alias($class, $alias);
+=cut
+
sub add_search_class_alias {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => $alias };
}
+=head2 search_class_aliases
+
+ $aliases = $QParser->search_class_aliases($class);
+=cut
+
sub search_class_aliases {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{class_map};
}
+=head2 add_search_field_alias
+
+ $QParser->add_search_field_alias($class, $field, $alias);
+=cut
+
sub add_search_field_alias {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => { $field => $alias } };
}
+=head2 search_field_aliases
+
+ $aliases = $QParser->search_field_aliases();
+=cut
+
sub search_field_aliases {
my $class = shift;
$class = ref($class) || $class;
return $parser_config{$class}{field_alias_map};
}
+=head2 remove_facet_field
+
+ $QParser->remove_facet_field($class, $field);
+=cut
+
sub remove_facet_field {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => $field };
}
+=head2 remove_search_field
+
+ $QParser->remove_search_field($class, $field);
+=cut
+
sub remove_search_field {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => $field };
}
+=head2 remove_search_field_alias
+
+ $QParser->remove_search_field_alias($class, $field, $alias);
+=cut
+
sub remove_search_field_alias {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => { $field => $alias } };
}
+=head2 remove_search_class_alias
+
+ $QParser->remove_search_class_alias($class, $alias);
+=cut
+
sub remove_search_class_alias {
my $pkg = shift;
$pkg = ref($pkg) || $pkg;
return { $class => $alias };
}
+=head2 debug
+
+ $debug = $QParser->debug([$debug]);
+
+Return or set whether debugging output is enabled.
+=cut
+
sub debug {
my $self = shift;
my $q = shift;
return $self->{_debug};
}
+=head2 query
+
+ $query = $QParser->query([$query]);
+
+Return or set the query.
+=cut
+
sub query {
my $self = shift;
my $q = shift;
return $self->{_query};
}
+=head2 parse_tree
+
+ $parse_tree = $QParser->parse_tree([$parse_tree]);
+
+Return or set the parse tree associated with the QueryParser.
+=cut
+
sub parse_tree {
my $self = shift;
my $q = shift;
return $self->{_top};
}
+=head2 parse
+
+ $QParser->parse([$query]);
+
+Parse the specified query, or the query already associated with the QueryParser
+object.
+=cut
+
sub parse {
my $self = shift;
my $pkg = ref($self) || $self;
return $self;
}
+=head2 decompose
+
+ ($struct, $remainder) = $QParser->decompose($querystring, [$current_class], [$recursing], [$phrase_helper]);
+
+This routine does the heavy work of parsing the query string recursively.
+Returns the top level query plan, or the query plan from a lower level plus
+the portion of the query string that needs to be processed at a higher level.
+=cut
+
sub decompose {
my $self = shift;
my $pkg = ref($self) || $self;
return ($struct, $remainder);
}
+=head2 find_class_index
+
+ $index = $QParser->find_class_index($class, $query);
+=cut
+
sub find_class_index {
my $class = shift;
my $query = shift;
return -1;
}
+=head2 core_limit
+
+ $limit = $QParser->core_limit([$limit]);
+
+Return and/or set the core_limit.
+=cut
+
sub core_limit {
my $self = shift;
my $l = shift;
return $self->{core_limit};
}
+=head2 superpage
+
+ $superpage = $QParser->superpage([$superpage]);
+
+Return and/or set the superpage.
+=cut
+
sub superpage {
my $self = shift;
my $l = shift;
return $self->{superpage};
}
+=head2 superpage_size
+
+ $size = $QParser->superpage_size([$size]);
+
+Return and/or set the superpage size.
+=cut
+
sub superpage_size {
my $self = shift;
my $l = shift;