simplified the rules engine
This commit is contained in:
parent
5037b16dbe
commit
394da51da7
5 changed files with 184 additions and 42 deletions
|
|
@ -47,9 +47,12 @@ Returns an array reference containing all the asset ids of the assets that match
|
|||
|
||||
sub getAssetIds {
|
||||
my $self = shift;
|
||||
my $query = "select assetId from assetIndex where ";
|
||||
my $query = "select assetId ";
|
||||
$query .= " , ".$self->{_score} if ($self->{_score});
|
||||
$query .= " from assetIndex where ";
|
||||
$query .= "isPublic=1 and " if ($self->{_isPublic});
|
||||
$query .= "(".$self->{_query}.")";
|
||||
$query .= "(".$self->{_where}.")";
|
||||
$query .= " order by score " if ($self->{_score});
|
||||
my $rs = $self->session->db->prepare($query);
|
||||
$rs->execute($self->{_params});
|
||||
my @ids = ();
|
||||
|
|
@ -70,9 +73,12 @@ Returns an array reference containing asset objects for those that matched.
|
|||
|
||||
sub getAssets {
|
||||
my $self = shift;
|
||||
my $query = "select assetId,className,revisionDate from assetIndex where ";
|
||||
my $query = "select assetId,className,revisionDate ";
|
||||
$query .= " , ".$self->{_score} if ($self->{_score});
|
||||
$query .= " from assetIndex where ";
|
||||
$query .= "isPublic=1 and " if ($self->{_isPublic});
|
||||
$query .= "(".$self->{_query}.")";
|
||||
$query .= "(".$self->{_where}.")";
|
||||
$query .= " order by score " if ($self->{_score});
|
||||
my $rs = $self->session->db->prepare($query);
|
||||
$rs->execute($self->{_params});
|
||||
my @assets = ();
|
||||
|
|
@ -84,6 +90,47 @@ sub getAssets {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getPaginatorResultSet ( )
|
||||
|
||||
Returns a paginator object containing the search result set data.
|
||||
|
||||
=head3 currentURL
|
||||
|
||||
The URL of the current page including attributes. The page number will be appended to this in all links generated by the paginator.
|
||||
|
||||
=head3 paginateAfter
|
||||
|
||||
The number of rows to display per page. If left blank it defaults to 50.
|
||||
|
||||
=head3 pageNumber
|
||||
|
||||
By default the page number will be determined by looking at $self->session->form->process("pn"). If that is empty the page number will be defaulted to "1". If you'd like to override the page number specify it here.
|
||||
|
||||
=head3 formVar
|
||||
|
||||
Specify the form variable the paginator should use in it's links. Defaults to "pn".
|
||||
|
||||
=cut
|
||||
|
||||
sub getPaginatorResultSet {
|
||||
my $self = shift;
|
||||
my $url = shift;
|
||||
my $paginate = shift;
|
||||
my $pageNumber = shift;
|
||||
my $formVar = shift;
|
||||
my $query = "select assetId, title, url, synopsis, ownerUserId, groupIdView, groupIdEdit, creationDate, revisionDate, className ";
|
||||
$query .= " , ".$self->{_score} if ($self->{_score});
|
||||
$query .= " from assetIndex where ";
|
||||
$query .= "isPublic=1 and " if ($self->{_isPublic});
|
||||
$query .= "(".$self->{_where}.")";
|
||||
$query .= " order by score " if ($self->{_score});
|
||||
my $paginator = WebGUI::Paginator->new($self->session, $url, $paginate, $pageNumber, $formVar);
|
||||
$paginator->setDataByQuery($query, undef, undef, $self->{_params});
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getResultSet ( )
|
||||
|
|
@ -94,9 +141,12 @@ Returns a WebGUI::SQL::ResultSet object containing the search results with colum
|
|||
|
||||
sub getResultSet {
|
||||
my $self = shift;
|
||||
my $query = "select assetId, title, url, synopsis, ownerUserId, groupIdView, groupIdEdit, creationDate, revisionDate, className from assetIndex where ";
|
||||
my $query = "select assetId, title, url, synopsis, ownerUserId, groupIdView, groupIdEdit, creationDate, revisionDate, className ";
|
||||
$query .= " , ".$self->{_score} if ($self->{_score});
|
||||
$query .= " from assetIndex where ";
|
||||
$query .= "isPublic=1 and " if ($self->{_isPublic});
|
||||
$query .= "(".$self->{_query}.")";
|
||||
$query .= "(".$self->{_where}.")";
|
||||
$query .= " order by score " if ($self->{_score});
|
||||
my $rs = $self->session->db->prepare($query);
|
||||
$rs->execute($self->{_params});
|
||||
return $rs;
|
||||
|
|
@ -149,7 +199,7 @@ A list of placeholder parameters to go along with the query. See WebGUI::SQL::Re
|
|||
|
||||
sub rawClause {
|
||||
my $self = shift;
|
||||
$self->{_query} = shift;
|
||||
$self->{_where} = shift;
|
||||
$self->{_params} = shift;
|
||||
return $self;
|
||||
}
|
||||
|
|
@ -166,39 +216,25 @@ A rules engine for WebGUI's search system. It also returns a reference to the se
|
|||
|
||||
A hash reference containing rules for a search. The rules will will be hash references containing the values of a rule. Here's an example rule set:
|
||||
|
||||
{
|
||||
{
|
||||
terms => [ "something to search for", "something else to search for"],
|
||||
match => "all"
|
||||
}, {
|
||||
terms => [ "000001000005", "000001000074000003" ]
|
||||
}
|
||||
}
|
||||
{ keywords => "something to search for", lineage => [ "000001000005", "000001000074000003" ] };
|
||||
|
||||
=head4 keywords
|
||||
|
||||
This rule limits the search results to assets that match keyword criteria. This rule has two properties: "terms" and "match". Terms is an array reference that contains key words and key phrases to be searched for. Match is an operator that determins whether "all" the terms must match or if "any" of the terms can match. Match defaults to "any" if not specified.
|
||||
This rule limits the search results to assets that match keyword criteria.
|
||||
|
||||
keywords => {
|
||||
terms => [ "this", "that", "foo bar" ],
|
||||
match => "all"
|
||||
}
|
||||
keywords => "foo bar"
|
||||
|
||||
=head4 lineage
|
||||
|
||||
This rule limits the search to a specific set of descendants in the asset tree. This has just one parameter, "terms", which is an array reference of asset lineages to match against.
|
||||
This rule limits the search to a specific set of descendants in the asset tree. An array reference of asset lineages to match against.
|
||||
|
||||
lineage => {
|
||||
terms => [ "000001000003", "000001000024000005" ]
|
||||
}
|
||||
lineage => [ "000001000003", "000001000024000005" ]
|
||||
|
||||
=head4 classes
|
||||
|
||||
This rule limits the search to a specific set of asset classes. It has just one parameter, "terms", which is an array reference of class names.
|
||||
This rule limits the search to a specific set of asset classes. An array reference of class names.
|
||||
|
||||
classes => {
|
||||
terms => [ "WebGUI::Asset::Wobject::Article", "WebGUI::Asset::Snippet" ]
|
||||
}
|
||||
classes => [ "WebGUI::Asset::Wobject::Article", "WebGUI::Asset::Snippet" ]
|
||||
|
||||
=head4 creationDate
|
||||
|
||||
|
|
@ -227,17 +263,13 @@ sub search {
|
|||
my $query = "";
|
||||
my @clauses = ();
|
||||
if ($rules->{keywords}) {
|
||||
push(@params,@{$rules->{keywords}{terms}});
|
||||
my $operator = ($rules->{keywords}{match} eq "all") ? " and " : " or ";
|
||||
my @phrases = ();
|
||||
foreach (1..scalar(@{$rules->{keywords}{terms}})) {
|
||||
push(@phrases, "match (keywords) against (?)");
|
||||
}
|
||||
push(@clauses, join($operator, @phrases));
|
||||
push(@params,$rules->{keywords},$rules->{keywords});
|
||||
$self->{_score} = "match (keywords) against (? in boolean mode) as score";
|
||||
push(@clauses, "match (keywords) against (? in boolean mode)");
|
||||
}
|
||||
if ($rules->{lineage}) {
|
||||
my @phrases = ();
|
||||
foreach my $lineage (@{$rules->{lineage}{terms}}) {
|
||||
foreach my $lineage (@{$rules->{lineage}}) {
|
||||
next unless defined $lineage;
|
||||
push(@params, $lineage."%");
|
||||
push(@phrases, "lineage like ?");
|
||||
|
|
@ -246,7 +278,7 @@ sub search {
|
|||
}
|
||||
if ($rules->{classes}) {
|
||||
my @phrases = ();
|
||||
foreach my $class (@{$rules->{classes}{terms}}) {
|
||||
foreach my $class (@{$rules->{classes}}) {
|
||||
next unless defined $class;
|
||||
push(@params, $class);
|
||||
push(@phrases, "className=?");
|
||||
|
|
@ -266,7 +298,7 @@ sub search {
|
|||
push(@params, $start, $end);
|
||||
}
|
||||
$self->{_params} = \@params;
|
||||
$self->{_query} = "(".join(") and (", @clauses).")";
|
||||
$self->{_where} = "(".join(") and (", @clauses).")";
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue