ORDER BY in query doesn't work

Enonic version: 6.15.5
OS: Linux

I have a simple query:

query = "fulltext('_allText', 'test~0', 'AND')";

This works fine. However, I want to order the results based on modifiedDate, so I added this:

query = "fulltext('_allText', 'test~0', 'AND') ORDER BY modifiedTime DESC";

This looks like a valid query based on all the examples I can find in the documentation, but when I execute the query I get this error:

line 1, column 42: AND, OR or EOF expected, ORDER encountered. (com.enonic.xp.resource.ResourceProblemException)

This is the context, in case it’s relevant:

var results = libs.content.query({
    start: start,
    count: postsPerPage,
    query: query,   // <- "fulltext('_allText', 'test~0', 'AND') ORDER BY modifiedTime DESC"
    contentTypes: [
        app.name + ':article',
        app.name + ':employee',
        app.name + ':employeeList',
        app.name + ':landing-page',
        app.name + ':seminar',
        app.name + ':articlesCategory'
    ]
});

What am I doing wrong here?

Any reason to not use sort parameter as described here?

1 Like

I have never seen those docs before. I’ve been using this: https://xp.readthedocs.io/en/stable/developer/index.html

I don’t believe the sort parameter is ever mentioned in the readthedocs documentation.

I’ll try this as soon as possible, thanks for the reply.

API and Reference Guide -> Javascript Libraries, then click “Read in your browser” link at the bottom

https://xp.readthedocs.io/en/stable/reference/libraries/index.html

It’s easier to find in the new developer portal (for XP7 docs): https://developer.enonic.com/docs/xp/stable/api/lib-content#query