Implemented filtering.
This took quite a bit longer than I thought it would. A simple filter turns out to be not so simple after all…
The first part is code that runs on the client and adds/removes values from the URL queries. For example, if I want to search for interfaces from 1984, it adds ?year=1984
to the URL. It can also do multiple values for the same query, so it can add like so: ?year=1984,1990
. Other attributes can also be added: ?year=1984,1990&os=macos-system-6
. This code ends up being quite compact thanks to the use of the URLSearchParams
class.
The second part is the code that runs on the server and does the actual filtering. Last week I wrote that it was easy to do pagination because all I'm working with is a list of markdown files. Unfortunately, having just a list of files made searching a bit trickier; rather than a database search I had to implement my own method. I ended up creating lookup tables for each of the attributes that can be filtered, then compiling a list of all matching items and sorting by number of attributes matching the query. It's not the fastest possible implementation, but it's fast enough and more importantly short and manageable.