mod_search (zotonic_mod_search v1.0.0-rc.17)

mod_search implements various ways of searching through the main resource table using m_search.

Configuration

There are two site configuration variables to tweak PostgreSQL text search settings.

mod_search.rank_behaviour

An integer representation to influence PostgreSQL search behaviour.

Default: 37 (1 | 4 | 32)

mod_search.rank_weight

A set of four numbers to override relative weights for the ABCD categories.

Default: {0.05, 0.25, 0.5, 1.0}

The following searches are implemented in mod_search:

NameDescriptionRequired arguments
queryVery powerful search with which you can implement almost all of the other search functionality. See: Search
facetsPerforms a query (see above) and then calculates facets. The facets are defined using the pivot/facet.tpl template. Facets are returned in the facets field of the search result. This shows per facet the counts for alternative values.
subfacetsPerforms a query (see above) and then calculates facets. The facets are defined using the pivot/facet.tpl template. Facets are returned in the facets field of the search result. This is a drill down where the facets are counted from the matching resources in the query. That means that only facet values that are in the result set are shown.
facet\_valuesReturns an empty result with the facets field set to all possible values per facet, or the min/max range for a range facet.
featuredList of pages, featured ones first.
featuredList of pages in a category, featured ones first.cat
featuredList of pages in a category having a certain object, featured pages first.cat, object, predicate
latestThe newest pages.
latestThe newest pages within in a category.cat
upcomingSelects pages with future date\_end.
upcoming\_onSelects pages with date\_end after the given time.datetime
upcoming\_dateSelects pages with date\_end after the given date.date
finishedSelects pages with a past date\_end.
finished\_onSelects pages with a date\_end before the given time.datetime
finished\_dateSelects pages with a date\_end before the given date.date
unfinishedSelects pages with a date\_end in the future.
unfinished\_onSelects pages with a date\_end after the given time.datetime
unfinished\_dateSelects pages with a date\_end after the given date.date
ongoingPages with past date\_start and future date\_end.
ongoing\_onPages with a date\_start - date\_end range around the given time.datetime
ongoing\_datePages with a date\_start - date\_end range around the given date.date
autocompleteFull text search where the last word gets a wildcard.text
autocompleteFull text search where the last word gets a wildcard, filtered by category.cat, text
fulltextFull text search. Returns {id,score} tuples.text
fulltextFull text search, filtered by category. Returns {id,score} tuples.cat, text
referrersAll subjects of a page.id
media\_category\_imageAll pages with a medium and within a certain category. Used to find category images.cat
media\_category\_depictionAll pages with a depiction edge to an image. Used to find category images.cat
mediaAll pages with a medium, ordered by descending creation date.
all\_bytitleReturn all {title,id} pairs for a category, sorted on title.cat
all\_bytitle\_featuredReturn all {title,id} pairs for a category, sorted on title, featured pages firstcat
all\_bytitleReturn all {title,id} pairs for a category without subcategories, sorted on title.cat\_is
all\_bytitle\_featuredReturn all {title,id} pairs for a category without subcategories, sorted on title, featured pages first.cat\_is
match\_objectsReturns a list of pages with similar object ids to the objects of the given resource with the given id. Accepts optional cat parameters for filtering on category. Optionally accepts a predicate parameter to only use the objects that are connected to the given id using the predicate or predicates.id
match\_objects\_catsReturns a list of pages with similar object ids or categories. Accepts an optional cat parameter for filtering on category.id
archive\_yearReturns an overview on publication year basis, for a specified category. Every row returned has parts: “as\_date”, “year” and “count”. The order is descending, newest year first.cat
archive\_year\_monthReturn a grouped “archive” overview of resources within a category. The result is a double list, consisting of [ {year, [ months ] }]. The result is grouped on publication year and month, and includes counts. The order is descending, newest year first.cat
keyword\_cloudReturn a list of {keyword_id, count} for all resources within a given category. The list is ordered on keyword title. Default predicate is subject, default category is keyword. Change optional keywordpred and keywordcat to create a different cloud.cat, keywordpred, keywordcat
previousGiven an id, return a list of “previous” ids in the given category. This list is ordered by publication date, latest first.id, cat
nextGiven an id, return a list of “next” ids in the given category. This list is ordred by publication date, oldest first.id, cat

Accepted Events

This module handles the following notifier callbacks:

  • observe_custom_pivot: Populate facet pivot columns during resource indexing for search facets.
  • observe_filewatcher: Rebuild facet tables when watched search facet definition files change.
  • observe_module_activate: Trigger asynchronous initialization when the search module is activated.
  • observe_module_reindexed: Check the search facet table if all modules are running and the indexer reindexed using search_facet:ensure_table.
  • observe_search_query: Execute supported full-text and facet search query operators.

Delegate callbacks:

  • event/2 with postback messages: facet_rebuild.

See also

Search, Custom search

Summary

Functions

code_change(OldVsn, State, Extra)

-spec code_change(term(), term(), term()) -> {ok, term()}.

event/2

find_by_id(S, Context)

-spec find_by_id(string() | binary(), z:context()) ->
                    #search_result{search_name :: binary() | atom(),
                                   search_args :: map() | proplists:proplist(),
                                   result :: list(),
                                   page :: pos_integer(),
                                   pagelen :: pos_integer() | undefined,
                                   options :: z_search:search_options(),
                                   total :: non_neg_integer() | undefined,
                                   pages :: non_neg_integer() | undefined,
                                   is_total_estimated :: boolean(),
                                   next :: pos_integer() | false,
                                   prev :: pos_integer(),
                                   facets :: #{binary() => map()} | undefined}.

find_by_id/3

-spec find_by_id(string() | binary(), boolean(), z:context()) ->
                    #search_result{search_name :: binary() | atom(),
                                   search_args :: map() | proplists:proplist(),
                                   result :: list(),
                                   page :: pos_integer(),
                                   pagelen :: pos_integer() | undefined,
                                   options :: z_search:search_options(),
                                   total :: non_neg_integer() | undefined,
                                   pages :: non_neg_integer() | undefined,
                                   is_total_estimated :: boolean(),
                                   next :: pos_integer() | false,
                                   prev :: pos_integer(),
                                   facets :: #{binary() => map()} | undefined}.

handle_call/3

handle_cast/2

handle_info/2

init(Args)

observe_custom_pivot/2

observe_filewatcher/2

observe_module_activate/2

observe_module_reindexed/2

observe_search_query/2

pid_observe_rsc_delete/3

pid_observe_rsc_update_done/3

rank_behaviour(Context)

-spec rank_behaviour(Context) -> Behaviour when Context :: z:context(), Behaviour :: non_neg_integer().

rank_weight(Context)

-spec rank_weight(Context) -> Weights when Context :: z:context(), Weights :: binary().

start_link(Args)

terminate(Reason, State)

to_tsquery/2

-spec to_tsquery(binary() | string() | z:trans() | undefined, z:context()) -> binary().

trim/2

-spec trim(binary() | string() | z:trans() | undefined, z:context()) -> binary().