Skip to content

Commit

Permalink
mod_search: add a query term 'name' for searching on unqiue names. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Jan 10, 2017
1 parent 105bbfb commit 0bc6a92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/developer-guide/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,17 @@ Select items which are member of the given content group (or one of its children

content_group=public

name
^^^^

Find resource with a matching unique name. A wildcard can be defined, for example::

name=page_*

Searching on an empty name or just ``*`` will return all resources with a defined name.
The given name will be trimmed and converted to lowercase before searching.


Filter behaviour
----------------

Expand Down
15 changes: 15 additions & 0 deletions modules/mod_search/support/search_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ request_arg("publication_before") -> publication_before;
request_arg("qargs") -> qargs;
request_arg("query_id") -> query_id;
request_arg("rsc_id") -> rsc_id;
request_arg("name") -> name;
request_arg("sort") -> sort;
request_arg("text") -> text;
request_arg("match_objects") -> match_objects;
Expand Down Expand Up @@ -451,6 +452,20 @@ parse_query([{rsc_id, Id}|Rest], Context, Result) ->
Result2 = add_where("rsc.id = " ++ Arg, Result1),
parse_query(Rest, Context, Result2);

%% name=<name-pattern>
%% Filter on the unique name of a resource.
parse_query([{name, Name}|Rest], Context, Result) ->
case z_string:to_lower(z_string:trim(z_convert:to_binary(Name))) of
All when All =:= <<>>; All =:= <<"*">>; All =:= <<"%">> ->
Result2 = add_where("rsc.name is not null", Result),
parse_query(Rest, Context, Result2);
Name1 ->
Name2 = binary:replace(Name1, <<"*">>, <<"%">>, [global]),
{Arg, Result1} = add_arg(Name2, Result),
Result2 = add_where("rsc.name like " ++ Arg, Result1),
parse_query(Rest, Context, Result2)
end;

%% sort=fieldname
%% Order by a given field. Putting a '-' in front of the field name reverts the ordering.
parse_query([{sort, Sort}|Rest], Context, Result) ->
Expand Down

0 comments on commit 0bc6a92

Please sign in to comment.