mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 08:44:27 +01:00
Merge pull request #173 from meilisearch/fix-ranked-map-set
Use the right ranked-map key name
This commit is contained in:
commit
3e1b81c4ce
@ -7,12 +7,17 @@ use crate::ranked_map::RankedMap;
|
|||||||
|
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
|
||||||
|
const SCHEMA_KEY: &str = "schema";
|
||||||
|
const WORDS_KEY: &str = "words";
|
||||||
|
const SYNONYMS_KEY: &str = "synonyms";
|
||||||
|
const RANKED_MAP_KEY: &str = "ranked-map";
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MainIndex(pub(crate) InnerRawIndex);
|
pub struct MainIndex(pub(crate) InnerRawIndex);
|
||||||
|
|
||||||
impl MainIndex {
|
impl MainIndex {
|
||||||
pub fn schema(&self) -> Result<Option<Schema>, Error> {
|
pub fn schema(&self) -> Result<Option<Schema>, Error> {
|
||||||
match self.0.get_pinned("schema")? {
|
match self.0.get_pinned(SCHEMA_KEY)? {
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
let schema = Schema::read_from_bin(bytes.as_ref())?;
|
let schema = Schema::read_from_bin(bytes.as_ref())?;
|
||||||
Ok(Some(schema))
|
Ok(Some(schema))
|
||||||
@ -24,12 +29,12 @@ impl MainIndex {
|
|||||||
pub fn set_schema(&self, schema: &Schema) -> Result<(), Error> {
|
pub fn set_schema(&self, schema: &Schema) -> Result<(), Error> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
schema.write_to_bin(&mut bytes)?;
|
schema.write_to_bin(&mut bytes)?;
|
||||||
self.0.set("schema", bytes)?;
|
self.0.set(SCHEMA_KEY, bytes)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn words_set(&self) -> Result<Option<fst::Set>, Error> {
|
pub fn words_set(&self) -> Result<Option<fst::Set>, Error> {
|
||||||
match self.0.get_pinned("words")? {
|
match self.0.get_pinned(WORDS_KEY)? {
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
let len = bytes.len();
|
let len = bytes.len();
|
||||||
let value = Arc::from(bytes.as_ref());
|
let value = Arc::from(bytes.as_ref());
|
||||||
@ -41,11 +46,11 @@ impl MainIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_words_set(&self, value: &fst::Set) -> Result<(), Error> {
|
pub fn set_words_set(&self, value: &fst::Set) -> Result<(), Error> {
|
||||||
self.0.set("words", value.as_fst().as_bytes()).map_err(Into::into)
|
self.0.set(WORDS_KEY, value.as_fst().as_bytes()).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn synonyms_set(&self) -> Result<Option<fst::Set>, Error> {
|
pub fn synonyms_set(&self) -> Result<Option<fst::Set>, Error> {
|
||||||
match self.0.get_pinned("synonyms")? {
|
match self.0.get_pinned(SYNONYMS_KEY)? {
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
let len = bytes.len();
|
let len = bytes.len();
|
||||||
let value = Arc::from(bytes.as_ref());
|
let value = Arc::from(bytes.as_ref());
|
||||||
@ -57,11 +62,11 @@ impl MainIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_synonyms_set(&self, value: &fst::Set) -> Result<(), Error> {
|
pub fn set_synonyms_set(&self, value: &fst::Set) -> Result<(), Error> {
|
||||||
self.0.set("synonyms", value.as_fst().as_bytes()).map_err(Into::into)
|
self.0.set(SYNONYMS_KEY, value.as_fst().as_bytes()).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ranked_map(&self) -> Result<Option<RankedMap>, Error> {
|
pub fn ranked_map(&self) -> Result<Option<RankedMap>, Error> {
|
||||||
match self.0.get_pinned("ranked-map")? {
|
match self.0.get_pinned(RANKED_MAP_KEY)? {
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
let ranked_map = RankedMap::read_from_bin(bytes.as_ref())?;
|
let ranked_map = RankedMap::read_from_bin(bytes.as_ref())?;
|
||||||
Ok(Some(ranked_map))
|
Ok(Some(ranked_map))
|
||||||
@ -73,7 +78,7 @@ impl MainIndex {
|
|||||||
pub fn set_ranked_map(&self, value: &RankedMap) -> Result<(), Error> {
|
pub fn set_ranked_map(&self, value: &RankedMap) -> Result<(), Error> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
value.write_to_bin(&mut bytes)?;
|
value.write_to_bin(&mut bytes)?;
|
||||||
self.0.set("ranked_map", bytes)?;
|
self.0.set(RANKED_MAP_KEY, bytes)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user