Forum OpenACS Development: Re: ltree sorting

Collapse
2: Re: ltree sorting (response to 1)
Posted by Malte Sussdorff on
Related to this is the question, if I have the following structure

cat1.1
cat1.2
cat2.1
cat2.10
cat2.2
cat3.4
cat4.5

and I want to order by the second level (1,2,10 ...), though within the first level (cat1, cat2 ..) where the ordering of the first level is given, e.g. I want to say.

Order me all pages which by page_order, where the category order is "cat2 cat3 cat1 cat4"

This should return:

cat2.1
cat2.2
cat2.10
cat3.4
cat1.1
cat1.2
cat4.5

Any clue how I could do this ?

Collapse
3: Re: ltree sorting (response to 2)
Posted by Tom Jackson on
It is always a mistake to use one piece of data to serve two independent purposes. Bite the bullet and add a separate field to specify order. If it is a hierarchy, you have to be more careful in maintaining this field. I think it is perfectly okay to expose compound fields, like phone numbers, as a single field, but if you intend to select and sort by a sub-field, you need to consider the impact on performance. For instance, there is no logical difference with representing 2.1 as 1, parent 2. Then order by parent, then child as integers.

You obviously cannot achieve your goal with the above example without a separate field, which pretty much proves the point: don't mix purposes. You may also need some indication of level in a hierarchy.

Collapse
4: Re: ltree sorting (response to 2)
Posted by Gustaf Neumann on
The categories includelet has a new option which allows the associated items to be ordered by page_order in the human oriented way (1, 2, 3, ..., 10, ...). XoWiki has a mixin for providing the sorting (handles as well the subsection style like 1.1, 1.2, 1.3, ...., 1.10 etc). Altogether, the sorting is done first by categories and then for the items per category by the sort order. The new option can be used by e.g.

categories -order_items_by page_order,asc

Maybe this helps...