Will,

when you run query w/o "order by" sort order is not guaranteed. If you want to 
enforce some order you need to add "order by" to your query. If you are getting 
different order of results even when enforcing the order then it would be a bug.

HTH,
Jan

On Nov 23, 2012, at 5:37 PM, Will Scheidegger <[email protected]> wrote:

> Dear Magnolia staff
> 
> I've just spent too much time tracking down a problem with 
> TemplatingFunctions.search(). I keep getting the results in reversed order. 
> Take this query for instance and run it in "Tools" > "JCR Queries":
> 
> select * from mgnl:contentNode where jcr:path like 
> '/demo-project/about/subsection-articles/large-article/content/%' AND 
> subtitle IS NOT NULL
> 
> You should end up with this:
> 
> /demo-project/about/subsection-articles/large-article/content/0
> /demo-project/about/subsection-articles/large-article/content/00
> /demo-project/about/subsection-articles/large-article/content/02
> 
> Compare it to the JCR tree and you will see that the order matches. Now 
> modify the template /templating-kit/pages/content/contentNavigation.ftl like 
> this:
> 
> [#if model.contentNavigation?exists]
>    <div id="nav-content">
>        [#if 
> content.title?has_content]<h3><em>${i18n['contentNavigation.index.title']} 
> </em>${content.title}</h3>[/#if]
>        [#list model.contentNavigation as item]
>        <ul>
>            <li><a href="${item.href}">${item.title}</a></li>
>        </ul>
>        [/#list]
>    </div><!-- end nav-content -->
> [/#if]
> 
> Test: 
> [#assign queryString = "select * from mgnl:contentNode where jcr:path like 
> '"+state.mainContent.@handle+"/content/%' AND subtitle IS NOT NULL" /]
> [#assign subTitleParagraphs = cmsfn.search("website", queryString, "sql", 
> "mgnl:contentNode") /]
> [#if subTitleParagraphs?has_content]
>    <div class="verticalNavi">
>        <ul>
>            [#list subTitleParagraphs as paragraph]  
>                <li>
>                       ${paragraph}
>                </li>
>            [/#list]  
>        </ul>
>    </div>
> [/#if]
> 
> Now, on my Mac, Magnolia 4.5.6 CE, Java 1.6.0_37, I'm getting the paragraphs 
> in reversed order. When I try the same on demoauthor.magnolia-cms.com 
> everything is fine!!!
> 
> I tracked this down to NodeUtil.getCollectionFromNodeIterator(NodeIterator 
> iterator) which runs through the iterator and stuffs everything an a HashSet 
> using the "add" method. When I change this method to use an ArrayList instead 
> of a HashSet, everything is fine! So this leads me to the conclusion, that 
> there must be a bug in my JDK. 
> 
> Now the questions at hand would be: 
> - Can I ignore the problem because I won't be deploying on the Mac anyways? 
> - Or does anyone see the same misbehavior on an other platform?
> - Is there a specific reason why you used HashSet instead of ArrayList?
> 
> Thanks!
> -will
> 
> 
> ----------------------------------------------------------------
> For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
> Alternatively, use our forums: http://forum.magnolia-cms.com/
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------



----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to