search.page error

16 views
Skip to first unread message

Wes James

unread,
Jun 6, 2011, 6:57:28 PM6/6/11
to zotoni...@googlegroups.com
I took this from the zotonic site:


{% with m.search.paged[{fulltext cat=q.qcat text=q.qs page=q.page}] as result %}
<ul>
{% pager result=result dispatch="admin_overview_rsc" qargs %}
{% for id in result %}
<li><a href="">{{ m.rsc[id].title }}</a></li>
{% empty %}
<li>Nothing found</li>
{% endfor %}
</ul>
{% endwith %}


and put it in a srch.tpl and created a dispatch:

{srch,["srch"], resource_template, [ {template, "srch.tpl"}]}

but when I visit zt:8000/srch I get an error. If you want I can post
the error somewhere if it is not obvious why.

thanks,

-wes

Marc Worrell

unread,
Jun 7, 2011, 5:34:53 AM6/7/11
to zotoni...@googlegroups.com, Wes James, Alain O'Dea
This looks like a documentation error.

The {fulltex ...} search doesn't just return an id but also a score. The score defines how well the page matches the search term:

> (zoton...@lamma.local)43> z_search:search({fulltext, [{text, "admin"}]}, z:c(maxclass)).
> {search_result,[{1,0.7222222089767456},
> {18601,0.23076923191547394},
> {19105,0.23076923191547394},
> {19113,0.23076923191547394},
> {18697,0.09090909361839294},
> {4134,0.09090909361839294},
> {19109,0.09090909361839294},
> {19332,0.09090909361839294}],
> 1,undefined,undefined,undefined,undefined,undefined,
> undefined}

So the loop should be:

> {% for id, score in result %}

I have corrected this on the page http://zotonic.com/scomp-pager

Best, Marc

Marc Worrell

unread,
Jun 7, 2011, 5:37:17 AM6/7/11
to zotoni...@googlegroups.com, Alain O'Dea
I also corrected the documentation on http://zotonic.com/documentation/726/m-search
At the two fulltext entries I added that they return {id,score} tuples.

- Marc


Andreas Stenius

unread,
Jun 7, 2011, 8:38:13 AM6/7/11
to zotoni...@googlegroups.com
Hi Marc et al,

Would it be difficult to allow only a subset of the tuple to match?

Say if we don't care for the score, it could be left out. Not a big
issue up front, but say that m.search would like to expand the tuple
and also return a popularity ranking value, {id, score, popularity}

As it is, either all templates needs update to accommodate the new
tuple member, or, the implementation needs to be done so that the new
format is only used when explicitly requested.
The latter may be the best option, but overtime it could cause the api
to become quite cumbersome.

//Andreas

Ps.
This is the reason that I wrote: "One way would be to have the filter
return a tuple with all data parsed out, but that is a bit too rigid,
and doesn't welcome future changes."
--http://blog.astekk.se/article/347/writing-your-own-zotonic-module-part-iv


2011/6/7 Marc Worrell <mwor...@me.com>:

douglas

unread,
Jun 7, 2011, 9:09:19 AM6/7/11
to zotoni...@googlegroups.com
is the "don't care" syntax available here?
{A,_,_,B} = MYlist
will only bind A , B here
is that correct?

Andreas Stenius

unread,
Jun 7, 2011, 11:01:02 AM6/7/11
to zotoni...@googlegroups.com
Hi Douglas,

No, it is (django) template syntax, so it is as Marc wrote:

id, score in list

What the "don't care" syntax should look like is yet to be decided, if
it is going to be implemented.

//Andreas

2011/6/7 douglas <dvdo...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages