Many thanks for your examples. :-)
You're ahead of me regarding custom pivots; so no further input from
me on that. Sorry. :-/
But, the observe_search_query ought to work from the main site module,
is my initial reaction. Does observing other events work from your
main site module?
I've not used the search_query event, but other events successfully
from the main site module.
Cheers,
Andreas
2012/1/18 Jeff Bell <jeff....@gmail.com>:
Pivot tables are only needed if you have custom fields defined in an rsc
that you need to search, sort or filter.
For instance see
http://zotonic.com/documentation/887/searchable-keywords
z_pivot_rsc:define_custom_pivot(?MODULE, [{foo, "text"}], Context),
This creates a pivot table named pivot_?MODULE with one column, "foo" of
type text. You need to fill this table on the observe_custom_pivot/2
notification:
observe_custom_pivot({custom_pivot, Id}, Context) ->
Foo = m_rsc:p(Id, foo, Context),
{?MODULE, [{foo, Foo}]}.
This copies the "foo" property from the rsc into your custom pivot table
whenever you change the rsc. "rebuild all search indexes" in the system
status page also calls this for every rsc in the database.
If you need to have entries in your custom pivot table for only a
certain category, you can return the atom 'none' for ids that do not
match it, like this:
observe_custom_pivot({custom_pivot, Id}, Context) ->
case m_rsc:is_a(Id, Context) of
[text, news] ->
Foo = m_rsc:p(Id, foo, Context),
{?MODULE, [{foo, Foo}]};
_ -> none
end.
This only copies the "foo" column in the pivot table for rsc of type news.
Hope this explains it a bit :-)
Arjan
> <mailto:jeff....@gmail.com>>:
> > {{ m.rsc[i.id <http://i.id>].title }} is {{ i.status }}<br>
Most of the time I just create custom search routines just like you did,
using the rsc table and joining the pivot_?MODULE table that is kept in
sync for me.
search({filter_foo, [{value, Value}]}, _OfffsetLimit, _Context) ->
#search_sql{
select="id",
from="rsc r, pivot_mymodule p",
where="r.id = p.id AND foo = $1",
args=[Value]
}.
Arjan
> <mailto:andreas...@astekk.se
> <mailto:andreas...@astekk.se>>> wrote:
> >
> > Hi Jeff,
> >
> > Many thanks for your examples. :-)
> > You're ahead of me regarding custom pivots; so no further
> input from
> > me on that. Sorry. :-/
> >
> > But, the observe_search_query ought to work from the main site
> module,
> > is my initial reaction. Does observing other events work from your
> > main site module?
> >
> > I've not used the search_query event, but other events
> successfully
> > from the main site module.
> >
> > Cheers,
> > Andreas
> >
> >
> > 2012/1/18 Jeff Bell <jeff....@gmail.com
> <mailto:jeff....@gmail.com>
> > <mailto:jeff....@gmail.com <mailto:jeff....@gmail.com>>>:
> > > {{ m.rsc[i.id <http://i.id> <http://i.id>].title