mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
Merge pull request #43 from meilisearch/lowercase-facet-strings
Lowercase the facet string value
This commit is contained in:
commit
6e3f4e5e45
@ -57,6 +57,14 @@ pub enum FacetStringOperator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FacetStringOperator {
|
impl FacetStringOperator {
|
||||||
|
fn equal(s: &str) -> Self {
|
||||||
|
FacetStringOperator::Equal(s.to_lowercase())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn not_equal(s: &str) -> Self {
|
||||||
|
FacetStringOperator::equal(s).negate()
|
||||||
|
}
|
||||||
|
|
||||||
fn negate(self) -> Self {
|
fn negate(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
FacetStringOperator::Equal(x) => FacetStringOperator::NotEqual(x),
|
FacetStringOperator::Equal(x) => FacetStringOperator::NotEqual(x),
|
||||||
@ -236,9 +244,7 @@ impl FacetCondition {
|
|||||||
match ftype {
|
match ftype {
|
||||||
FacetType::Integer => Ok(OperatorI64(fid, Equal(pest_parse(value)?))),
|
FacetType::Integer => Ok(OperatorI64(fid, Equal(pest_parse(value)?))),
|
||||||
FacetType::Float => Ok(OperatorF64(fid, Equal(pest_parse(value)?))),
|
FacetType::Float => Ok(OperatorF64(fid, Equal(pest_parse(value)?))),
|
||||||
FacetType::String => {
|
FacetType::String => Ok(OperatorString(fid, FacetStringOperator::equal(value.as_str()))),
|
||||||
Ok(OperatorString(fid, FacetStringOperator::Equal(value.as_str().to_string())))
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,15 +569,15 @@ mod tests {
|
|||||||
// Test that the facet condition is correctly generated.
|
// Test that the facet condition is correctly generated.
|
||||||
let rtxn = index.read_txn().unwrap();
|
let rtxn = index.read_txn().unwrap();
|
||||||
let condition = FacetCondition::from_str(&rtxn, &index, "channel = ponce").unwrap();
|
let condition = FacetCondition::from_str(&rtxn, &index, "channel = ponce").unwrap();
|
||||||
let expected = OperatorString(1, FacetStringOperator::Equal("ponce".into()));
|
let expected = OperatorString(1, FacetStringOperator::equal("Ponce"));
|
||||||
assert_eq!(condition, expected);
|
assert_eq!(condition, expected);
|
||||||
|
|
||||||
let condition = FacetCondition::from_str(&rtxn, &index, "channel != ponce").unwrap();
|
let condition = FacetCondition::from_str(&rtxn, &index, "channel != ponce").unwrap();
|
||||||
let expected = OperatorString(1, FacetStringOperator::NotEqual("ponce".into()));
|
let expected = OperatorString(1, FacetStringOperator::not_equal("ponce"));
|
||||||
assert_eq!(condition, expected);
|
assert_eq!(condition, expected);
|
||||||
|
|
||||||
let condition = FacetCondition::from_str(&rtxn, &index, "NOT channel = ponce").unwrap();
|
let condition = FacetCondition::from_str(&rtxn, &index, "NOT channel = ponce").unwrap();
|
||||||
let expected = OperatorString(1, FacetStringOperator::NotEqual("ponce".into()));
|
let expected = OperatorString(1, FacetStringOperator::not_equal("ponce"));
|
||||||
assert_eq!(condition, expected);
|
assert_eq!(condition, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,10 +634,10 @@ mod tests {
|
|||||||
"channel = gotaga OR (timestamp 22 TO 44 AND channel != ponce)",
|
"channel = gotaga OR (timestamp 22 TO 44 AND channel != ponce)",
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let expected = Or(
|
let expected = Or(
|
||||||
Box::new(OperatorString(0, FacetStringOperator::Equal("gotaga".into()))),
|
Box::new(OperatorString(0, FacetStringOperator::equal("gotaga"))),
|
||||||
Box::new(And(
|
Box::new(And(
|
||||||
Box::new(OperatorI64(1, Between(22, 44))),
|
Box::new(OperatorI64(1, Between(22, 44))),
|
||||||
Box::new(OperatorString(0, FacetStringOperator::NotEqual("ponce".into()))),
|
Box::new(OperatorString(0, FacetStringOperator::not_equal("ponce"))),
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
assert_eq!(condition, expected);
|
assert_eq!(condition, expected);
|
||||||
@ -641,13 +647,13 @@ mod tests {
|
|||||||
"channel = gotaga OR NOT (timestamp 22 TO 44 AND channel != ponce)",
|
"channel = gotaga OR NOT (timestamp 22 TO 44 AND channel != ponce)",
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let expected = Or(
|
let expected = Or(
|
||||||
Box::new(OperatorString(0, FacetStringOperator::Equal("gotaga".into()))),
|
Box::new(OperatorString(0, FacetStringOperator::equal("gotaga"))),
|
||||||
Box::new(Or(
|
Box::new(Or(
|
||||||
Box::new(Or(
|
Box::new(Or(
|
||||||
Box::new(OperatorI64(1, LowerThan(22))),
|
Box::new(OperatorI64(1, LowerThan(22))),
|
||||||
Box::new(OperatorI64(1, GreaterThan(44))),
|
Box::new(OperatorI64(1, GreaterThan(44))),
|
||||||
)),
|
)),
|
||||||
Box::new(OperatorString(0, FacetStringOperator::Equal("ponce".into()))),
|
Box::new(OperatorString(0, FacetStringOperator::equal("ponce"))),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
assert_eq!(condition, expected);
|
assert_eq!(condition, expected);
|
||||||
|
Loading…
Reference in New Issue
Block a user