Discourses API get just the number of search results

Hi. I am trying to get just the number of search results from the API.
I have the following query /search.json?q=query but i just need information about how many results there are. Not blurbs, cooked, etc.
Is it possible with discourse API?

1 Like

I don’t think we return a “count” in the response, but it is something you can calculate yourself.

See the search API docs for a more detailed response example, but it will look something like this:

    "posts": [],
    "topics": [],
    "users": [],
    "categories": [],
    "grouped_search_result": {}

Be default the API will return a max of 50 results. To calculate the count you need to just count the number of items in the posts array. The number items in the topics array should be the same so there is no reason to count that array too.


I’m trying every way I can think of to just download all the topics and posts from my site - latest and top are limited, and I’m now trying getting all categories, and doing a search for the category (akin to how I can in the site). For example, in our site if I search for Q&A #q-a here I get over 50 results. When I search for that exact string with the discourse_api ruby gem, I get only 5:

irb(main):123:0> topics["posts"].length
=> 5
irb(main):124:0> topics["topics"].length
=> 5

Why is this not consistent with the interface and with what you are reporting? What is the easiest way to export data? I’d like to do some NLP on our site’s content and it’s proving to be very hard just to get the data. Thanks!