Skip to main content

redisearch_api/
lib.rs

1use std::os::raw::c_int;
2
3#[macro_use]
4extern crate bitflags;
5
6#[macro_use]
7extern crate enum_primitive_derive;
8
9use redis_module::raw as rawmod;
10
11mod document;
12mod index;
13pub mod raw;
14
15pub use document::Document;
16pub use index::{Index, TagOptions};
17
18bitflags! {
19    pub struct FieldType: u32 {
20        const FULLTEXT = raw::RSFLDTYPE_FULLTEXT;
21        const NUMERIC = raw::RSFLDTYPE_NUMERIC;
22        const GEO = raw::RSFLDTYPE_GEO;
23        const TAG = raw::RSFLDTYPE_TAG;
24    }
25}
26
27pub fn get_c_api_version() -> i32 {
28    unsafe { raw::RediSearch_GetCApiVersion() }
29}
30
31pub extern "C" fn init(raw_ctx: *mut rawmod::RedisModuleCtx) -> c_int {
32    let ctx = redis_module::Context::new(raw_ctx);
33    ctx.log_debug("Initializing RediSearch...");
34
35    let result = unsafe { raw::RediSearch_Init(raw_ctx, raw::REDISEARCH_INIT_LIBRARY as c_int) };
36
37    if result == rawmod::REDISMODULE_OK as c_int {
38        ctx.log_debug("RediSearch initialized successfully.");
39    } else {
40        ctx.log_debug("Failed initializing RediSearch.");
41    }
42
43    result
44}