Improves usage of shared indexes

This commit is contained in:
Pedro Turik Firmino 2024-11-04 17:26:50 -03:00
parent c79ca9679b
commit d0b1ba20cb
2 changed files with 33 additions and 29 deletions

View file

@ -389,3 +389,23 @@ pub static VECTOR_DOCUMENTS: Lazy<Value> = Lazy::new(|| {
},
])
});
pub async fn shared_index_with_test_set() -> &'static Index<'static, Shared> {
static INDEX: OnceCell<Index<'static, Shared>> = OnceCell::const_new();
INDEX.get_or_init(|| async {
let server = Server::new_shared();
let index = server._index("SHARED_TEST_SET").to_shared();
let url = format!("/indexes/{}/documents", urlencoding::encode(index.uid.as_ref()));
let (response, code) = index
.service
.post_str(
url,
include_str!("../assets/test_set.json"),
vec![("content-type", "application/json")],
)
.await;
assert_eq!(code, 202);
index.wait_task(response.uid()).await;
index
}).await
}