Support numbers and boolean when indexing JSON

This commit is contained in:
Clément Renault 2020-10-31 17:25:07 +01:00
parent f0d028d3a4
commit a4f8be7811
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 14 additions and 2 deletions

View File

@ -745,7 +745,7 @@ mod tests {
let mut wtxn = index.write_txn().unwrap();
let content = &br#"[
{ "name": "kevin" },
{ "name": "kevina", "id": "21" },
{ "name": "kevina", "id": 21 },
{ "name": "benoit" }
]"#[..];
let mut builder = IndexDocuments::new(&mut wtxn, &index);

View File

@ -309,7 +309,19 @@ impl Store {
}
for (attr, content) in document.iter() {
let content: Cow<str> = serde_json::from_slice(content).unwrap();
use serde_json::Value;
let content: Cow<str> = match serde_json::from_slice(content) {
Ok(string) => string,
Err(_) => match serde_json::from_slice(content)? {
Value::Null => continue,
Value::Bool(boolean) => Cow::Owned(boolean.to_string()),
Value::Number(number) => Cow::Owned(number.to_string()),
Value::String(string) => Cow::Owned(string),
Value::Array(_array) => continue,
Value::Object(_object) => continue,
}
};
for (pos, token) in simple_tokenizer(&content).filter_map(only_token).enumerate().take(MAX_POSITION) {
let word = token.to_lowercase();
let position = (attr as usize * MAX_POSITION + pos) as u32;