Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API search for facility and pagination #921

Closed
dickoa opened this issue Apr 25, 2017 · 3 comments
Closed

API search for facility and pagination #921

dickoa opened this issue Apr 25, 2017 · 3 comments
Labels
Milestone

Comments

@dickoa
Copy link

dickoa commented Apr 25, 2017

Hi everyone,

Thanks again for the healthsites project, we really love it at HDX.

I was testing the API and how to search for healthsites by name or placename and found something odd.
When you search by placename the page parameter works well and you have 100 healthsites (or less) per page as documented.

However, when you search healthsites by name, it looks like the pagination doesn't work. For example, this query gives all the healthsites with "chu" in their name (689 healthsites as of 25th April 2017)

https://healthsites.io/api/v1/healthsites/search?search_type=facility&name=CHU&format=json&page=1

I also want to add that it would be great if we can have the number of page in the metadata, a kind of summary or a limit parameter to control the number of healthsites we want per page. I think it is quite related to #920

Thanks again and let me know how I can help

Best,

@dickoa
Copy link
Author

dickoa commented Apr 26, 2017

Hi everyone,

Not sure, but I think we need to modify this part:

https://github.com/healthsites/healthsites/blob/develop/django_project/api/views/locality_search.py#L92-L95

Using the same approach for placename i.e:

https://github.com/healthsites/healthsites/blob/develop/django_project/api/views/locality_search.py#L33-L36

Let me know if I can do something to help

@markherringer markherringer assigned Gustry and unassigned timlinux Apr 26, 2017
@meomancer
Copy link
Collaborator

hi @dickoa
yes, i missed it
the solution from you is correct, i much appreciate if you could update it.

@dickoa
Copy link
Author

dickoa commented Apr 27, 2017

Just to be sure that we are saying the same thing, shoudl this be sufficient ?

        elif search_type == "facility":
            facilities = Locality.objects.filter(name__icontains=place_name)
            
            if self.page:   
                facilities = self.get_query_by_page(facilities, self.page)
            else:
                facilities = facilities[:100]
            
            facilities = self.query_to_json(facilities, self.format)
            return self.api_response(facilities)

If yes I can add it ASAP.
I am not a Django dev, so setting up an env will take probably some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants