z_search (zotonic_core v1.0.0-rc.11)

Search the database, interfaces to specific search routines.

Link to this section Summary

Functions

Map a map with (binary) search options to a search option list.
Change a search props list to a map with binary keys.
Given a query as proplist or map, return all results.
Inject the ACL checks in the SQL query.
Search with the question and return the results
Perform the named search and its arguments
Perform a named search with arguments.
Perform a named search with arguments.
Search items and handle the paging. Uses the default page length.
Search items and handle the paging. This fetches extra rows beyond the requested rows to ensure that the pager has the information for the "next page" options. The number of extra rows depends on the current page, more for page 1, less for later pages.
Handle a return value from a search function. This can be an intermediate SQL statement that still needs to be augmented with extra ACL checks.

Link to this section Types

Link to this type

search_offset/0

-type search_offset() :: Limit :: pos_integer() | {Offset :: pos_integer(), Limit :: pos_integer()}.
Link to this type

search_options/0

-type search_options() :: #{properties => [binary()] | boolean()}.
Link to this type

search_query/0

-type search_query() :: {atom(), list()} | {binary(), map() | undefined}.

Link to this section Functions

Link to this function

concat_sql_query(Search_sql, Limit1)

Link to this function

map_to_options(Map)

-spec map_to_options(map()) -> search_options().
Map a map with (binary) search options to a search option list.
Link to this function

props_to_map(Props)

-spec props_to_map(proplists:proplist() | map()) -> #{binary() => term()}.
Change a search props list to a map with binary keys.
Link to this function

query_(Args, Context)

-spec query_(proplists:proplist() | map(), z:context()) -> [m_rsc:resource_id()].
Given a query as proplist or map, return all results.
Link to this function

reformat_sql_query(Search_sql, Context)

-spec reformat_sql_query(#search_sql{}, z:context()) -> #search_sql{}.
Inject the ACL checks in the SQL query.
Link to this function

search(Search, Context)

This function is deprecated. use search/5.
-spec search({atom() | binary(), proplists:proplist() | map()}, z:context()) -> #search_result{}.
Search with the question and return the results
Link to this function

search(Search, MaxRows, Context)

This function is deprecated. use search/5.
-spec search(search_query(), search_offset() | undefined, z:context()) -> #search_result{}.
Perform the named search and its arguments
Link to this function

search(Name, Args, Page, PageLen, Context)

-spec search(Name, Args, Page, PageLen, Context) -> Result
          when
              Name :: binary(),
              Args :: map() | proplists:proplist() | undefined,
              Page :: pos_integer() | undefined,
              PageLen :: pos_integer() | undefined,
              Context :: z:context(),
              Result :: #search_result{}.
Perform a named search with arguments.
Link to this function

search(Name, Args, Page, PageLen, Options, Context)

-spec search(Name, Args, Page, PageLen, Options, Context) -> Result
          when
              Name :: binary(),
              Args :: map() | proplists:proplist() | undefined,
              Page :: pos_integer() | undefined,
              PageLen :: pos_integer() | undefined,
              Options :: map(),
              Context :: z:context(),
              Result :: #search_result{}.
Perform a named search with arguments.
Link to this function

search_pager(Query, Page, Context)

This function is deprecated. use search/5.
-spec search_pager(Query, Page, Context) -> Result
                when
                    Query :: search_query(),
                    Page :: pos_integer(),
                    Context :: z:context(),
                    Result :: #search_result{}.
Search items and handle the paging. Uses the default page length.
Link to this function

search_pager(Query, Page, PageLen, Context)

-spec search_pager(Query, Page, PageLen, Context) -> Result
                when
                    Query :: search_query(),
                    Page :: pos_integer() | undefined,
                    PageLen :: pos_integer() | undefined,
                    Context :: z:context(),
                    Result :: #search_result{}.
Search items and handle the paging. This fetches extra rows beyond the requested rows to ensure that the pager has the information for the "next page" options. The number of extra rows depends on the current page, more for page 1, less for later pages.
Link to this function

search_result(Result, Limit, Context)

-spec search_result(Result, search_offset(), Context) -> #search_result{}
                 when Result :: list() | #search_result{} | #search_sql{}, Context :: z:context().
Handle a return value from a search function. This can be an intermediate SQL statement that still needs to be augmented with extra ACL checks.