Celestial Searches

Aug 29, 2021 – To the API and back again

See the code for this post on GitHub

With the current state of the app, the user can now search for celestial objects in an autocomplete search box, choose the desired result, and save it with their observation data. Reaching that goal involved three distinct efforts: 1) finding a good dataset of celestial objects and storing it in a CosmosDB container, 2) implementing an Azure Function for querying that data and returning the results, and 3) implementing a Svelte component for the search UI.

The dataset I ended up using comes from OpenNGC, an open source aggregation of different celestial object catalogs. It's raw CSV data, so I needed to convert it to JSON before migrating it to a CosmosDB container. It has pretty much all of the data for objects that I'm interested in at the moment: its positions in the sky (right ascension and declination), its official catalog name (like NGC1976), and other common names (like "Orion Nebula").

I wrote the Azure Function for the API endpoint in C#. I went that route because it's the language I currently use the most in my day job and I'm quite comfortable with it. I considered writing it in Node.JS instead, and I might switch to Node for future Azure Functions, but that's the beauty of using Functions for the back-end—I can mix and match runtimes as I see fit! The Function queries the data's name field for the search term, as well as the Common names field.

Warning: Astronomy nerd talk incoming! One issue I'll need to solve for: if a user searches by Messier catalog designation, like "M13" or "messier 13", they won't get any results. That's because the dataset has a separate m field, whose value is just an integer corresponding to the Messier number. I'll have to either modify the query logic to account for searches like that, or modify the dataset to take the m value and add it to the Common names collection in the form of "M13", "Messier 13", etc. For a commercial product, this would be a showstopping bug. But for my purposes here, it's something I can save for a rainy day.

Once I had the Azure Function querying the CosmosDB and returning results in a form I expected, it was pretty straightforward to hook up a third-party Svelte autocomplete search component. I ended up going with one appropriately called Simple Svelte Autocomplete. It's a pretty simple drop-in solution in my Observation form component. A couple tweaks of the default settings and a couple small style hacks to get it to match the rest of the form, and I had a pretty good solution to my "celestial object search" problem.

The next major issues I want to tackle are user authentication and data persistence. I'm pretty certain I'll continue using CosmosDB for the data, but I'm not very familiar with what Azure has to offer in terms of authentication. My next step will be to do a little research around that.

© 2022 Andrew Iafrate. Contact me for questions or comments.