Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Initial /api/searchLocations API #367

Closed
simonw opened this issue Apr 20, 2021 · 10 comments
Closed

Initial /api/searchLocations API #367

simonw opened this issue Apr 20, 2021 · 10 comments
Labels
api Anything under /api/ enhancement New feature or request search

Comments

@simonw
Copy link
Collaborator

simonw commented Apr 20, 2021

We need a basic search API with the following features:

  • Export everything (maybe by paginating, maybe even in one big authenticated lump) - needed for all sorts of productive import/matching/processing scripts
  • Search by term (initially probably with LIKE but we can add PostgreSQL FTS soon afterwards)
  • Search by concordance IDs

This issue is to get a basic framework up and running with those features. Will be adding plenty more features later on as and when we need them.

@simonw simonw added enhancement New feature or request api Anything under /api/ labels Apr 20, 2021
@simonw
Copy link
Collaborator Author

simonw commented Apr 20, 2021

Initial design:

GET /api/searchLocations

Arguments:

  • ?q= - search term, applied against name (and maybe against address too)
  • ?latitude=&longitude=&radius= - search within a specific radius - using https://til.simonwillison.net/postgresql/closest-locations-to-a-point initially, later sped up using GeoDjango and PostGIS
  • ?state=CA
  • ?idref=concordance_id - an ID within the concordances table - can be passed multiple times for an OR search (or can be passed a comma-separated list)
  • ?format= specify output format - you can use geojson or nlgeojson here, default is regular JSON. Might even support CSV.
  • ?size=10 - to retrieve the first ten results
  • ?all=1 - to stream ALL results, using the streaming keyset pagination mechanism I built in c340bd2

@simonw
Copy link
Collaborator Author

simonw commented Apr 20, 2021

Default JSON shape will be:

{
  "results": [
    {"id": "...", "name": "..."},
    {"id": "...", "name": "..."},
    {"id": "...", "name": "..."}
  ],
  "total": 1023
}

This leaves room to add extra keys for things like pagination later.

@simonw
Copy link
Collaborator Author

simonw commented Apr 20, 2021

This will start out unauthenticated but we may want to start requiring Authorization: Bearer xxx authentication later on, especially for expensive operations like ?all=1.

@simonw
Copy link
Collaborator Author

simonw commented Apr 20, 2021

Now live on staging, docs here: https://vial-staging.calltheshots.us/api/docs#get-apisearchlocations

@simonw
Copy link
Collaborator Author

simonw commented Apr 21, 2021

Concordances are now populated, so this API can grow options to search by concordance ID reference.

@simonw
Copy link
Collaborator Author

simonw commented Apr 21, 2021

For concordance filtering this works:

locations = Location.objects.filter(
    concordances__in=ConcordanceIdentifier.objects.filter(
      Q(authority = 'cvs', identifier='#11344') | Q(authority = 'google_places', identifier='ChIJ3S7I3CE9hYARLpUyyZ21Q2A')
    )
)

@simonw
Copy link
Collaborator Author

simonw commented Apr 21, 2021

I'm going to try and get the streaming option to work next. I'm bumping the lat/lon/radius thing to another ticket.

@simonw
Copy link
Collaborator Author

simonw commented Apr 22, 2021

@simonw
Copy link
Collaborator Author

simonw commented Apr 22, 2021

?all=1 is now live on staging!

curl 'https://vial-staging.calltheshots.us/api/searchLocations?all=1' > /tmp/wat.json

... that seemed to work! It gave me a 8MB JSON file with 10,562 locations in it

~ % cat /tmp/wat.json| jq .results | jq length
10562

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api Anything under /api/ enhancement New feature or request search
Projects
None yet
Development

No branches or pull requests

2 participants