I’m pleased to announce that the SingAboutScience.org database now has a “limit search results to songs for a specific age range” feature. This should make it easier for teachers, parents, and others to find songs that are suitable for their specific target audiences. Try it out and let me know what you think!
In implementing this feature, I first assigned a minimum age and maximum age to each song in the database. (These do NOT represent the full range of ages that might enjoy the song, but rather my guess as to the “ideal” target audience.) I then added a pair of boxes to the search page where users can specify the minimum and maximum ages of interest to them. The user-entered values are then compared with each song’s age range, and songs whose ranges overlap with the searched-for range get included in the results (assuming that they also meet any other criteria specified by the user).
Conceptually, this is not difficult to understand. If a user searches for songs for ages 4-9, a song with an age range of 8-11 will be considered a match because the two ranges overlap. Likewise, a search for ages 17-22 would match a song for ages 14-17. However, writing the MySQL commands corresponding to the concept of “overlap” proved a bit trickier than I had imagined — mostly because, for any given search/song comparison, you don’t know in advance whether the search range will be to the left of the song range or vice versa. What turned out to work in all cases was the following: Include song in search results IF Search_max ≥ Song_min AND Song_max ≥ Search_min.