Topic on Extension talk:TextExtracts

For multiple titles, only the first title returns an extract

4
Jji (talkcontribs)

Hi there,

On Wikipedia (running 1.26mw6), when I use the API with multiple titles, an extract seems to be returned only for the first title. Example:

https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exchars=100&explaintext&titles=Earth|Mar&continue

{
    "continue": {
        "excontinue": 1,
        "continue": "||"
    },
    "query": {
        "pages": {
            "9228": {
                "pageid": 9228,
                "ns": 0,
                "title": "Earth",
                "extract": "Earth, also called the world and, less frequently, Gaia (and Terra in some works of science fiction)..."
            },
            "14640471": {
                "pageid": 14640471,
                "ns": 0,
                "title": "Mars"
            }
        }
    }

}

Only Earth got an extract, while Mars didn't. I saw similar results when I was using a generator to get a list of titles which I wanted extracts for - only the first one got an extract. Am I using the API incorrectly?

MaxSem (talkcontribs)

That's because you're requesting full extracts which is a potentially very slow operation. You might want to add &exintro to the URL since you want first 100 chars anyway. Ahem, and I might want to treat all "first N (characters|sentences)" requests as intro-only automatically :P

MaxSem (talkcontribs)
Jji (talkcontribs)

Thanks for your comment - and I'm leaving this reply only in case anyone else comes to this page and finds this discussion in the future:

I tried adding &exintro to the URL as you suggested initially, and I still only got an extract for the first title, which confused me. But then I looked at the documentation again and found the exlimit parameter, which defaults to 1, which I hadn't realized. I added &exlimit=2 and it worked, and when I then removed &exintro, it gave me the warning "exlimit was too large for a whole article extracts request, lowered to 1", which is probably what you were referring to!

TL,DR for future readers: add &exlimit=n to get multiple extracts, and use &exintro to make sure you actually get them.

Reply to "For multiple titles, only the first title returns an extract"