@Rubaru we are trying to run Rust based ‘probly_search’ library on IC for full text search. I am creating Rust base canister for this with following code
use core::str;
use std::{collections::HashMap, sync::{Mutex}};
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use probly_search::{
index::{add_document_to_index, create_index, remove_document_from_index, Index},
query::{
query,
score::default::{bm25, zero_to_one},
QueryResult,
},
};
use probly_search::query::*;
use ic_cdk_macros::update;
use std::panic;
thread_local! {
//static CANISTER_INDEX:RefCell<Index> = RefCell::new(create_index(1));
static CANISTER_INDEX:Index =create_index(1);
}
#[derive(Serialize, Deserialize, Clone)]
struct Doc
{
id: usize,
token:String,
}
fn tokenizer(s: &str) → Vec {
s.split(’ ')
.map(|slice| slice.to_lowercase())
.collect::<Vec>()
}
fn token_accesor(d: &Doc) → Option<&str> {
Some(d.token.as_str())
}
fn filter(s: &str) → String {
s.to_owned()
}
#[derive(Serialize, Deserialize)]
struct Result
{
document:Doc,
score:f64
}
#[update(name = “addIndex”)]
fn add_index(queryString: String) → bool {
let doc = Doc {
id: 0,
token: queryString.to_string(),
};
// let index1 = CANISTER_INDEX.with(|index| index.borrow());
add_document_to_index(
& CANISTER_INDEX,
&[token_accesor],
tokenizer,
filter,
doc.id,
doc.clone(),
);
return true;
}
but while doing so I am getting error
error[E0308]: mismatched types**
src/rust_hello_backend/src/lib.rs:66:9
add_document_to_index(
arguments to this function are incorrect**
&CANISTER_INDEX,
types differ in mutability**
expected mutable reference **&mut probly_search::index::Index<usize>**
found reference **&LocalKey<probly_search::index::Index<usize>>**
can anyone help me in pointing me out what i am doing wrong