mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Support numbers and boolean when indexing JSON
This commit is contained in:
parent
f0d028d3a4
commit
a4f8be7811
@ -745,7 +745,7 @@ mod tests {
|
|||||||
let mut wtxn = index.write_txn().unwrap();
|
let mut wtxn = index.write_txn().unwrap();
|
||||||
let content = &br#"[
|
let content = &br#"[
|
||||||
{ "name": "kevin" },
|
{ "name": "kevin" },
|
||||||
{ "name": "kevina", "id": "21" },
|
{ "name": "kevina", "id": 21 },
|
||||||
{ "name": "benoit" }
|
{ "name": "benoit" }
|
||||||
]"#[..];
|
]"#[..];
|
||||||
let mut builder = IndexDocuments::new(&mut wtxn, &index);
|
let mut builder = IndexDocuments::new(&mut wtxn, &index);
|
||||||
|
@ -309,7 +309,19 @@ impl Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (attr, content) in document.iter() {
|
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) {
|
for (pos, token) in simple_tokenizer(&content).filter_map(only_token).enumerate().take(MAX_POSITION) {
|
||||||
let word = token.to_lowercase();
|
let word = token.to_lowercase();
|
||||||
let position = (attr as usize * MAX_POSITION + pos) as u32;
|
let position = (attr as usize * MAX_POSITION + pos) as u32;
|
||||||
|
Loading…
Reference in New Issue
Block a user