Implement searching no tag
This commit is contained in:
parent
4d9f3e32e2
commit
b0f730d162
|
@ -60,7 +60,7 @@ pub fn main() !void {
|
||||||
// -------------------- QUERY ---------------------------
|
// -------------------- QUERY ---------------------------
|
||||||
|
|
||||||
const jsonQuery: [:0]const u8 =
|
const jsonQuery: [:0]const u8 =
|
||||||
\\{ "query" : "fur made_with:krita date:2022", "limit" : 20 }
|
\\{ "query" : "" }
|
||||||
;
|
;
|
||||||
|
|
||||||
var jquery = json.Obj.newFromString(jsonQuery);
|
var jquery = json.Obj.newFromString(jsonQuery);
|
||||||
|
|
|
@ -63,9 +63,6 @@ pub fn query(jobj: *json.Obj, db: *Db, allocator: std.mem.Allocator) !json.Obj {
|
||||||
const query_str = jobj.getString();
|
const query_str = jobj.getString();
|
||||||
var jret = json.Obj.newArray();
|
var jret = json.Obj.newArray();
|
||||||
|
|
||||||
// Go through each tag
|
|
||||||
var tag_iter = std.mem.split(u8, query_str, " ");
|
|
||||||
|
|
||||||
var ids = std.ArrayList([]u8).init(allocator);
|
var ids = std.ArrayList([]u8).init(allocator);
|
||||||
defer {
|
defer {
|
||||||
for (ids.items) |item| {
|
for (ids.items) |item| {
|
||||||
|
@ -74,6 +71,9 @@ pub fn query(jobj: *json.Obj, db: *Db, allocator: std.mem.Allocator) !json.Obj {
|
||||||
ids.deinit();
|
ids.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query_str.len > 0) {
|
||||||
|
// Get all the items under the individual tags
|
||||||
|
var tag_iter = std.mem.split(u8, query_str, " ");
|
||||||
while (tag_iter.next()) |tag| {
|
while (tag_iter.next()) |tag| {
|
||||||
// Get the tag selector: "tag:<tag>"
|
// Get the tag selector: "tag:<tag>"
|
||||||
const tag_sel = try std.mem.concat(allocator, u8, &[_][]const u8{ "tag:", tag });
|
const tag_sel = try std.mem.concat(allocator, u8, &[_][]const u8{ "tag:", tag });
|
||||||
|
@ -85,6 +85,9 @@ pub fn query(jobj: *json.Obj, db: *Db, allocator: std.mem.Allocator) !json.Obj {
|
||||||
// This has been deferred before.
|
// This has been deferred before.
|
||||||
//defer Db.free(tag_str.ptr);
|
//defer Db.free(tag_str.ptr);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
try ids.append(db.get("item") orelse return jret);
|
||||||
|
}
|
||||||
|
|
||||||
var id_iter = util.intersection(ids.items);
|
var id_iter = util.intersection(ids.items);
|
||||||
while (id_iter.next()) |item_id| {
|
while (id_iter.next()) |item_id| {
|
||||||
|
|
Loading…
Reference in New Issue