Forums / Developer / Alpha pagination of objects

Alpha pagination of objects

Author Message

Bruce Morrison

Thursday 04 September 2003 12:51:27 am

I'm looking to implement a site where content is paginated by the first letter of it's name.

For example. On the top page there is the "0-9 A B C D E F....X Y Z" Each linked to a page showing only those objects whose name starts with the letter chosen. (An example may be a list of users - like a contact list)

I could set the backend structure up so that there were subfolders starting with each letter, but I would then have to reply on the person entering the content to place the data in the correct folder (or workflow). It also means that the display is determined by the layout of the data in the backend and any changes in the design would require a change in the structure.

While the google navigator is great for search results, it's not the best for pagination of a list of 500 products.

Any ideas on the best way of approaching this?

(I've started writing an extension to handle this)

Cheers
Bruce
designIT

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Paul Forsyth

Thursday 04 September 2003 1:14:56 am

Are you saying you have a way to return search results according to pagination, or that you have a problem with handling that many results?

For the size of results can you use the offset feature found in the advancedsearch scripts?

Paul

Bruce Morrison

Thursday 04 September 2003 2:19:51 am

Hi Paul

I'm after something like this
http://www.graduateopportunities.com/employers.php?id=D

In the admin section I want to have a single folder of contacts. In the user section I want to be able to display a "A....Z" navigation bar that when clicked on displays those contacts starting with the letter clicked.

The google navigator is used in the admin section to paginate child objects. This is great for browsing to a object but it can take several clicks to find the right page (and object).

In some cases it would be easier to be able to be able to alpha-page through these types of pages.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Paul Forsyth

Thursday 04 September 2003 3:04:28 am

Just noticed a typo in my post. I meant to ask if you *didn't* have a way of identifying which objects started with your letter of choice... Though i guess thats what you mean now.

Looking in the doco for fetch:

http://ez.no/developer/ez_publish_3/documentation/development/libraries/ez_template/operators/data_fetch

With 3.2 you can return results from a fetch by attribute. Now, it is feasible to return a list of objects by pattern matching on their name, like so:

fetch( 'content', 'list',
--------hash( parent_node_id, <node to start search from>,
----------------attribute_filter,
-------------------------array( 'or', array( <attribute id>, '=', 'a*' ),
--------------------------------------array( <attribute id>, '=', 'A*' ) )
--------------)
-------)

Here <attribute id> is the class attribute. ez3.2 displays this number if you edit the class you wish to sort by...

Now, im not sure this will work, but its worth a try :)

Hope you see what im doing here.

paul

Paul Borgermans

Thursday 04 September 2003 4:14:08 am

Don't forget to add the class_filter too before specifying attribute ids

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Jakub Chromy

Monday 08 December 2003 12:13:17 pm

The code below works for selecting nodes which attribute nr. 181 begins with k.

Hix

{section loop=fetch( 'content', 'list', hash( parent_node_id, 1118 , attribute_filter, array( 'or', array( 181, '>=', 'k' ) )) ) }

<a href={$:item.url_alias|ezurl}>{$:item.name}</a><br>

{/section}

steve walker

Wednesday 07 September 2005 1:08:46 pm

Hi there,

I'm looking to implement this for the contacts folder on the Ez Intranet.

Before I start coding, I don't suppose any one has already created the form/fetch combination you need for this?

Thanks, Steve.

http://www.oneworldmarket.co.uk

steve walker

Thursday 08 September 2005 10:14:15 am

Hi,

I've got this half working with:

                {set list_items=fetch_alias( children, hash( parent_node_id, $node.node_id,                                                             offset, $view_parameters.offset,                                                             sort_by, $node.sort_array,
'attribute_filter', array( 'or', array( 'person/last_name', '>=', 'a' )), 			
limit, $page_limit ) )}

but the problem is that this fetches last_name that include 'a', not those that start with the letter 'a'.

I've tried wildcards 'a*' with no joy...

For me Jakub's code above doesnt work, tho' I'm building on 3.6 and his comment is from 2003...

Any ideas on this one?

Thanks, Steve.

http://www.oneworldmarket.co.uk

Kristof Coomans

Thursday 08 September 2005 11:31:30 pm

Since eZ publish 3.6, the fetch functions content/list, content/list_count, content/tree
and content/tree_count have been given extra filter functionality.

Maybe you can use the "like" filter operation:

{set list_items=fetch( content, list, hash(
    parent_node_id, $node.node_id,
    offset, $view_parameters.offset,
    sort_by, $node.sort_array,                                                                                                       
    attribute_filter, array( 
        'or',
        array( 'person/last_name' 'like', 'a%' ) 
        ),
    limit, $page_limit
    )
)}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

steve walker

Friday 09 September 2005 1:00:02 am

Kristof,

Thanks for your reply. I have tried with the 'like' op but with no success.

Some combinations I've tried are:

Returns no results:

'attribute_filter', array( 'or', array( 'person/last_name', '=', 'A%' ) ),

'attribute_filter', array( 'or', array( 'person/last_name', '=', 'A*' ) ),

'attribute_filter', array( 'or', array( 'person/last_name', '=', 'A' ) ),

'attribute_filter', array( 'and', array( 'person/last_name', '=', 'A*' ) ),

'attribute_filter', array( 'and', array( 'person/last_name', '=', 'A' ) ),

Returns everything:

'attribute_filter', array( 'or', array( 'person/last_name', '>=', 'A' ) ),

'attribute_filter', array( 'or', array( 'person/last_name', '>=', 'A%' ) ),

'attribute_filter', array( 'and', array( 'person/last_name', '>=', 'A%' ) ),

I just cant get it to filter by the first letter only :(

I'm wondering, do I need to use '=' and tweak the 'first-letter+wildcard' combination? I cant see any info on wildcards in docs or forum.

Steve.

http://www.oneworldmarket.co.uk

Kristof Coomans

Friday 09 September 2005 1:27:26 am

Can you paste the code you used with the "like" filter operation? Maybe there was an error in it.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Friday 09 September 2005 1:33:55 am

I've made a mistake. The wildcard filter in the "like" filter operation is * instead of %.

So the correct code is:

{set list_items=fetch( content, list, hash(
    parent_node_id, $node.node_id,
    offset, $view_parameters.offset,
    sort_by, $node.sort_array,                                                                                                       
    attribute_filter, array( 
        'or',
        array( 'person/last_name' 'like', 'a*' ) 
        ),
    limit, $page_limit
    )
)}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

steve walker

Friday 09 September 2005 2:04:07 am

Hi Kristof,

Sorry, still no joy I'm afraid... I've got:

                {set list_items=fetch_alias( children, hash( parent_node_id, $node.node_id,                                                             offset, $view_parameters.offset,                                                             sort_by, $node.sort_array,
'attribute_filter', array( 'or', array( 'person/last_name' 'like', 'a*' ) ),			
limit, $page_limit ) )}

but it doesnt return any results - it should return one. I tried the 'a*' as an 'A*' in case it was a caps issue.

Steve.

http://www.oneworldmarket.co.uk

Eivind Marienborg

Friday 09 September 2005 4:57:30 am

This works for me:

{default fra=$view_parameters.fom
         til=$view_parameters.to}


{let children=fetch( content, list, hash( parent_node_id, $node.node_id,                      attribute_filter, array('and',array(241,'>='$from),array(241,'<=',$to))))

You'll have to adjust 241 to your attribute, of course.

Kristof Coomans

Friday 09 September 2005 5:25:45 am

How does the configuration of your fetch alias looks like? You can find it in fetchalias.ini, under the group [children]. By default, it doesn't support the <i>attribute_filter</i> parameter, so you will need to change it, or make your own alias.

[filtered_children]
Module=content
FunctionName=list
Parameter[sort_by]=sort_by
Parameter[parent_node_id]=parent_node_id
Parameter[offset]=offset
Parameter[limit]=limit
Parameter[attribute_filter]=attribute_filter

I never use <i>fetch_alias</i> myself. For the particular things you are trying to do, I don't think it has any added value and you can use <i>fetch</i> instead.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

steve walker

Wednesday 14 September 2005 9:46:18 am

Hi,

Well, you have to laugh... Now I've got the reverse problem, have got the code giving results but it wont filter the results at all :)))

Kristof, your code needed an extra ',', so:

array( 'person/last_name' 'like', 'a*' )

is

array( 'person/last_name', 'like', 'a*' )

Now I get results returned, but it gives the whole list. The current fetch I have is:

 {set list_items=fetch_alias( children, hash( parent_node_id, $node.node_id,                                                             offset, $view_parameters.offset,                                                             attribute_filter, $time_filter,			 array( 'or', array( 'person/last_name', 'like', 'a*' )),                                                          sort_by, $node.sort_array,                                                             limit, $page_limit ) )}

Like I say, it just doesnt filter at all now :-/ I get a full set of results.

I've added the

Parameter[attribute_filter]=attribute_filter

into the fetch_alias files...

Any other thoughts on this conundrum?

Thanks, Steve

http://www.oneworldmarket.co.uk

Kristof Coomans

Wednesday 14 September 2005 11:11:39 pm

Indeed it needs the ',', I must have looked over that.

There's a problem with your attribute filter. The correct code is:

{set list_items=fetch_alias( children, hash(
        parent_node_id, $node.node_id,                                                  
        offset, $view_parameters.offset,
        attribute_filter, array(
            'and',
            $time_filter,
            array( 'person/last_name', 'like', 'a*'  )
            ),
        sort_by, $node.sort_array,
        limit, $page_limit
        )
    )}

 

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Christiane Kloss

Thursday 15 September 2005 2:42:38 am

Hi Steve,

I had the same problem once...
Read carefully...
'attribute_filter', array( [condition] )
'attribute_filter', array( 'person/last_name' 'like', 'a*' )
or
'attribute_filter', array( array( [logic], [condition1], [condition2] ) )

'attribute_filter', array( 'or', array( 'person/last_name' 'like', 'a*' ), [cond2] )...

so in your code [condition2] was missing completly.
But it looks like you don't need it at all.

Cheers Christiane

steve walker

Thursday 15 September 2005 7:27:31 am

Hi,

Kristof, your code worked :), though I had to remove the ' $time_filter,' to get it to work.

{set list_items=fetch_alias( children, hash(
        parent_node_id, $node.node_id,                                                  
        offset, $view_parameters.offset,
        attribute_filter, array(
            'and',
            array( 'person/last_name', 'like', $filter  )
            ),
        sort_by, $node.sort_array,
        limit, $page_limit
        )
    )}

The only issue I now have is I have to clear the cache every time the sorting value is changed, other wise the value of $filter doesnt change.

I'm going to post that in a seperate thread as its a slightly different subject - once I get it all working I'll post back the complete folder template code here.

Thanks for all the help!

Steve.

http://www.oneworldmarket.co.uk

steve walker

Thursday 15 September 2005 7:32:58 am

Just found this post:

http://ez.no/community/forum/general/probleme_with_a_href

Has the caching reolution...

http://www.oneworldmarket.co.uk