Page MenuHomePhabricator

API: Change default ordering of page titles namespace
Closed, ResolvedPublic3 Story Points

Description

Instead of ordering by title, we should change It so that pages get ordered in the following way:

  • Firstly by namespace. e.g. NS_MAIN articles first, followed by NS_TALK, NS_USER etc.. ...
  • Secondly by title

FYI: Note ideally we would sort by time they were added to the collection but we'll do that later. See T95786

Event Timeline

Jdlrobson raised the priority of this task from to Needs Triage.
Jdlrobson updated the task description. (Show Details)
Jdlrobson added a project: Gather.
Jdlrobson added subscribers: Aklapper, Yurik, Jdlrobson.
Jdlrobson moved this task from Needs triage to This Sprint on the Gather board.Apr 16 2015, 5:39 PM
Jdlrobson renamed this task from API: Support ordering by namespace to API: Change default ordering of page titles namespace.Apr 16 2015, 5:47 PM
Jdlrobson updated the task description. (Show Details)
Jdlrobson set Security to None.
Jdlrobson edited a custom field.

@Yurik this should be trivial to do right?

Jdlrobson updated the task description. (Show Details)Apr 16 2015, 5:47 PM
Yurik added a comment.Apr 16 2015, 5:48 PM

Which query? please provide a sample api call

Jdlrobson edited a custom field.Apr 27 2015, 6:05 PM
Jdlrobson moved this task from In Analysis to Ready for dev on the Gather Sprint Greatest Hits board.

@Yurik query would be like http://localhost:8888/w/api.php?action=query&list=listpages&lspid=18
Current response

{
    "query": {
        "listpages": [
            {
                "ns": 2,
                "title": "User:Jdlrobson"
            },
            {
                "ns": 0,
                "title": "Headings"
            },
            {
                "ns": 3,
                "title": "User talk:Jdlrobson"
            },
            {
                "ns": 8,
                "title": "MediaWiki:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson 2"
            },
            {
                "ns": 1,
                "title": "Talk:Jdlrobson"
            }
        ]
    }
}

Expected response:

{
    "query": {
        "listpages": [
            {
                "ns": 0,
                "title": "Headings"
            },
            {
                "ns": 1,
                "title": "Talk:Jdlrobson"
            }
            {
                "ns": 2,
                "title": "User:Jdlrobson"
            },
            {
                "ns": 3,
                "title": "User talk:Jdlrobson"
            },
            {
                "ns": 8,
                "title": "MediaWiki:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson 2"
            }
        ]
    }
}

I was hoping https://gist.github.com/jdlrobson/cc3ed6592b3334d66a57 would do it but it seems the API takes over sorting of the results... what am I doing wrong?

Yurik added a comment.Apr 28 2015, 1:49 AM

When used as a generator, there is no real sorting. Just like it doesn't
matter in what order you give the "titles" parameter. Your approach would
work for non generator use, and for generator, the "sets" of pages it will
return will be in the right order, but not the titles themselves inside one
result. In other words, simply sort them on the client.

You will have to fix the patch to also order by title, because gli_order is
a unique field, but namespace is not. So continuation is broken

sigh.
Why does the generator not have a concept of sorting? I'd need to do this both on frontend and client and that just sounds horrible.

Yurik added a comment.Apr 30 2015, 3:01 AM

Generator does have a concept of sorting - it yields batches of page titles
in the given order. The output's <pages> xml/JSON element is a dictionary
of

{pageid:{page properties}, ...}``` elements, so they get sorted by the
numeric ID of the page.
Tgr claimed this task.Apr 30 2015, 4:56 PM
Jdlrobson moved this task from This Sprint to In sprint on the Gather board.Apr 30 2015, 5:35 PM

Change 209123 had a related patch set uploaded (by Gergő Tisza):
Add sort "namespace,title" sort option for listpages

https://gerrit.wikimedia.org/r/209123

Tgr added a comment.May 5 2015, 8:57 PM

Why does the generator not have a concept of sorting? I'd need to do this both on frontend and client and that just sounds horrible.

Filed as T98205.

Tgr added a comment.May 5 2015, 9:18 PM

Patch could use more tests, I'll get back to that.

Moving out of sprint. Seems close to completion though so hopefully with those tests we can get this merged sometime soon.

Change 209123 merged by jenkins-bot:
Add sort "namespace,title" sort option for listpages

https://gerrit.wikimedia.org/r/209123

phuedx closed this task as Resolved.Jun 11 2015, 10:37 AM
phuedx added a subscriber: phuedx.

I verified this locally.