Peculiar ordering - company search

Hi -

When querying https://api.companieshouse.gov.uk/search it returns a list of results. These appear to be nicely sorted by how close the company name is to my search parameter. Let’s call these results search_results.

When using the items_per_page parameter and setting it to 1, I would expect to get back the same result as index zero of search_results. However it’s a different company.

Why is this the case? What’s the logic behind the ordering of companies?

Best,
George

Short: don’t set items_per_page=1 without also specifying start_index (e.g. start_index=0)

Long-standing bug - see my notes at:

…it looks like someone changed the behaviour here because even further back you would get no results at all if you did this (although the fields would suggest there were).

I just tried this and indeed this issue is still occurring as described:
All as expected for e.g. items_per_page=2 (and up)

curl -uMY_API_KEY_: "https://api.companieshouse.gov.uk/search?q=kirklands&items_per_page=2"

{
    "start_index": 0,
    "total_results": 31,
    "kind": "search#all",
    "items_per_page": 2,
    "page_number": 1,
    "items": [
        {
            "description": "00620610 - Incorporated on  9 February 1959",
            "kind": "searchresults#company",
            "company_number": "00620610",
            "title": "KIRKLANDS LIMITED"
            ...
        },
        {
            "title": "KIRKLANDS BUSINESS SOLUTIONS LIMITED",
            "company_number": "SC229764",
            "kind": "searchresults#company",
            "description": "SC229764 - Incorporated on 28 March 2002"
            ...
        }
    ]
}

Different first (and only) item for items_per_page=1. Note the change in start_index - now 1 (but 0 above).

curl -uMY_API_KEY: "https://api.companieshouse.gov.uk/search?q=kirklands&items_per_page=1"

{
    "page_number": 2,
    "kind": "search#all",
    "total_results": 31,
    "items_per_page": 1,
    "start_index": 1,
    "items": [
        {
            "title": "KIRKLANDS BUSINESS SOLUTIONS LIMITED",
            "company_number": "SC229764",
            "company_status": "active",
            "kind": "searchresults#company",
            ...
        }
    ]
}

Good spot.

I ended up setting items_per_page to 2 and just taking the item at index zero to circumnavigate this for now.