Owned items, static values
This commit is contained in:
@@ -104,7 +104,7 @@ impl DbFtsIndex {
|
||||
|
||||
pub async fn get_field(
|
||||
&self,
|
||||
extractor: &PileValue<'_>,
|
||||
extractor: &PileValue,
|
||||
field_name: &Label,
|
||||
) -> Result<Option<String>, std::io::Error> {
|
||||
let field = match self.cfg.schema.get(field_name) {
|
||||
@@ -148,16 +148,14 @@ impl DbFtsIndex {
|
||||
PileValue::U64(x) => return Ok(Some(x.to_string())),
|
||||
PileValue::I64(x) => return Ok(Some(x.to_string())),
|
||||
|
||||
#[expect(clippy::unwrap_used)]
|
||||
PileValue::Array(ref mut x) => {
|
||||
PileValue::Array(x) => {
|
||||
if x.len() == 1 {
|
||||
x.pop().unwrap()
|
||||
x[0].clone()
|
||||
} else if x.len() > 1 {
|
||||
debug!(
|
||||
message = "Skipping field, is array with more than one element",
|
||||
field = field_name.to_string(),
|
||||
?path,
|
||||
//value = ?val
|
||||
);
|
||||
continue 'outer;
|
||||
} else {
|
||||
@@ -299,7 +297,7 @@ impl DbFtsIndex {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<'a>> {
|
||||
pub fn apply(post: &FieldSpecPost, val: &PileValue) -> Option<PileValue> {
|
||||
Some(match post {
|
||||
FieldSpecPost::NotEmpty { notempty: false } => val.clone(),
|
||||
FieldSpecPost::NotEmpty { notempty: true } => match val {
|
||||
@@ -316,11 +314,11 @@ pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<
|
||||
PileValue::Blob { .. } => return None,
|
||||
PileValue::ObjectExtractor(_) => return None,
|
||||
PileValue::ListExtractor(_) => return None,
|
||||
PileValue::String(x) => PileValue::String(x.to_lowercase().into()),
|
||||
PileValue::String(x) => PileValue::String(Arc::new(x.as_str().to_lowercase().into())),
|
||||
|
||||
PileValue::Array(x) => {
|
||||
PileValue::Array(x.iter().map(|x| apply(post, x)).collect::<Option<_>>()?)
|
||||
}
|
||||
PileValue::Array(x) => PileValue::Array(Arc::new(
|
||||
x.iter().map(|x| apply(post, x)).collect::<Option<_>>()?,
|
||||
)),
|
||||
},
|
||||
|
||||
FieldSpecPost::SetCase { case: Case::Upper } => match val {
|
||||
@@ -330,11 +328,13 @@ pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<
|
||||
PileValue::Blob { .. } => return None,
|
||||
PileValue::ObjectExtractor(_) => return None,
|
||||
PileValue::ListExtractor(_) => return None,
|
||||
PileValue::String(x) => PileValue::String(x.to_uppercase().into()),
|
||||
PileValue::String(x) => PileValue::String(Arc::new(x.as_str().to_uppercase().into())),
|
||||
|
||||
PileValue::Array(x) => {
|
||||
PileValue::Array(x.iter().map(|x| apply(post, x)).collect::<Option<_>>()?)
|
||||
}
|
||||
PileValue::Array(x) => PileValue::Array(Arc::new(
|
||||
x.iter()
|
||||
.map(|x| apply(post, x))
|
||||
.collect::<Option<Vec<_>>>()?,
|
||||
)),
|
||||
},
|
||||
|
||||
FieldSpecPost::TrimSuffix { trim_suffix } => match val {
|
||||
@@ -345,13 +345,15 @@ pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<
|
||||
PileValue::ObjectExtractor(_) => return None,
|
||||
PileValue::ListExtractor(_) => return None,
|
||||
|
||||
PileValue::String(x) => {
|
||||
PileValue::String(x.strip_suffix(trim_suffix).unwrap_or(x).into())
|
||||
}
|
||||
PileValue::String(x) => PileValue::String(Arc::new(
|
||||
x.strip_suffix(trim_suffix).unwrap_or(x.as_str()).into(),
|
||||
)),
|
||||
|
||||
PileValue::Array(x) => {
|
||||
PileValue::Array(x.iter().map(|x| apply(post, x)).collect::<Option<_>>()?)
|
||||
}
|
||||
PileValue::Array(x) => PileValue::Array(Arc::new(
|
||||
x.iter()
|
||||
.map(|x| apply(post, x))
|
||||
.collect::<Option<Vec<_>>>()?,
|
||||
)),
|
||||
},
|
||||
|
||||
FieldSpecPost::TrimPrefix { trim_prefix } => match val {
|
||||
@@ -362,13 +364,15 @@ pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<
|
||||
PileValue::ObjectExtractor(_) => return None,
|
||||
PileValue::ListExtractor(_) => return None,
|
||||
|
||||
PileValue::String(x) => {
|
||||
PileValue::String(x.strip_prefix(trim_prefix).unwrap_or(x).into())
|
||||
}
|
||||
PileValue::String(x) => PileValue::String(Arc::new(
|
||||
x.strip_prefix(trim_prefix).unwrap_or(x.as_str()).into(),
|
||||
)),
|
||||
|
||||
PileValue::Array(x) => {
|
||||
PileValue::Array(x.iter().map(|x| apply(post, x)).collect::<Option<_>>()?)
|
||||
}
|
||||
PileValue::Array(x) => PileValue::Array(Arc::new(
|
||||
x.iter()
|
||||
.map(|x| apply(post, x))
|
||||
.collect::<Option<Vec<_>>>()?,
|
||||
)),
|
||||
},
|
||||
|
||||
FieldSpecPost::Join { join } => match val {
|
||||
@@ -381,7 +385,7 @@ pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<
|
||||
|
||||
PileValue::String(x) => PileValue::String(x.clone()),
|
||||
|
||||
PileValue::Array(x) => PileValue::String(
|
||||
PileValue::Array(x) => PileValue::String(Arc::new(
|
||||
x.iter()
|
||||
.map(|x| apply(post, x))
|
||||
.map(|x| x.and_then(|x| x.as_str().map(|x| x.to_owned())))
|
||||
@@ -389,7 +393,7 @@ pub fn apply<'a>(post: &FieldSpecPost, val: &PileValue<'a>) -> Option<PileValue<
|
||||
.into_iter()
|
||||
.join(join)
|
||||
.into(),
|
||||
),
|
||||
)),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user