Upload 6 files
Browse files- .gitattributes +1 -0
- build.zig +50 -0
- build.zig.zon +56 -0
- dockerfile +18 -0
- src/database.json +3 -0
- src/main.zig +55 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
src/database.json filter=lfs diff=lfs merge=lfs -text
|
build.zig
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const std = @import("std");
|
2 |
+
|
3 |
+
pub fn build(b: *std.Build) void {
|
4 |
+
const target = b.standardTargetOptions(.{});
|
5 |
+
const optimize = b.standardOptimizeOption(.{});
|
6 |
+
const exe_mod = b.createModule(.{
|
7 |
+
.root_source_file = b.path("src/main.zig"),
|
8 |
+
.target = target,
|
9 |
+
.optimize = optimize,
|
10 |
+
});
|
11 |
+
|
12 |
+
const exe = b.addExecutable(.{
|
13 |
+
.name = "newmine",
|
14 |
+
.root_module = exe_mod,
|
15 |
+
});
|
16 |
+
|
17 |
+
const ZigSmartSearch = b.dependency("ZigSmartSearch", .{
|
18 |
+
.target = target,
|
19 |
+
.optimize = optimize,
|
20 |
+
});
|
21 |
+
exe.root_module.addImport("ZigSmartSearch", ZigSmartSearch.module("ZigSmartSearch"));
|
22 |
+
|
23 |
+
const zap = b.dependency("zap", .{
|
24 |
+
.target = target,
|
25 |
+
.optimize = optimize,
|
26 |
+
.openssl = false, // set to true to enable TLS support
|
27 |
+
});
|
28 |
+
|
29 |
+
exe.root_module.addImport("zap", zap.module("zap"));
|
30 |
+
b.installArtifact(exe);
|
31 |
+
|
32 |
+
const run_cmd = b.addRunArtifact(exe);
|
33 |
+
run_cmd.step.dependOn(b.getInstallStep());
|
34 |
+
|
35 |
+
if (b.args) |args| {
|
36 |
+
run_cmd.addArgs(args);
|
37 |
+
}
|
38 |
+
|
39 |
+
const run_step = b.step("run", "Run the app");
|
40 |
+
run_step.dependOn(&run_cmd.step);
|
41 |
+
|
42 |
+
const exe_unit_tests = b.addTest(.{
|
43 |
+
.root_module = exe_mod,
|
44 |
+
});
|
45 |
+
|
46 |
+
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
47 |
+
|
48 |
+
const test_step = b.step("test", "Run unit tests");
|
49 |
+
test_step.dependOn(&run_exe_unit_tests.step);
|
50 |
+
}
|
build.zig.zon
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.{
|
2 |
+
// This is the default name used by packages depending on this one. For
|
3 |
+
// example, when a user runs `zig fetch --save <url>`, this field is used
|
4 |
+
// as the key in the `dependencies` table. Although the user can choose a
|
5 |
+
// different name, most users will stick with this provided value.
|
6 |
+
//
|
7 |
+
// It is redundant to include "zig" in this name because it is already
|
8 |
+
// within the Zig package namespace.
|
9 |
+
.name = .newmine,
|
10 |
+
|
11 |
+
// This is a [Semantic Version](https://semver.org/).
|
12 |
+
// In a future version of Zig it will be used for package deduplication.
|
13 |
+
.version = "0.0.0",
|
14 |
+
|
15 |
+
// Together with name, this represents a globally unique package
|
16 |
+
// identifier. This field is generated by the Zig toolchain when the
|
17 |
+
// package is first created, and then *never changes*. This allows
|
18 |
+
// unambiguous detection of one package being an updated version of
|
19 |
+
// another.
|
20 |
+
//
|
21 |
+
// When forking a Zig project, this id should be regenerated (delete the
|
22 |
+
// field and run `zig build`) if the upstream project is still maintained.
|
23 |
+
// Otherwise, the fork is *hostile*, attempting to take control over the
|
24 |
+
// original project's identity. Thus it is recommended to leave the comment
|
25 |
+
// on the following line intact, so that it shows up in code reviews that
|
26 |
+
// modify the field.
|
27 |
+
.fingerprint = 0x1dc2467f30372256, // Changing this has security and trust implications.
|
28 |
+
|
29 |
+
// Tracks the earliest Zig version that the package considers to be a
|
30 |
+
// supported use case.
|
31 |
+
.minimum_zig_version = "0.14.0",
|
32 |
+
|
33 |
+
// This field is optional.
|
34 |
+
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
35 |
+
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
36 |
+
// Once all dependencies are fetched, `zig build` no longer requires
|
37 |
+
// internet connectivity.
|
38 |
+
.dependencies = .{
|
39 |
+
.ZigSmartSearch = .{
|
40 |
+
.url = "https://github.com/RohanVashisht1234/ZigSmartSearch/archive/refs/tags/v0.0.1.tar.gz",
|
41 |
+
.hash = "ZigSmartSearch-0.0.1-AAAAAN0IkABROXK7FlkeqbIFedYvV4GAaCR6NVO7zKNx",
|
42 |
+
},
|
43 |
+
.zap = .{
|
44 |
+
.url = "git+https://github.com/zigzap/zap?ref=v0.10.6#e1c973d5e2b282c673d91d857459cc389eab80bb",
|
45 |
+
.hash = "zap-0.10.6-GoeB89aDJAAUufiqV7sUCudCoSSCle0E2fbw388bO1Ug",
|
46 |
+
},
|
47 |
+
},
|
48 |
+
.paths = .{
|
49 |
+
"build.zig",
|
50 |
+
"build.zig.zon",
|
51 |
+
"src",
|
52 |
+
// For example...
|
53 |
+
//"LICENSE",
|
54 |
+
//"README.md",
|
55 |
+
},
|
56 |
+
}
|
dockerfile
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use the official Zig image as the base
|
2 |
+
FROM ziglang/zig:0.14.0
|
3 |
+
|
4 |
+
# Set working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Copy the Zig source files
|
8 |
+
COPY . .
|
9 |
+
|
10 |
+
# Build the Zig application
|
11 |
+
RUN zig build -Doptimize=ReleaseFast
|
12 |
+
|
13 |
+
# Expose port 3000
|
14 |
+
EXPOSE 7860
|
15 |
+
|
16 |
+
# Run the application, binding to 0.0.0.0:7860
|
17 |
+
# run ./zig-out/bin/newmine
|
18 |
+
CMD ["./zig-out/bin/newmine"]
|
src/database.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:835297e98327c50bbed1c8b1da1a105eb55c36d9f454ec513baac784ffa56388
|
3 |
+
size 11753356
|
src/main.zig
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const std = @import("std");
|
2 |
+
const zap = @import("zap");
|
3 |
+
const ZigSmartSearch = @import("ZigSmartSearch").ZigSmartSearch;
|
4 |
+
const database = @embedFile("database.json");
|
5 |
+
const allocator = std.heap.c_allocator;
|
6 |
+
|
7 |
+
var instance: ZigSmartSearch = undefined;
|
8 |
+
|
9 |
+
fn on_request(r: zap.Request) !void {
|
10 |
+
if (r.query) |the_query| {
|
11 |
+
var results = try instance.search(the_query);
|
12 |
+
defer results.deinit();
|
13 |
+
if (results.items.len == 0) {
|
14 |
+
r.sendJson("[]") catch return;
|
15 |
+
return;
|
16 |
+
}
|
17 |
+
const res = try results.toOwnedSlice();
|
18 |
+
var arraylist = std.ArrayList(u8).init(allocator);
|
19 |
+
errdefer arraylist.deinit();
|
20 |
+
try arraylist.append('[');
|
21 |
+
for (res) |result| {
|
22 |
+
try arraylist.append('"');
|
23 |
+
try arraylist.appendSlice(result.doc.get("title").?.string);
|
24 |
+
try arraylist.append('"');
|
25 |
+
try arraylist.append(',');
|
26 |
+
}
|
27 |
+
_ = arraylist.pop(); // remove last comma
|
28 |
+
try arraylist.append(']');
|
29 |
+
const result = try arraylist.toOwnedSlice();
|
30 |
+
defer allocator.free(result);
|
31 |
+
r.sendJson(result) catch return;
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
pub fn main() !void {
|
36 |
+
instance = try ZigSmartSearch.init(
|
37 |
+
allocator,
|
38 |
+
database,
|
39 |
+
ZigSmartSearch.default_config,
|
40 |
+
);
|
41 |
+
var listener = zap.HttpListener.init(.{
|
42 |
+
.port = 7860,
|
43 |
+
.on_request = on_request,
|
44 |
+
.log = true,
|
45 |
+
});
|
46 |
+
try listener.listen();
|
47 |
+
|
48 |
+
std.debug.print("Listening on 0.0.0.0:7860\n", .{});
|
49 |
+
|
50 |
+
// start worker threads
|
51 |
+
zap.start(.{
|
52 |
+
.threads = 2,
|
53 |
+
.workers = 2,
|
54 |
+
});
|
55 |
+
}
|