Implement album and track searching

This commit is contained in:
Samuel Webb 2024-04-11 17:22:24 -04:00
parent 8f34815904
commit fa4c3a6eff
5 changed files with 18 additions and 12 deletions

Binary file not shown.

View file

@ -10,8 +10,13 @@ pub const getArtist = \\SELECT artist, plays FROM artists WHERE artist == ?
pub const getTrack = \\SELECT artist, track, album, plays FROM tracks WHERE track == ?
;
pub const getTrackSearch = \\SELECT url FROM artists WHERE artist == ?
pub const getTrackSearch = \\SELECT track, url, form FROM tracks WHERE track LIKE '%' || ? || '%'
;
pub const getArtistSearch = \\SELECT artist, url FROM artists WHERE artist LIKE '%' || ? || '%'
;
pub const getArtistSearch = \\SELECT artist, url, form FROM artists WHERE artist LIKE '%' || ? || '%'
;
pub const getAlbumSearch = \\SELECT album, url, form FROM albums WHERE album LIKE '%' || ? || '%'
;
pub const total_search = getArtistSearch ++ " UNION " ++ getAlbumSearch ++ " UNION " ++ getTrackSearch;

View file

@ -21,23 +21,25 @@ pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
const queryOrNull: ?[]const u8 = if (params.get("q")) |param| param.string.value else null;
if (queryOrNull) |query| {
// sql.search(query, db);
var artistSearch = try db.prepare(queries.getArtistSearch);
var artistSearch = try db.prepare(queries.total_search);
defer artistSearch.deinit();
const artistResults = try artistSearch.all(
struct {
artist: []u8,
url: []u8,
form: []u8,
},
arena.allocator(),
.{},
.{ .artist = query },
.{ .artist = query, .album = query, .track = query },
);
for (artistResults) |r| {
std.log.debug("artist: {s}, url: {s}", .{ r.artist, r.url });
try root.append(data.string(r.artist));
try root.append(data.string(r.url));
try root.append(data.string(r.form));
//std.log.debug("{s}", .{r});
}
} else {

View file

@ -4,15 +4,13 @@
<th>Album</th>
<th>Track</th>
</tr>
@zig ZIG
@zig {
for (zmpl.items(.array), 0..) |u,i| {
if(@mod(i,2)==0){
if(@mod(i,3)==0){
<tr>
<td id="artistUpdate"><a href={{zmpl.items(.array)[i+1].string.value}}>{{u}}</a></td>
<td id="albumUpdate">{{i}}</td>
<td id="trackUpdate"></td>
<td id={{zmpl.items(.array)[i+2].string.value}}><a href={{zmpl.items(.array)[i+1].string.value}}>{{u}}</a></td>
</tr>
}
}
ZIG
}
</table>