mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
Store the schema in the main index
This commit is contained in:
parent
df2ef8d2e1
commit
88d0d3931c
@ -1,6 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
use meilidb_schema::Schema;
|
||||||
use rkv::Value;
|
use rkv::Value;
|
||||||
use crate::{RankedMap, MResult};
|
use crate::{RankedMap, MResult};
|
||||||
|
|
||||||
@ -43,6 +44,33 @@ impl Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn put_schema(
|
||||||
|
&self,
|
||||||
|
writer: &mut rkv::Writer,
|
||||||
|
schema: &Schema,
|
||||||
|
) -> MResult<()>
|
||||||
|
{
|
||||||
|
let bytes = bincode::serialize(schema)?;
|
||||||
|
let blob = Value::Blob(&bytes[..]);
|
||||||
|
self.main.put(writer, SCHEMA_KEY, &blob)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn schema(
|
||||||
|
&self,
|
||||||
|
reader: &impl rkv::Readable,
|
||||||
|
) -> MResult<Option<Schema>>
|
||||||
|
{
|
||||||
|
match self.main.get(reader, SCHEMA_KEY)? {
|
||||||
|
Some(Value::Blob(bytes)) => {
|
||||||
|
let schema = bincode::deserialize_from(bytes.as_ref())?;
|
||||||
|
Ok(Some(schema))
|
||||||
|
},
|
||||||
|
Some(value) => panic!("invalid type {:?}", value),
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn put_ranked_map(
|
pub fn put_ranked_map(
|
||||||
&self,
|
&self,
|
||||||
writer: &mut rkv::Writer,
|
writer: &mut rkv::Writer,
|
||||||
|
Loading…
Reference in New Issue
Block a user