feat: Change the STORED attribute property by DISPLAYED

This commit is contained in:
Clément Renault 2019-09-03 11:14:20 +02:00
parent 8be3fc1a66
commit 50b8a66794
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
4 changed files with 24 additions and 25 deletions

View File

@ -50,7 +50,8 @@ impl<'de, 'a, 'b> de::Deserializer<'de> for &'b mut Deserializer<'a>
}); });
let iter = document_attributes.filter_map(|(attr, value)| { let iter = document_attributes.filter_map(|(attr, value)| {
if self.fields.map_or(true, |f| f.contains(&attr)) { let is_displayed = schema.props(attr).is_displayed();
if is_displayed && self.fields.map_or(true, |f| f.contains(&attr)) {
let attribute_name = schema.attribute_name(attr); let attribute_name = schema.attribute_name(attr);
Some((attribute_name, Value::new(value))) Some((attribute_name, Value::new(value)))
} else { } else {

View File

@ -269,10 +269,8 @@ where T: ser::Serialize,
if let Some(attribute) = schema.attribute(key) { if let Some(attribute) = schema.attribute(key) {
let props = schema.props(attribute); let props = schema.props(attribute);
if props.is_stored() { let serialized = rmp_serde::to_vec_named(value)?;
let value = rmp_serde::to_vec_named(value)?; document_store.set_document_field(document_id, attribute, serialized);
document_store.set_document_field(document_id, attribute, value);
}
if props.is_indexed() { if props.is_indexed() {
let indexer = Indexer { attribute, indexer, document_id }; let indexer = Indexer { attribute, indexer, document_id };

View File

@ -1,11 +1,11 @@
use serde_json::json; use serde_json::json;
use meilidb_data::Database; use meilidb_data::Database;
use meilidb_schema::{Schema, SchemaBuilder, STORED, INDEXED}; use meilidb_schema::{Schema, SchemaBuilder, DISPLAYED, INDEXED};
fn simple_schema() -> Schema { fn simple_schema() -> Schema {
let mut builder = SchemaBuilder::with_identifier("objectId"); let mut builder = SchemaBuilder::with_identifier("objectId");
builder.new_attribute("objectId", STORED | INDEXED); builder.new_attribute("objectId", DISPLAYED | INDEXED);
builder.new_attribute("title", STORED | INDEXED); builder.new_attribute("title", DISPLAYED | INDEXED);
builder.build() builder.build()
} }

View File

@ -8,14 +8,14 @@ use std::sync::Arc;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use linked_hash_map::LinkedHashMap; use linked_hash_map::LinkedHashMap;
pub const STORED: SchemaProps = SchemaProps { stored: true, indexed: false, ranked: false }; pub const DISPLAYED: SchemaProps = SchemaProps { displayed: true, indexed: false, ranked: false };
pub const INDEXED: SchemaProps = SchemaProps { stored: false, indexed: true, ranked: false }; pub const INDEXED: SchemaProps = SchemaProps { displayed: false, indexed: true, ranked: false };
pub const RANKED: SchemaProps = SchemaProps { stored: false, indexed: false, ranked: true }; pub const RANKED: SchemaProps = SchemaProps { displayed: false, indexed: false, ranked: true };
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SchemaProps { pub struct SchemaProps {
#[serde(default)] #[serde(default)]
stored: bool, displayed: bool,
#[serde(default)] #[serde(default)]
indexed: bool, indexed: bool,
@ -25,8 +25,8 @@ pub struct SchemaProps {
} }
impl SchemaProps { impl SchemaProps {
pub fn is_stored(self) -> bool { pub fn is_displayed(self) -> bool {
self.stored self.displayed
} }
pub fn is_indexed(self) -> bool { pub fn is_indexed(self) -> bool {
@ -43,7 +43,7 @@ impl BitOr for SchemaProps {
fn bitor(self, other: Self) -> Self::Output { fn bitor(self, other: Self) -> Self::Output {
SchemaProps { SchemaProps {
stored: self.stored | other.stored, displayed: self.displayed | other.displayed,
indexed: self.indexed | other.indexed, indexed: self.indexed | other.indexed,
ranked: self.ranked | other.ranked, ranked: self.ranked | other.ranked,
} }
@ -229,8 +229,8 @@ mod tests {
#[test] #[test]
fn serialize_deserialize() -> bincode::Result<()> { fn serialize_deserialize() -> bincode::Result<()> {
let mut builder = SchemaBuilder::with_identifier("id"); let mut builder = SchemaBuilder::with_identifier("id");
builder.new_attribute("alpha", STORED); builder.new_attribute("alpha", DISPLAYED);
builder.new_attribute("beta", STORED | INDEXED); builder.new_attribute("beta", DISPLAYED | INDEXED);
builder.new_attribute("gamma", INDEXED); builder.new_attribute("gamma", INDEXED);
let schema = builder.build(); let schema = builder.build();
@ -247,8 +247,8 @@ mod tests {
#[test] #[test]
fn serialize_deserialize_toml() -> Result<(), Box<Error>> { fn serialize_deserialize_toml() -> Result<(), Box<Error>> {
let mut builder = SchemaBuilder::with_identifier("id"); let mut builder = SchemaBuilder::with_identifier("id");
builder.new_attribute("alpha", STORED); builder.new_attribute("alpha", DISPLAYED);
builder.new_attribute("beta", STORED | INDEXED); builder.new_attribute("beta", DISPLAYED | INDEXED);
builder.new_attribute("gamma", INDEXED); builder.new_attribute("gamma", INDEXED);
let schema = builder.build(); let schema = builder.build();
@ -262,10 +262,10 @@ mod tests {
identifier = "id" identifier = "id"
[attributes."alpha"] [attributes."alpha"]
stored = true displayed = true
[attributes."beta"] [attributes."beta"]
stored = true displayed = true
indexed = true indexed = true
[attributes."gamma"] [attributes."gamma"]
@ -280,8 +280,8 @@ mod tests {
#[test] #[test]
fn serialize_deserialize_json() -> Result<(), Box<Error>> { fn serialize_deserialize_json() -> Result<(), Box<Error>> {
let mut builder = SchemaBuilder::with_identifier("id"); let mut builder = SchemaBuilder::with_identifier("id");
builder.new_attribute("alpha", STORED); builder.new_attribute("alpha", DISPLAYED);
builder.new_attribute("beta", STORED | INDEXED); builder.new_attribute("beta", DISPLAYED | INDEXED);
builder.new_attribute("gamma", INDEXED); builder.new_attribute("gamma", INDEXED);
let schema = builder.build(); let schema = builder.build();
@ -296,10 +296,10 @@ mod tests {
"identifier": "id", "identifier": "id",
"attributes": { "attributes": {
"alpha": { "alpha": {
"stored": true "displayed": true
}, },
"beta": { "beta": {
"stored": true, "displayed": true,
"indexed": true "indexed": true
}, },
"gamma": { "gamma": {